log

package
v0.0.0-...-e3e1183 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2019 License: Apache-2.0 Imports: 18 Imported by: 0

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 (
	InfoPre  string = "[INFO]"
	DebugPre string = "[DEBUG]"
	WarnPre  string = "[WARN]"
	ErrorPre string = "[ERROR]"
	FatalPre string = "[FATAL]"
	TracePre string = "[TRACE]"
)
View Source
const AccessLogLen = 1 << 8

Variables

View Source
var (
	RequestInfoFuncMap      map[string]func(info types.RequestInfo) string
	DefaultDisableAccessLog bool
)

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

View Source
var (
	DefaultLogger ErrorLogger
	StartLogger   ErrorLogger
	Proxy         ProxyLogger

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

	// error
	ErrReopenUnsupported = errors.New("reopen unsupported")
)

Functions

func BytesReceivedGetter

func BytesReceivedGetter(info types.RequestInfo) string

BytesReceivedGetter get bytes received

func BytesSentGetter

func BytesSentGetter(info types.RequestInfo) string

BytesSentGetter get bytes sent

func CloseAll

func CloseAll() (err error)

CloseAll logger

func DisableAllAccessLog

func DisableAllAccessLog()

func DownstreamLocalAddressGetter

func DownstreamLocalAddressGetter(info types.RequestInfo) string

DownstreamLocalAddressGetter get downstream's local address

func DownstreamRemoteAddressGetter

func DownstreamRemoteAddressGetter(info types.RequestInfo) string

DownstreamRemoteAddressGetter get upstream's remote address

func DurationGetter

func DurationGetter(info types.RequestInfo) string

DurationGetter get duration since request's starting time

func GetResponseFlagGetter

func GetResponseFlagGetter(info types.RequestInfo) string

GetResponseFlagGetter get request's response flag

func InitDefaultLogger

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

func InitGlobalRoller

func InitGlobalRoller(roller string) error

InitDefaultRoller

func IsLogRollerSubdirective

func IsLogRollerSubdirective(subdir string) bool

IsLogRollerSubdirective is true if the subdirective is for the log roller.

func NewAccessLog

func NewAccessLog(output string, filter types.AccessLogFilter,
	format string) (types.AccessLog, error)

NewAccessLog

func NewAccessLogFormatter

func NewAccessLogFormatter(format string) types.AccessLogFormatter

NewAccessLogFormatter

func ProtocolGetter

func ProtocolGetter(info types.RequestInfo) string

get request's protocol type

func ReceivedDurationGetter

func ReceivedDurationGetter(info types.RequestInfo) string

ReceivedDurationGetter get duration between request arriving and request resend to upstream

func Reopen

func Reopen() (err error)

Reopen all logger

func RequestFinishedDurationGetter

func RequestFinishedDurationGetter(info types.RequestInfo) string

RequestFinishedDurationGetter hets duration between request arriving and request finished

func ResponseCodeGetter

func ResponseCodeGetter(info types.RequestInfo) string

ResponseCodeGetter get request's response code

func ResponseReceivedDurationGetter

func ResponseReceivedDurationGetter(info types.RequestInfo) string

ResponseReceivedDurationGetter get duration between request arriving and response sending

func StartTimeGetter

func StartTimeGetter(info types.RequestInfo) string

StartTimeGetter get request's arriving time

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 Level) bool

UpdateErrorLoggerLevel updates the exists ErrorLogger's Level

func UpstreamHostSelectedGetter

func UpstreamHostSelectedGetter(info types.RequestInfo) string

UpstreamHostSelectedGetter get upstream's selected host address

func UpstreamLocalAddressGetter

func UpstreamLocalAddressGetter(info types.RequestInfo) string

UpstreamLocalAddressGetter get upstream's local address

Types

type CreateErrorLoggerFunc

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

CreateErrorLoggerFunc creates a ErrorLogger implementation by output and level

type ErrorLogger

