Documentation ¶
Overview ¶
Package log
Package log 日志记录器 ¶
基于zap的日志库 提供zap可定制的日志类
初始化日志类 logger = log.New() logger.Info() logger.Warn() logger.Error()
默认内置了常用的日志类 prodLog = log.Default() devLog = log.Dev() 创建原生Logger而不是Sugar log.NewZap() 基于zapCore创建 zap.NewCore() 注意:带日志绕接的日志类只能通过core创建
Package log ¶
Package log ¶
Package log ¶
Package log ¶
Package log
Index ¶
- Constants
- Variables
- func ConvertConfig(op Option) zap.Config
- func DefaultEncodeConfig() zapcore.EncoderConfig
- func ModuleName() string
- func NewZap(c zap.Config, op ...zap.Option) (*zap.Logger, error)
- type Level
- type Logger
- func Default(name string) *Logger
- func Dev(name string) *Logger
- func New(name string, op Option) *Logger
- func NewCore(name string, op Option) *Logger
- func NewCoreRotate(name string, op Option) *Logger
- func NewCoreStd(name string, op Option) *Logger
- func Raw(name string, c zap.Config, op ...zap.Option) Logger
- func (l Logger) Error(v ...interface{})
- func (l Logger) ErrorF(fmtStr string, v ...interface{})
- func (l Logger) Info(v ...interface{})
- func (l Logger) InfoF(fmtStr string, v ...interface{})
- func (l *Logger) Init() error
- func (l Logger) Warn(v ...interface{})
- func (l Logger) WarnF(fmtStr string, v ...interface{})
- type LoggerInterface
- type LoggerPanic
- type Option
- type RotateOption
Constants ¶
View Source
const EncodingConsole = "console"
View Source
const EncodingJSON = "json"
Variables ¶
View Source
var DefaultOption = Option{ Development: false, Level: InfoLevel, StackTrace: false, Encoding: EncodingJSON, Output: DefaultOutput, EncodeConfig: zapEncodeConfig, }
DefaultOption 默认配置
View Source
var DefaultOutput = []string{"stderr"}
DefaultOutput 默认会记录到stderr fatal错误不会被记录
View Source
var DefaultRotateOption = RotateOption{ MaxSize: 10, MaxAge: 30, MaxBackups: 10, LocalTime: true, Compress: false, }
View Source
var DevOption = Option{ Development: true, Level: DebugLevel, StackTrace: true, Encoding: EncodingJSON, Output: DefaultOutput, EncodeConfig: zapEncodeConfig, }
Functions ¶
func ConvertConfig ¶
ConvertConfig 从fushin option转为zap config
func DefaultEncodeConfig ¶
func DefaultEncodeConfig() zapcore.EncoderConfig
func ModuleName ¶
func ModuleName() string
Types ¶
type Level ¶
type Level int8
const ( // DebugLevel logs are typically voluminous, and are usually disabled in // production. DebugLevel Level = iota - 1 // InfoLevel is the default logging priority. InfoLevel // WarnLevel logs are more important than Info, but don't need individual // human review. WarnLevel // ErrorLevel logs are high-priority. If an application is running smoothly, // it shouldn't generate any error-level logs. ErrorLevel // DPanicLevel logs are particularly important errors. In development the // logger panics after writing the message. DPanicLevel // PanicLevel logs a message, then panics. PanicLevel // FatalLevel logs a message, then calls os.Exit(1). FatalLevel )
type Logger ¶
type Logger struct { Name string Option Option Sync bool // contains filtered or unexported fields }
func NewCoreRotate ¶ added in v1.1.13
NewCoreRotate create a coreLogger with rotate
func NewCoreStd ¶ added in v1.1.13
NewCoreStd create a coreLogger with os.std
type LoggerInterface ¶ added in v1.0.5
type LoggerPanic ¶ added in v1.0.5
type LoggerPanic interface { Panic(v ...interface{}) PanicF(fmt string, v ...interface{}) }
Source Files ¶
Click to show internal directories.
Click to hide internal directories.