Documentation ¶
Index ¶
- Constants
- Variables
- func Init(opts *Options)
- func SetHooks(hooks ...Hook)
- type Entry
- type Field
- type Hook
- type Level
- type Logger
- func (l *Logger) C(ctx context.Context) *Logger
- func (l *Logger) DPanic(msg string, fields ...Field)
- func (l *Logger) DPanicf(format string, v ...interface{})
- func (l *Logger) DPanicw(msg string, keysAndValues ...interface{})
- func (l *Logger) Debug(msg string, fields ...Field)
- func (l *Logger) Debugf(format string, v ...interface{})
- func (l *Logger) Debugw(msg string, keysAndValues ...interface{})
- func (l *Logger) Error(msg string, fields ...Field)
- func (l *Logger) Errorf(format string, v ...interface{})
- func (l *Logger) Errorw(msg string, keysAndValues ...interface{})
- func (l *Logger) Fatal(msg string, fields ...Field)
- func (l *Logger) Fatalf(format string, v ...interface{})
- func (l *Logger) Fatalw(msg string, keysAndValues ...interface{})
- func (l *Logger) FromContext(ctx context.Context) *Logger
- func (l *Logger) GetOptions() *Options
- func (l *Logger) Info(msg string, fields ...Field)
- func (l *Logger) Infof(format string, v ...interface{})
- func (l *Logger) Infow(msg string, keysAndValues ...interface{})
- func (l *Logger) Panic(msg string, fields ...Field)
- func (l *Logger) Panicf(format string, v ...interface{})
- func (l *Logger) Panicw(msg string, keysAndValues ...interface{})
- func (l *Logger) Sync()
- func (l *Logger) ToContext(ctx context.Context) context.Context
- func (l *Logger) Warn(msg string, fields ...Field)
- func (l *Logger) Warnf(format string, v ...interface{})
- func (l *Logger) Warnw(msg string, keysAndValues ...interface{})
- func (l *Logger) WithFields(fields ...Field) *Logger
- func (l *Logger) WithHooks(hooks ...Hook) *Logger
- func (l *Logger) WithName(name string) *Logger
- type Options
- type RotateOptions
Constants ¶
const (
// ContextLoggerName is logger key from context.Context.
ContextLoggerName = "contextLgger"
)
Variables ¶
var ( DebugLevel = zapcore.DebugLevel InfoLevel = zapcore.InfoLevel WarnLevel = zapcore.WarnLevel ErrorLevel = zapcore.ErrorLevel DPanicLevel = zapcore.DPanicLevel PanicLevel = zapcore.PanicLevel FatalLevel = zapcore.FatalLevel )
Alias for zap level.
var ( Any = zap.Any Array = zap.Array Object = zap.Object Binary = zap.Binary Bool = zap.Bool Bools = zap.Bools ByteString = zap.ByteString ByteStrings = zap.ByteStrings Complex64 = zap.Complex64 Complex64s = zap.Complex64s Complex128 = zap.Complex128 Complex128s = zap.Complex128s Duration = zap.Duration Durations = zap.Durations Err = zap.Error Errors = zap.Errors Float32 = zap.Float32 Float32s = zap.Float32s Float64 = zap.Float64 Float64s = zap.Float64s Int = zap.Int Ints = zap.Ints Int8 = zap.Int8 Int8s = zap.Int8s Int16 = zap.Int16 Int16s = zap.Int16s Int32 = zap.Int32 Int32s = zap.Int32s Int64 = zap.Int64 Int64s = zap.Int64s Namespace = zap.Namespace Reflect = zap.Reflect Stack = zap.Stack String = zap.String Stringer = zap.Stringer Strings = zap.Strings Time = zap.Time Times = zap.Times Uint = zap.Uint Uints = zap.Uints Uint8 = zap.Uint8 Uint8s = zap.Uint8s Uint16 = zap.Uint16 Uint16s = zap.Uint16s Uint32 = zap.Uint32 Uint32s = zap.Uint32s Uint64 = zap.Uint64 Uint64s = zap.Uint64s Uintptr = zap.Uintptr Uintptrs = zap.Uintptrs )
Alias for zap type functions.
var ( Debug = std.Debug Debugf = std.Debugf Debugw = std.Debugw Info = std.Info Infof = std.Infof Infow = std.Infow Warn = std.Warn Warnf = std.Warnf Warnw = std.Warnw Error = std.Error Errorf = std.Errorf Errorw = std.Errorw DPanic = std.DPanic DPanicf = std.DPanicf DPanicw = std.DPanicw Panic = std.Panic Panicf = std.Panicf Panicw = std.Panicw Fatal = std.Fatal Fatalf = std.Fatalf Fatalw = std.Fatalw Sync = std.Sync WithName = std.WithName WithFields = std.WithFields WithHooks = std.WithHooks ToContext = std.ToContext FromContext = std.FromContext GetOptions = std.GetOptions C = std.C )
User can directly use package level functions
Functions ¶
Types ¶
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger ...
func (*Logger) C ¶ added in v0.1.1
C get logger from gin.Context.
Usage example:
This is a middleware that put logger into gin.Context:
func Context() gin.HandlerFunc { return func(c *gin.Context) { l := log.WithFields( log.String("x-request-id", c.GetString(XRequestIDKey)), log.String("username", c.GetString(UsernameKey)), ) c.Set(log.ContextLoggerName, l) c.Next() } }
Get logger that with fileds from gin.Context:
func (u *UserController) Get(c *gin.Context) { log.C(c).Debug("user get called") }
func (*Logger) FromContext ¶ added in v0.1.1
FromContext return logger from context.
func (*Logger) GetOptions ¶ added in v0.1.3
GetOptions get logger instance configuration.
func (*Logger) WithFields ¶
WithFields custom other log entry fileds.
type Options ¶
type Options struct { *RotateOptions // logger name, default "" Name string Level string Format string DisableColor bool DisableCaller bool DisableStacktrace bool OutputPaths []string ErrorOutputPaths []string EnableRotate bool }
Options for logger.
type RotateOptions ¶
type RotateOptions struct { // MaxSize is the maximum size in megabytes of the log file before it gets // rotated. It defaults to 100 megabytes. MaxSize int // MaxAge is the maximum number of days to retain old log files based on the // timestamp encoded in their filename. Note that a day is defined as 24 // hours and may not exactly correspond to calendar days due to daylight // savings, leap seconds, etc. The default is not to remove old log files // based on age. MaxAge int // MaxBackups is the maximum number of old log files to retain. The default // is to retain all old log files (though MaxAge may still cause them to get // deleted.) MaxBackups int // LocalTime determines if the time used for formatting the timestamps in // backup files is the computer's local time. The default is to use UTC // time. LocalTime bool // Compress determines if the rotated log files should be compressed // using gzip. The default is not to perform compression. Compress bool }
RotateOptions for log rotate feature.