Documentation
¶
Index ¶
- Constants
- type LogFormat
- type Logger
- func (l *Logger) Fork() *Logger
- func (l *Logger) GetLevel() zapcore.Level
- func (l *Logger) Named(name string) *Logger
- func (l *Logger) SetLevel(lvl zapcore.Level)
- func (l *Logger) SetLevelString(text string) error
- func (l *Logger) With(fields ...interface{}) *Logger
- func (l *Logger) WithOptions(_ ...Option) *Logger
- type Option
- func WithConsoleLogFormat(format LogFormat) Option
- func WithDevelopmentMode() Option
- func WithErrorLogOutput(w io.Writer) Option
- func WithLevel(level zapcore.Level) Option
- func WithMonochrome(b bool) Option
- func WithNormalLogOutput(w io.Writer) Option
- func WithOutputFile(p string) Option
- func WithOutputFileCompress(b bool) Option
- func WithOutputFileLogFormat(format LogFormat) Option
- func WithOutputFileMaxSizeInMB(s uint) Option
- func WithOutputFileRetainNum(n uint) Option
- func WithStacktraceLevel(lvl zapcore.Level) Option
- func WithStacktraceLevelString(text string) Option
- func WithZapOptions(opts ...zap.Option) Option
Constants ¶
const ( // LogFormatConsole indicates the console format, i.e. [time] [level] [caller] [message] [fields*] LogFormatConsole = "console" // LogFormatJSON indicates the JSON format. LogFormatJSON = "json" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Logger ¶
type Logger struct { *zap.SugaredLogger // contains filtered or unexported fields }
Logger is a wrapper of zap.SugaredLogger with some extra features.
func NewJSONLogger ¶
NewJSONLogger returns a logger which outputs in JSON format only and keeps 10 recent log archives.
func NewNoopLogger ¶
func NewNoopLogger() *Logger
NewNoopLogger returns a no-op logger which does nothing except panicking when calling Fatal or Panic.
func NewPersistentLogger ¶
NewPersistentLogger returns a logger which keeps all the log file in JSON format and never cleans up.
func NewSimpleLogger ¶
func NewSimpleLogger() *Logger
NewSimpleLogger returns a simple logger which writes to stdout/stderr only with process id in development mode.
func (*Logger) SetLevelString ¶
SetLevelString sets the log level by string.
func (*Logger) WithOptions ¶ added in v0.1.2
type Option ¶
type Option func(*config)
Option is a function that configures the logger.
func WithConsoleLogFormat ¶
WithConsoleLogFormat configures the format of the console log output.
func WithDevelopmentMode ¶
func WithDevelopmentMode() Option
WithDevelopmentMode configures the development mode.
func WithErrorLogOutput ¶
WithErrorLogOutput configures the io.Writer for logs at or above error level.
func WithMonochrome ¶
WithMonochrome configures the monochrome mode of console output.
func WithNormalLogOutput ¶
WithNormalLogOutput configures the io.Writer for logs under error level.
func WithOutputFile ¶
WithOutputFile configures the output file path.
func WithOutputFileCompress ¶
WithOutputFileCompress configures whether to compress the output file.
func WithOutputFileLogFormat ¶
WithOutputFileLogFormat configures the format of the output file log output.
func WithOutputFileMaxSizeInMB ¶
WithOutputFileMaxSizeInMB configures the max size of the output file in MB.
func WithOutputFileRetainNum ¶
WithOutputFileRetainNum configures the number of output files to retain, 0 means unlimited.
func WithStacktraceLevel ¶
WithStacktraceLevel configures a logger to record a stack trace for all messages at or above a given level.
func WithStacktraceLevelString ¶
WithStacktraceLevelString configures a logger to record a stack trace for all messages at or above a given level, if the level string is invalid, it will be ignored.
func WithZapOptions ¶
WithZapOptions wraps the zap.Options to configure the logger.