type ErrorLogger interface {
	Println(args ...interface{})

	Printf(format string, args ...interface{})

	// Alertf is a wrapper of Errorf
	Alertf(errkey types.ErrorKey, format string, args ...interface{})

	Infof(format string, args ...interface{})

	Debugf(format string, args ...interface{})

	Warnf(format string, args ...interface{})

	Errorf(format string, args ...interface{})

	Tracef(format string, args ...interface{})

	Fatalf(format string, args ...interface{})

	Fatal(args ...interface{})

	Fatalln(args ...interface{})

	// SetLogLevel updates the log level
	SetLogLevel(Level)
	// GetLogLevel returns the logger's level
	GetLogLevel() Level

	// Toggle disable/enable the logger
	Toggle(disable bool)
}

ErrorLogger generates lines of output to an io.Writer

func CreateDefaultErrorLogger

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

func GetOrCreateDefaultErrorLogger

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

GetOrCreateDefaultErrorLogger used default create function

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) GetOrCreateErrorLogger

func (mng *ErrorLoggerManager) GetOrCreateErrorLogger(p string, level Level, f CreateErrorLoggerFunc) (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 Level)

type Level

type Level uint8
const (
	FATAL Level = iota
	ERROR
	WARN
	INFO
	DEBUG
	TRACE
	RAW
)

type Logger

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

Logger is a basic sync logger implement, contains unexported fields The Logger Function contains: Print(buffer types.IoBuffer, discard bool) error Printf(format string, args ...interface{}) Println(args ...interface{}) Fatalf(format string, args ...interface{}) Fatal(args ...interface{}) Fatalln(args ...interface{}) Close() error Reopen() error Toggle(disable bool)

func GetOrCreateLogger

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

func (*Logger) Close

func (l *Logger) Close() error

func (*Logger) Fatal

func (l *Logger) Fatal(args ...interface{})

func (*Logger) Fatalf

func (l *Logger) Fatalf(format string, args ...interface{})

Fatal cannot be disabled

func (*Logger) Fatalln

func (l *Logger) Fatalln(args ...interface{})

func (*Logger) Print

func (l *Logger) Print(buf types.IoBuffer, discard bool) error

Print writes the final buffere to the buffer chan if discard is true and the buffer is full, returns an error

func (*Logger) Printf

func (l *Logger) Printf(format string, args ...interface{})

func (*Logger) Println

func (l *Logger) Println(args ...interface{})

func (*Logger) Reopen

func (l *Logger) Reopen() error

func (*Logger) Toggle

func (l *Logger) Toggle(disable bool)

func (*Logger) Write

func (l *Logger) Write(p []byte) (n int, err error)

type ProxyLogger

type ProxyLogger interface {
	// Alertf is a wrapper of Errorf
	Alertf(ctx context.Context, errkey types.ErrorKey, format string, args ...interface{})

	Infof(ctx context.Context, format string, args ...interface{})

	Debugf(ctx context.Context, format string, args ...interface{})

	Warnf(ctx context.Context, format string, args ...interface{})

	Errorf(ctx context.Context, format string, args ...interface{})

	Fatalf(ctx context.Context, format string, args ...interface{})

	// SetLogLevel updates the log level
	SetLogLevel(Level)
	// GetLogLevel returns the logger's level
	GetLogLevel() Level

	// Toggle disable/enable the logger
	Toggle(disable bool)
}

ProxyLogger generates lines of output to an io.Writer, works for data flow

func CreateDefaultProxyLogger

func CreateDefaultProxyLogger(output string, level Level) (ProxyLogger, error)

type Roller

type Roller struct {
	Filename   string
	MaxSize    int
	MaxAge     int
	MaxBackups int
	Compress   bool
	LocalTime  bool
	MaxTime    int64
}

roller implements a type that provides a rolling logger.

func DefaultRoller

func DefaultRoller() *Roller

DefaultRoller will roll logs by default.

func ParseRoller

func ParseRoller(what string) (*Roller, error)

ParseRoller parses roller contents out of c.

func (Roller) GetLogWriter

func (l Roller) GetLogWriter() io.Writer

GetLogWriter returns an io.Writer that writes to a rolling logger. This should be called only from the main goroutine (like during server setup) because this method is not thread-safe; it is careful to create only one log writer per log file, even if the log file is shared by different sites or middlewares. This ensures that rolling is synchronized, since a process (or multiple processes) should not create more than one roller on the same file at the same time. See issue #1363.

Jump to

Keyboard shortcuts

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