Documentation ¶
Index ¶
- Constants
- Variables
- func Debug(msg string, fields ...Field)
- func Debugf(format string, v ...interface{})
- func Debugw(msg string, kv ...interface{})
- func Error(msg string, fields ...Field)
- func Errorf(format string, v ...interface{})
- func Errorw(msg string, kv ...interface{})
- func Fatal(msg string, fields ...Field)
- func Fatalf(format string, v ...interface{})
- func Fatalw(msg string, kv ...interface{})
- func Flush()
- func Info(msg string, fields ...Field)
- func Infof(format string, v ...interface{})
- func Infow(msg string, kv ...interface{})
- func Init(opts *Options)
- func LoggerErr() *log.Logger
- func LoggerInfo() *log.Logger
- func LoggerSugared() *zap.SugaredLogger
- func New(opts *Options) *zapLogger
- func Panic(msg string, fields ...Field)
- func Panicf(format string, v ...interface{})
- func Panicw(msg string, kv ...interface{})
- func Record(ctx context.Context) *zapLogger
- func StdInfoLogger() *log.Logger
- func Warn(msg string, fields ...Field)
- func Warnf(format string, v ...interface{})
- func Warnw(msg string, kv ...interface{})
- type Field
- type InfoLogger
- type Level
- type Logger
- type Options
Constants ¶
const ( KeyRequestID string = "requestID" KeyUsername string = "username" )
Variables ¶
var ( DebugLevel = zapcore.DebugLevel InfoLevel = zapcore.InfoLevel WarnLevel = zapcore.WarnLevel ErrorLevel = zapcore.ErrorLevel PanicLevel = zapcore.PanicLevel FatalLevel = zapcore.FatalLevel )
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 )
Functions ¶
func LoggerErr ¶
ErrLogger creates and returns a standard library *log.Logger instance that logs at the ErrorLevel in zap. If the global logger is not initialized, it safely returns nil.
func LoggerInfo ¶
InfoLogger creates and returns a standard library *log.Logger instance that logs at the InfoLevel in zap. If the global logger is not initialized, it returns nil.
func LoggerSugared ¶
func LoggerSugared() *zap.SugaredLogger
SugaredLogger returns a *zap.SugaredLogger instance, offering a more flexible logging approach. This logger supports fast and loosely-typed logging, suitable for most use cases.
func New ¶
func New(opts *Options) *zapLogger
New create logger by opts which can custmoized by command arguments.
func StdInfoLogger ¶
StdInfoLogger returns logger of standard library which writes to supplied zap logger at info level.
Types ¶
type InfoLogger ¶
type InfoLogger interface { Info(msg string, fields ...Field) Infof(format string, v ...interface{}) Infokv(msg string, kv ...interface{}) Enabled() bool }
func LoggerForLevel ¶
func LoggerForLevel(level Level) InfoLogger
LoggerForLevel returns a logger for the specified logging level.
type Logger ¶
type Logger interface { InfoLogger Debug(msg string, fields ...Field) Debugf(format string, v ...interface{}) Debugkv(msg string, kv ...interface{}) Warn(msg string, fields ...Field) Warnf(format string, v ...interface{}) Warnkv(msg string, kv ...interface{}) Error(msg string, fields ...Field) Errorf(format string, v ...interface{}) Errorkv(msg string, kv ...interface{}) Panic(msg string, fields ...Field) Panicf(format string, v ...interface{}) Panickv(msg string, kv ...interface{}) Fatal(msg string, fields ...Field) Fatalf(format string, v ...interface{}) Fatalkv(msg string, kv ...interface{}) LoggerForLevel(level zapcore.Level) InfoLogger Write(p []byte) (n int, err error) WithValues(kv ...interface{}) Logger WithName(name string) Logger WithContext(ctx context.Context) context.Context Sync() }
func WithValues ¶
func WithValues(kv ...interface{}) Logger
type Options ¶
type Options struct { Level string `json:"level" mapstructure:"level"` Format string `json:"format" mapstructure:"format"` DisableCaller bool `json:"disable-caller" mapstructure:"disable-caller"` DisableStacktrace bool `json:"disable-stacktrace" mapstructure:"disable-stacktrace"` EnableColor bool `json:"enable-color" mapstructure:"enable-color"` Development bool `json:"development" mapstructure:"development"` Name string `json:"name" mapstructure:"name"` OutputPaths []string `json:"output-paths" mapstructure:"output-paths"` ErrorOutputPaths []string `json:"error-output-paths" mapstructure:"error-output-paths"` }
func NewOptions ¶
func NewOptions() *Options
NewOptions creates a new instance of Options with default values.
func (*Options) AddFlags ¶
AddFlags adds logging-related command line flags to the provided FlagSet. This allows the configuration of the logging system via command line parameters.
func (*Options) Build ¶
Build constructs and configures a global zap logger based on the Options settings. It sets up the logger with the specified level, format, output paths, and other configurations.