Documentation
¶
Index ¶
- Variables
- func Any(key string, value interface{}) zap.Field
- func Error(err error) zap.Field
- func InitLogger(fileName string, setting Setting, cfg *zapcore.EncoderConfig, ...) (*zap.Logger, error)
- func Int(key string, val int) zap.Field
- func Int32(key string, val int32) zap.Field
- func Int64(key string, val int64) zap.Field
- func IsDebug() bool
- func IsTerminal(f *os.File) bool
- func LevelString(l zapcore.Level) string
- func Reflect(key string, val interface{}) zap.Field
- func RegisterLogger(module string, logger *zap.Logger, ignoreModuleAndRole bool)
- func SimpleAccessLevelEncoder(l zapcore.Level, enc zapcore.PrimitiveArrayEncoder)
- func SimpleLevelEncoder(l zapcore.Level, enc zapcore.PrimitiveArrayEncoder)
- func SimpleTimeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder)
- func Stack() zap.Field
- func String(key, val string) zap.Field
- func Uint16(key string, val uint16) zap.Field
- func Uint32(key string, val uint32) zap.Field
- type Color
- type Logger
- type Setting
Constants ¶
This section is empty.
Variables ¶
var ( DebugLevel = zapcore.DebugLevel InfoLevel = zapcore.InfoLevel WarnLevel = zapcore.WarnLevel ErrorLevel = zapcore.ErrorLevel DPanicLevel = zapcore.DPanicLevel PanicLevel = zapcore.PanicLevel FatalLevel = zapcore.FatalLevel )
var ( // IsCli represents if command-line. IsCli = false // RunningAtomicLevel supports changing level on the fly RunningAtomicLevel = zap.NewAtomicLevelAt(zapcore.InfoLevel) AccessLogModule = "AccessLog" DefaultLogger atomic.Value )
Functions ¶
func Any ¶
Any takes a key and an arbitrary value and chooses the best way to represent them as a field, falling back to a reflection-based approach only if necessary.
func InitLogger ¶
func InitLogger(fileName string, setting Setting, cfg *zapcore.EncoderConfig, options ...zap.Option) (*zap.Logger, error)
InitLogger initializes a zap logger from user config
func IsTerminal ¶
IsTerminal checks if the stdOut is a terminal or not
func LevelString ¶
LevelString returns a upper-case ASCII representation of the log level.
func Reflect ¶
Reflect constructs a field with the given key and an arbitrary object. It uses an encoding-appropriate, reflection-based function to lazily serialize nearly any object into the logging context, but it's relatively slow and allocation-heavy. Outside tests, Any is always a better choice.
If encoding fails (e.g., trying to serialize a map[int]string to JSON), Reflect includes the error message in the final log output.
func RegisterLogger ¶
func SimpleAccessLevelEncoder ¶ added in v0.0.4
func SimpleAccessLevelEncoder(l zapcore.Level, enc zapcore.PrimitiveArrayEncoder)
SimpleAccessLevelEncoder serializes access log level
func SimpleLevelEncoder ¶
func SimpleLevelEncoder(l zapcore.Level, enc zapcore.PrimitiveArrayEncoder)
SimpleLevelEncoder serializes a Level to a upper case string. For example, InfoLevel is serialized to "INFO".
func SimpleTimeEncoder ¶
func SimpleTimeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder)
SimpleTimeEncoder serializes a time.Time to a simplified format without timezone
func Stack ¶
Stack constructs a field that stores a stacktrace of the current goroutine under provided key. Keep in mind that taking a stacktrace is eager and expensive (relatively speaking); this function both makes an allocation and takes about two microseconds.
Types ¶
type Logger ¶
type Logger interface { // Debug logs a message at DebugLevel. The message includes any fields passed // at the log site, as well as any fields accumulated on the logger. Debug(msg string, fields ...zap.Field) // Info logs a message at InfoLevel. The message includes any fields passed // at the log site, as well as any fields accumulated on the logger. Info(msg string, fields ...zap.Field) // Warn logs a message at WarnLevel. The message includes any fields passed // at the log site, as well as any fields accumulated on the logger. Warn(msg string, fields ...zap.Field) // Error logs a message at ErrorLevel. The message includes any fields passed // at the log site, as well as any fields accumulated on the logger. Error(msg string, fields ...zap.Field) // Enabled decides whether a given logging level is enabled when logging a message. Enabled(level zapcore.Level) bool }
logger is wrapper for zap logger with module.
type Setting ¶
type Setting struct { Dir string `env:"DIR" toml:"dir"` Level string `env:"LEVEL" toml:"level"` MaxSize ltoml.Size `env:"MAX_SIZE" toml:"maxsize"` MaxBackups uint16 `env:"MAX_BACKUPS" toml:"maxbackups"` MaxAge uint16 `env:"MAX_AGE" toml:"maxage"` }
Setting represents a logging configuration.
func NewDefaultSetting ¶
func NewDefaultSetting() *Setting
NewDefaultSetting returns a new default logging setting.