Documentation
¶
Overview ¶
Package logging 1. 支持打印至console/file; 2. 打印至file时支持自动归档。
导入该包时init会生成默认logger,并支持运行时替换默认logger
logger, err := logging.NewLogger(...opts)
_, err := logging.SetDefault(logging.WithLogger(logger))
API均兼容原有
Index ¶
- Constants
- Variables
- func AppendWith(ctx context.Context, kvs ...interface{}) context.Context
- func ColorForMethod(method string) string
- func ColorForStatus(code int) string
- func GinRecovery() gin.HandlerFunc
- func IsTerminal() bool
- func Reverse()
- func SetLevel(level int)
- func SetToDebug()
- func Stack(skip int) []byte
- func Sync() error
- type LogConfig
- type LogConfigOption
- func WithDefaultLogConfigOption() LogConfigOption
- func WithLogLevel(logLevel LogLevel) LogConfigOption
- func WithLogPath(path string) LogConfigOption
- func WithMaxAge(maxAge int) LogConfigOption
- func WithMaxBackups(maxBackups int) LogConfigOption
- func WithMaxSize(maxSize int) LogConfigOption
- func WithReleaseLevel(releaseLevel ReleaseLevel) LogConfigOption
- func WithUseConsole(useConsole bool) LogConfigOption
- type LogLevel
- type Logger
- type ReleaseLevel
- type SetDefaultOption
Constants ¶
View Source
const ( LoggerName = "logger" DefaultMaxSize = 500 // MB DefaultMaxAge = 180 // DAY DefaultMaxBackups = 30 // COUNT DefaultLogPath = "./custom.log" )
Variables ¶
View Source
var ( Green = string([]byte{27, 91, 57, 55, 59, 52, 50, 109}) White = string([]byte{27, 91, 57, 48, 59, 52, 55, 109}) Yellow = string([]byte{27, 91, 57, 48, 59, 52, 51, 109}) Red = string([]byte{27, 91, 57, 55, 59, 52, 49, 109}) Blue = string([]byte{27, 91, 57, 55, 59, 52, 52, 109}) Magenta = string([]byte{27, 91, 57, 55, 59, 52, 53, 109}) Cyan = string([]byte{27, 91, 57, 55, 59, 52, 54, 109}) ResetColor = string([]byte{27, 91, 48, 109}) DisableColor = false )
Functions ¶
func AppendWith ¶
AppendWith AppendWith
func GinRecovery ¶
func GinRecovery() gin.HandlerFunc
GinRecovery RecoveryWithWriter returns a middleware for a given writer that recovers from any panics and writes a 500 if there was one.
Types ¶
type LogConfigOption ¶
type LogConfigOption interface {
// contains filtered or unexported methods
}
func WithDefaultLogConfigOption ¶
func WithDefaultLogConfigOption() LogConfigOption
func WithLogLevel ¶
func WithLogLevel(logLevel LogLevel) LogConfigOption
WithLogLevel 日志等级 [ info | debug ]
func WithReleaseLevel ¶
func WithReleaseLevel(releaseLevel ReleaseLevel) LogConfigOption
WithReleaseLevel 日志发布等级 [ development | production ]
func WithUseConsole ¶
func WithUseConsole(useConsole bool) LogConfigOption
WithUseConsole 是否打印在console(即使用标准stdout/stderr),true: 打印在console上,false:打印在文件中
type ReleaseLevel ¶
type ReleaseLevel string
const ( DevelopmentLevel ReleaseLevel = "development" ProductionLevel ReleaseLevel = "production" )
func (ReleaseLevel) String ¶
func (l ReleaseLevel) String() string
type SetDefaultOption ¶
type SetDefaultOption interface {
// contains filtered or unexported methods
}
func WithLogger ¶
func WithLogger(logger *Logger) SetDefaultOption
Click to show internal directories.
Click to hide internal directories.