Documentation
¶
Index ¶
- Variables
- func Setup(opts ...Option)
- type CallerEncoder
- type Encoder
- type EncoderConfig
- type Level
- type LevelEnabler
- type LevelEncoder
- type Logger
- type LoggerType
- type MockCheckWriteHook
- type Option
- func AddCaller() Option
- func AddCallerSkip(skip int) Option
- func AddStacktrace(lvl Level) Option
- func ErrorOutput(w io.Writer) Option
- func Fields(fs map[string]interface{}) Option
- func SetProjectName(pname string) Option
- func WithEncoder(encoder Encoder) Option
- func WithEncoderCfg(cfg EncoderConfig) Option
- func WithLevelEnabler(lvl Level) Option
- func WithOnFatal(onFatal any) Option
- func WithWriter(writer io.Writer) Option
- type Options
- type TimeEncoder
- type ZapOption
- func WithZapEncoder(encoder zapcore.Encoder) ZapOption
- func WithZapErrWriter(w io.Writer) ZapOption
- func WithZapFields(fields []zap.Field) ZapOption
- func WithZapLevelEnabler(lv Level) ZapOption
- func WithZapOnFatal(onFatal zapcore.CheckWriteHook) ZapOption
- func WithZapOptions(zopts []zap.Option) ZapOption
- func WithZapWriter(w io.Writer) ZapOption
Constants ¶
This section is empty.
Variables ¶
var ( Info func(args ...interface{}) Warn func(args ...interface{}) Error func(args ...interface{}) Fatal func(args ...interface{}) Notice func(args ...interface{}) Debug func(args ...interface{}) Infof func(format string, args ...interface{}) Warnf func(format string, args ...interface{}) Errorf func(format string, args ...interface{}) Fatalf func(format string, args ...interface{}) Noticef func(format string, args ...interface{}) Debugf func(format string, args ...interface{}) WithField func(key string, value interface{}) Logger WithFields func(fields map[string]interface{}) Logger WithTraceId func(ctx context.Context) Logger )
Functions ¶
Types ¶
type CallerEncoder ¶
type CallerEncoder int
FullCallerEncoder serializes a caller in /full/path/to/package/file:line format. ShortCallerEncoder serializes a caller in package/file:line format, trimming all but the final directory from the full path.
const ( FullCallerEncoder CallerEncoder = iota ShortCallerEncoder )
type EncoderConfig ¶
type EncoderConfig struct { MessageKey string LevelKey string EncodeLevel LevelEncoder TimeKey string EncodeTime TimeEncoder CallerKey string EncodeCaller CallerEncoder StacktraceKey string }
func NewEncoderConfig ¶
func NewEncoderConfig() EncoderConfig
type Level ¶
type Level int
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 // PanicLevel logs a message, then panics. PanicLevel // FatalLevel logs a message, then calls os.Exit(1). FatalLevel // NoticeLevel logs a message, then make a log alert NoticeLevel TraceLevel = DebugLevel )
type LevelEnabler ¶
LevelEnabler decides whether a given logging level is enabled when logging a message.
Enablers are intended to be used to implement deterministic filters; concerns like sampling are better implemented as a Core.
Each concrete Level value implements a static LevelEnabler which returns true for itself and all higher logging levels. For example WarnLevel.Enabled() will return true for WarnLevel, ErrorLevel, DPanicLevel, PanicLevel, and FatalLevel, but return false for InfoLevel and DebugLevel.
type LevelEncoder ¶
type LevelEncoder int
LowercaseLevelEncoder serializes a Level to a lowercase string. For example, InfoLevel is serialized to "info". CapitalLevelEncoder serializes a Level to an all-caps string. For example, InfoLevel is serialized to "INFO".
const ( LowercaseLevelEncoder LevelEncoder = iota CapitalLevelEncoder )
type Logger ¶
type Logger interface { Debug(args ...interface{}) Debugf(format string, args ...interface{}) Info(args ...interface{}) Infof(format string, args ...interface{}) Warn(args ...interface{}) Warnf(format string, args ...interface{}) Error(args ...interface{}) Errorf(format string, args ...interface{}) Trace(args ...interface{}) Tracef(format string, args ...interface{}) Panic(args ...interface{}) Panicf(format string, args ...interface{}) Fatal(args ...interface{}) Fatalf(format string, args ...interface{}) Notice(args ...interface{}) Noticef(format string, args ...interface{}) WithField(key string, value interface{}) Logger WithFields(fields map[string]interface{}) Logger WithTraceId(ctx context.Context) Logger SetLogLevel(level Level) error LogLevel() Level }
type MockCheckWriteHook ¶
type MockCheckWriteHook struct{}
MockCheckWriteHook should be careful for test, should be recover
func (*MockCheckWriteHook) OnWrite ¶
func (mcw *MockCheckWriteHook) OnWrite(e *zapcore.CheckedEntry, _ []zapcore.Field)
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
func AddCaller ¶
func AddCaller() Option
AddCaller configures the Logger to annotate each message with the filename and line number of logger's caller.
func AddCallerSkip ¶
AddCallerSkip increases the number of callers skipped by caller annotation (as enabled by the AddCaller option).
func AddStacktrace ¶
AddStacktrace configures the Logger to record a stack trace for all messages at or above a given level.
func ErrorOutput ¶
ErrorOutput sets the destination for errors generated by the Logger. Note that this option only affects internal errors; for sample code that sends error-level logs to a different location from info- and debug-level logs, see the package-level AdvancedConfiguration example.
func SetProjectName ¶
func WithEncoder ¶
func WithEncoderCfg ¶
func WithEncoderCfg(cfg EncoderConfig) Option
func WithLevelEnabler ¶
LevelEnabler decides whether a given logging level is enabled when logging a message.
func WithOnFatal ¶
func WithWriter ¶
type TimeEncoder ¶
type TimeEncoder int
A TimeEncoder serializes a time.Time to a primitive type.
const ( RFC3339TimeEncoder TimeEncoder = iota RFC3339MilliTimeEncoder RFC3339NanoTimeEncoder )
type ZapOption ¶
type ZapOption interface {
// contains filtered or unexported methods
}
func WithZapEncoder ¶
func WithZapErrWriter ¶
func WithZapFields ¶
func WithZapLevelEnabler ¶
func WithZapOnFatal ¶
func WithZapOnFatal(onFatal zapcore.CheckWriteHook) ZapOption
func WithZapOptions ¶
func WithZapWriter ¶
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
writer
|
|
rotate/file-rotatelogs
package rotatelogs is a port of File-RotateLogs from Perl (https://metacpan.org/release/File-RotateLogs), and it allows you to automatically rotate output files when you write to them according to the filename pattern that you can specify.
|
package rotatelogs is a port of File-RotateLogs from Perl (https://metacpan.org/release/File-RotateLogs), and it allows you to automatically rotate output files when you write to them according to the filename pattern that you can specify. |