Documentation ¶
Index ¶
- Constants
- Variables
- func CopyFields(fields map[string]interface{}) []zap.Field
- func Debug(args ...interface{})
- func Debugf(format string, args ...interface{})
- func Debugw(msg string, keysAndValues ...interface{})
- func Error(args ...interface{})
- func Errorf(format string, args ...interface{})
- func Errorw(msg string, keysAndValues ...interface{})
- func Fatal(args ...interface{})
- func Fatalf(format string, args ...interface{})
- func Fatalw(msg string, keysAndValues ...interface{})
- func Info(args ...interface{})
- func Infof(format string, args ...interface{})
- func Infow(msg string, keysAndValues ...interface{})
- func InitLogger(log Logger)
- func Must(err error)
- func SetLevel(lv Level)
- func Sync() error
- func Warn(args ...interface{})
- func Warnf(format string, args ...interface{})
- func Warnw(msg string, keysAndValues ...interface{})
- type Default
- func (l *Default) Debug(args ...interface{})
- func (l *Default) Debugf(template string, args ...interface{})
- func (l *Default) Debugw(msg string, keysAndValues ...interface{})
- func (l *Default) Error(args ...interface{})
- func (l *Default) Errorf(template string, args ...interface{})
- func (l *Default) Errorw(msg string, keysAndValues ...interface{})
- func (l *Default) Fatal(args ...interface{})
- func (l *Default) Fatalf(template string, args ...interface{})
- func (l *Default) Fatalw(msg string, keysAndValues ...interface{})
- func (l *Default) Info(args ...interface{})
- func (l *Default) Infof(template string, args ...interface{})
- func (l *Default) Infow(msg string, keysAndValues ...interface{})
- func (l *Default) LevelEnablerFunc(level zapcore.Level) LevelEnablerFunc
- func (l *Default) Log(level Level, template string, fmtArgs []interface{}, context []interface{})
- func (l *Default) Options() Option
- func (l *Default) SetLevel(lv Level)
- func (l *Default) StdLog() *std.Logger
- func (l *Default) Sync() error
- func (l *Default) Warn(args ...interface{})
- func (l *Default) Warnf(template string, args ...interface{})
- func (l *Default) Warnw(msg string, keysAndValues ...interface{})
- func (l *Default) WithCallDepth(callDepth int) Logger
- func (l *Default) WithContext(ctx context.Context) Logger
- func (l *Default) WithError(err error) Logger
- func (l *Default) WithFields(fields map[string]interface{}) Logger
- type Encoder
- type Level
- type LevelEnablerFunc
- type Logger
- type Option
- type Options
- func WithBasePath(path string) Options
- func WithCallerSkip(skip int) Options
- func WithConsole(enableConsole bool) Options
- func WithDisableDisk(disableDisk bool) Options
- func WithEncoder(encoder Encoder) Options
- func WithEncoderConfig(encoderConfig zapcore.EncoderConfig) Options
- func WithFields(fields map[string]interface{}) Options
- func WithFilename(filename string) Options
- func WithLevel(lv Level) Options
- func WithNamespace(name string) Options
- type RollingFile
- type RollingFormat
Constants ¶
const ( // DebugLevel level. Usually only enabled when debugging. Very verbose logging. DebugLevel = iota + 1 // InfoLevel is the default logging priority. // General operational entries about what's going on inside the application. InfoLevel // WarnLevel level. Non-critical entries that deserve eyes. WarnLevel // ErrorLevel level. Logs. Used for errors that should definitely be noted. ErrorLevel // FatalLevel level. Logs and then calls `logger.Exit(1)`. highest level of severity. FatalLevel )
const ( MonthlyRolling RollingFormat = "200601" DailyRolling = "20060102" HourlyRolling = "2006010215" MinutelyRolling = "200601021504" SecondlyRolling = "20060102150405" )
RollingFormats
Variables ¶
var ( ErrClosedRollingFile = errors.New("rolling file is closed") ErrBuffer = errors.New("buffer exceeds the limit") )
Errors
var ( // ErrLogPathNotSet is an error that indicates the log path is not set. ErrLogPathNotSet = errors.New("log path must be set") )
Functions ¶
func CopyFields ¶
func Debugf ¶
func Debugf(format string, args ...interface{})
Debugf uses fmt.Sprintf to log a templated message.
func Debugw ¶
func Debugw(msg string, keysAndValues ...interface{})
Debugw logs a message with some additional context. The variadic key-value pairs are treated as they are in With.
When debug-level logging is disabled, this is much faster than
s.With(keysAndValues).Debug(msg)
func Errorf ¶
func Errorf(format string, args ...interface{})
Errorf uses fmt.Sprintf to log a templated message.
func Errorw ¶
func Errorw(msg string, keysAndValues ...interface{})
Errorw logs a message with some additional context. The variadic key-value pairs are treated as they are in With.
func Fatal ¶
func Fatal(args ...interface{})
Fatal uses fmt.Sprint to construct and log a message, then calls os.Exit. Deprecated: 记录消息后,直接调用 os.Exit(1),这意味着: 在其他 goroutine defer 语句不会被执行; 各种 buffers 不会被 flush,包括日志的; 临时文件或者目录不会被移除; 不要使用 fatal 记录日志,而是向调用者返回错误。如果错误一直持续到 main.main。main.main 那就是在退出之前做处理任何清理操作的正确位置。
func Fatalf ¶
func Fatalf(format string, args ...interface{})
Fatalf uses fmt.Sprintf to log a templated message, then calls os.Exit. Deprecated: 记录消息后,直接调用 os.Exit(1),这意味着: 在其他 goroutine defer 语句不会被执行; 各种 buffers 不会被 flush,包括日志的; 临时文件或者目录不会被移除; 不要使用 fatal 记录日志,而是向调用者返回错误。如果错误一直持续到 main.main。main.main 那就是在退出之前做处理任何清理操作的正确位置。
func Fatalw ¶
func Fatalw(msg string, keysAndValues ...interface{})
Fatalw logs a message with some additional context, then calls os.Exit. The variadic key-value pairs are treated as they are in With. Deprecated: 记录消息后,直接调用 os.Exit(1),这意味着: 在其他 goroutine defer 语句不会被执行; 各种 buffers 不会被 flush,包括日志的; 临时文件或者目录不会被移除; 不要使用 fatal 记录日志,而是向调用者返回错误。如果错误一直持续到 main.main。main.main 那就是在退出之前做处理任何清理操作的正确位置。
func Infof ¶
func Infof(format string, args ...interface{})
Infof uses fmt.Sprintf to log a templated message.
func Infow ¶
func Infow(msg string, keysAndValues ...interface{})
Infow logs a message with some additional context. The variadic key-value pairs are treated as they are in With.
Types ¶
type Default ¶
type Default struct {
// contains filtered or unexported fields
}
Default default logger achieve
func (*Default) Debug ¶
func (l *Default) Debug(args ...interface{})
Debug uses fmt.Sprint to construct and log a message.
func (*Default) Debugw ¶
Debugw logs a message with some additional context. The variadic key-value pairs are treated as they are in With.
When debug-level logging is disabled, this is much faster than
s.With(keysAndValues).Debug(msg)
func (*Default) Error ¶
func (l *Default) Error(args ...interface{})
Error uses fmt.Sprint to construct and log a message.
func (*Default) Errorw ¶
Errorw logs a message with some additional context. The variadic key-value pairs are treated as they are in With.
func (*Default) Fatal ¶
func (l *Default) Fatal(args ...interface{})
Fatal uses fmt.Sprint to construct and log a message, then calls os.Exit. Deprecated: 记录消息后,直接调用 os.Exit(1),这意味着: 在其他 goroutine defer 语句不会被执行; 各种 buffers 不会被 flush,包括日志的; 临时文件或者目录不会被移除; 不要使用 fatal 记录日志,而是向调用者返回错误。如果错误一直持续到 main.main。main.main 那就是在退出之前做处理任何清理操作的正确位置。
func (*Default) Fatalf ¶
Fatalf uses fmt.Sprintf to log a templated message, then calls os.Exit. Deprecated: 记录消息后,直接调用 os.Exit(1),这意味着: 在其他 goroutine defer 语句不会被执行; 各种 buffers 不会被 flush,包括日志的; 临时文件或者目录不会被移除; 不要使用 fatal 记录日志,而是向调用者返回错误。如果错误一直持续到 main.main。main.main 那就是在退出之前做处理任何清理操作的正确位置。
func (*Default) Fatalw ¶
Fatalw logs a message with some additional context, then calls os.Exit. The variadic key-value pairs are treated as they are in With. Deprecated: 记录消息后,直接调用 os.Exit(1),这意味着: 在其他 goroutine defer 语句不会被执行; 各种 buffers 不会被 flush,包括日志的; 临时文件或者目录不会被移除; 不要使用 fatal 记录日志,而是向调用者返回错误。如果错误一直持续到 main.main。main.main 那就是在退出之前做处理任何清理操作的正确位置。
func (*Default) Info ¶
func (l *Default) Info(args ...interface{})
Info uses fmt.Sprint to construct and log a message.
func (*Default) Infow ¶
Infow logs a message with some additional context. The variadic key-value pairs are treated as they are in With.
func (*Default) LevelEnablerFunc ¶
func (l *Default) LevelEnablerFunc(level zapcore.Level) LevelEnablerFunc
func (*Default) Warn ¶
func (l *Default) Warn(args ...interface{})
Warn uses fmt.Sprint to construct and log a message.
func (*Default) Warnw ¶
Warnw logs a message with some additional context. The variadic key-value pairs are treated as they are in With.
func (*Default) WithCallDepth ¶
WithCallDepth with logger call depth.
func (*Default) WithContext ¶
WithContext with context
func (*Default) WithFields ¶
WithFields set fields to always be logged
type Level ¶
type Level int8
func ParseLevel ¶
ParseLevel parses a level string into a logger Level value.
type LevelEnablerFunc ¶
LevelEnablerFunc is a convenient way to implement zapcore.LevelEnabler with an anonymous function.
It's particularly useful when splitting log output between different outputs (e.g., standard error and standard out). For sample code, see the package-level AdvancedConfiguration example.
type Logger ¶
type Logger interface { // Options The Logger options Options() Option // SetLevel set logger level SetLevel(lv Level) // WithContext with context WithContext(ctx context.Context) Logger // WithFields set fields to always be logged WithFields(fields map[string]interface{}) Logger // WithCallDepth with logger call depth. WithCallDepth(callDepth int) Logger // WithError with logger error WithError(err error) Logger // Debug uses fmt.Sprint to construct and log a message. Debug(args ...interface{}) // Info uses fmt.Sprint to construct and log a message. Info(args ...interface{}) // Warn uses fmt.Sprint to construct and log a message. Warn(args ...interface{}) // Error uses fmt.Sprint to construct and log a message. Error(args ...interface{}) // Fatal uses fmt.Sprint to construct and log a message, then calls os.Exit. Fatal(args ...interface{}) // Debugf uses fmt.Sprintf to log a templated message. Debugf(template string, args ...interface{}) // Infof uses fmt.Sprintf to log a templated message. Infof(template string, args ...interface{}) // Warnf uses fmt.Sprintf to log a templated message. Warnf(template string, args ...interface{}) // Errorf uses fmt.Sprintf to log a templated message. Errorf(template string, args ...interface{}) // Fatalf uses fmt.Sprintf to log a templated message, then calls os.Exit. Fatalf(template string, args ...interface{}) // Debugw logs a message with some additional context. The variadic key-value // pairs are treated as they are in With. // // When debug-level logging is disabled, this is much faster than // s.With(keysAndValues).Debug(msg) Debugw(msg string, keysAndValues ...interface{}) // Infow logs a message with some additional context. The variadic key-value // pairs are treated as they are in With. Infow(msg string, keysAndValues ...interface{}) // Warnw logs a message with some additional context. The variadic key-value // pairs are treated as they are in With. Warnw(msg string, keysAndValues ...interface{}) // Errorw logs a message with some additional context. The variadic key-value // pairs are treated as they are in With. Errorw(msg string, keysAndValues ...interface{}) // Fatalw logs a message with some additional context, then calls os.Exit. The // variadic key-value pairs are treated as they are in With. Fatalw(msg string, keysAndValues ...interface{}) // Log writes a log entry Log(level Level, template string, fmtArgs []interface{}, context []interface{}) StdLog() *std.Logger // Sync logger sync Sync() error }
func InitDefaultLogger ¶
func InitDefaultLogger() Logger
func WithContext ¶
WithContext returns a shallow copy of l with its context changed to ctx. The provided ctx must be non-nil.
type Options ¶
type Options func(o *Option)
func WithCallerSkip ¶
WithCallerSkip increases the number of callers skipped by caller annotation (as enabled by the AddCaller option). When building wrappers around the Logger and SugaredLogger, supplying this Option prevents base from always reporting the wrapper code as the caller.
func WithEncoderConfig ¶
func WithEncoderConfig(encoderConfig zapcore.EncoderConfig) Options
WithEncoderConfig set logger encoderConfig
func WithFields ¶
WithFields set default fields for the logger
func WithNamespace ¶
WithNamespace creates a named, isolated scope within the logger's context. All subsequent fields will be added to the new namespace.
This helps prevent key collisions when injecting loggers into sub-components or third-party libraries.
type RollingFile ¶
type RollingFile struct {
// contains filtered or unexported fields
}
RollingFile : Defination of rolling
func NewRollingFile ¶
func NewRollingFile(basePath string, rolling RollingFormat) (*RollingFile, error)
NewRollingFile create new rolling
func (*RollingFile) SetRolling ¶
func (r *RollingFile) SetRolling(fmt RollingFormat)
SetRolling : Set rolling format