log

package
v0.22.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 2, 2021 License: Apache-2.0 Imports: 10 Imported by: 61

README

配置示例:

{
    "servers": [
        {
            "global_log_roller": "size=100 age=10 keep=10 compress=off",
            "default_log_path": "/home/admin/mosn/logs/default.log",
            "default_log_level": "ERROR",
            "listeners": [
                {
                    "access_logs": [
                        {
                            "log_path": "/home/admin/mosn/logs/access.log",
                            "log_format": "%StartTime% %RequestReceivedDuration% %ResponseReceivedDuration% %REQ.requestid% %REQ.cmdcode% %RESP.requestid% %RESP.service%"
                        }
                    ]
                }
            ]
        }
    ]
}
  • global_log_roller 全局的日志轮转参数,针对所有日志生效,包括accesslog,defaultlog等。

    • size 表示日志达到多少M进行轮转,单位: M
    • age 表示最大保存多少天内的日志
    • keep 表示最大保存多少个日志
    • compress 表示是否压缩(on/off) "global_log_roller": "size=100 age=10 keep=10 compress=off"
  • default_log_path 默认的错误日志路径

  • default_log_level 默认的错误日志等级

    • ERROR
    • WARN
    • INFO
    • DEBUG
    • TRACE
  • access_logs 请求日志

    • log_path 日志路径
    • log_format 日志格式

注意事项:

  • 默认配置为按天轮转。
  • 日志按时间轮转优先级最高,配置了之后其他规F则都失效。

Documentation

Index

Constants

View Source
const (
	FATAL Level = log.FATAL
	ERROR       = log.ERROR
	WARN        = log.WARN
	INFO        = log.INFO
	DEBUG       = log.DEBUG
	TRACE       = log.TRACE
	RAW         = log.RAW
)
View Source
const AccessLogLen = 1 << 8

Variables

View Source
var (
	DefaultDisableAccessLog bool

	ErrLogFormatUndefined = errors.New("access log format undefined")
	ErrEmptyVarDef        = errors.New("access log format error: empty variable definition")
	ErrUnclosedVarDef     = errors.New("access log format error: unclosed variable definition")

	UnknowDefaultValue = "-"
)

RequestInfoFuncMap is a map which key is the format-key, value is the func to get corresponding string value

View Source
var (
	DefaultLogger log.ErrorLogger
	StartLogger   log.ErrorLogger
	Proxy         log.ContextLogger

	ErrNoLoggerFound = errors.New("no logger found in logger manager")
)

Functions

func CreateDefaultContextLogger

func CreateDefaultContextLogger(output string, level log.Level) (log.ContextLogger, error)

func CreateDefaultErrorLogger

func CreateDefaultErrorLogger(output string, level log.Level) (log.ErrorLogger, error)

func DisableAllAccessLog

func DisableAllAccessLog()

func EnableAllAccessLog added in v0.14.0

func EnableAllAccessLog()

func GetErrorLoggersInfo added in v0.15.0

func GetErrorLoggersInfo() map[string]string

GetErrorLoggerInfo get the exists ErrorLogger

func GetOrCreateDefaultErrorLogger

func GetOrCreateDefaultErrorLogger(p string, level log.Level) (log.ErrorLogger, error)

GetOrCreateDefaultErrorLogger used default create function

func GetOrCreateLogger

func GetOrCreateLogger(output string, roller *log.Roller) (*log.Logger, error)

func InitDefaultLogger

func InitDefaultLogger(output string, level log.Level) (err error)

InitDefaultLogger inits a default logger

func NewAccessLog

func NewAccessLog(output string, format string) (api.AccessLog, error)

NewAccessLog

func ToggleLogger

func ToggleLogger(p string, disable bool) bool

ToggleLogger enable/disable the exists logger, include ErrorLogger and Logger

func UpdateErrorLoggerLevel

func UpdateErrorLoggerLevel(p string, level log.Level) bool

UpdateErrorLoggerLevel updates the exists ErrorLogger's Level

Types

type CreateErrorLoggerFunc

type CreateErrorLoggerFunc func(output string, level log.Level) (log.ErrorLogger, error)

CreateErrorLoggerFunc creates a ErrorLogger implementation by output and level

var DefaultCreateErrorLoggerFunc CreateErrorLoggerFunc = CreateDefaultErrorLogger

The default function to CreateErrorLoggerFunc

type ErrorLoggerManager

type ErrorLoggerManager struct {
	// contains filtered or unexported fields
}

ErrorLoggerManager manages error log can be updated dynamicly

func GetErrorLoggerManagerInstance

func GetErrorLoggerManagerInstance() *ErrorLoggerManager

Default Export Functions

func (*ErrorLoggerManager) Disable added in v0.14.0

func (mng *ErrorLoggerManager) Disable()

func (*ErrorLoggerManager) DisableLogLevelControl added in v0.14.0

func (mng *ErrorLoggerManager) DisableLogLevelControl()

func (*ErrorLoggerManager) Enable added in v0.14.0

func (mng *ErrorLoggerManager) Enable()

func (*ErrorLoggerManager) GetAllErrorLogger added in v0.15.0

func (mng *ErrorLoggerManager) GetAllErrorLogger() map[string]string

GetAllErrorLogger returns all of ErrorLogger info

func (*ErrorLoggerManager) GetOrCreateErrorLogger

func (mng *ErrorLoggerManager) GetOrCreateErrorLogger(p string, level log.Level, f CreateErrorLoggerFunc) (log.ErrorLogger, error)

GetOrCreateErrorLogger returns a ErrorLogger based on the output(p). If Logger not exists, and create function is not nil, creates a new logger

func (*ErrorLoggerManager) SetAllErrorLoggerLevel

func (mng *ErrorLoggerManager) SetAllErrorLoggerLevel(level log.Level)

func (*ErrorLoggerManager) SetLogLevelControl added in v0.14.0

func (mng *ErrorLoggerManager) SetLogLevelControl(level log.Level)

type Level

type Level = log.Level

Wrapper of pkg/log Level is an alias of log.Level

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL