Documentation
¶
Index ¶
- Constants
- func InitFromConfig(conf Config, opts ...Option) (err error)
- func InitFromJson(conf []byte, opts ...Option) (err error)
- func InitFromOption(opts ...Option) (err error)
- func NewFromConfig(conf Config, opts ...Option) (_ internal.XLog, err error)
- func NewFromJson(conf []byte, opts ...Option) (_ internal.XLog, err error)
- func NewFromOption(opts ...Option) (_ internal.XLog, err error)
- type Config
- type Level
- type Option
- func WithCaller() Option
- func WithCallerSkip(skip int) Option
- func WithDevelopment() Option
- func WithEncoding(enc string) Option
- func WithErrorOutput(w zapcore.WriteSyncer) Option
- func WithFields(fs ...zap.Field) Option
- func WithHooks(hooks ...func(zapcore.Entry) error) Option
- func WithLevel(ll Level) Option
- func WithStacktrace(lvl zapcore.LevelEnabler) Option
Constants ¶
const ( // DebugLevel logs are typically voluminous, and are usually disabled in // production. DebugLevel = zapcore.DebugLevel // InfoLevel is the default logging priority. InfoLevel = zapcore.InfoLevel // WarnLevel logs are more important than Info, but don't need individual // human review. WarnLevel = zapcore.WarnLevel // ErrorLevel logs are high-priority. If an application is running smoothly, // it shouldn't generate any error-level logs. ErrorLevel = zapcore.ErrorLevel // DPanicLevel logs are particularly important errors. In development the // logger panics after writing the message. DPanicLevel = zapcore.DPanicLevel // PanicLevel logs a message, then panics. PanicLevel = zapcore.PanicLevel // FatalLevel logs a message, then calls os.Exit(1). FatalLevel = zapcore.FatalLevel )
Variables ¶
This section is empty.
Functions ¶
func InitFromConfig ¶
func InitFromJson ¶
func InitFromOption ¶
Types ¶
type Config ¶
type Config config
func NewDevConfig ¶
func NewDevConfig() Config
func NewProdConfig ¶
func NewProdConfig() Config
type Option ¶
type Option func(opts *config)
func WithCaller ¶
func WithCaller() Option
AddCaller configures the Logger to annotate each message with the filename and line number of zap's caller.
func WithCallerSkip ¶
AddCallerSkip 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 zap from always reporting the wrapper code as the caller.
func WithDevelopment ¶
func WithDevelopment() Option
Development puts the logger in development mode, which makes DPanic-level logs panic instead of simply logging an error.
func WithErrorOutput ¶
func WithErrorOutput(w zapcore.WriteSyncer) Option
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.
The supplied WriteSyncer must be safe for concurrent use. The Open and zapcore.Lock functions are the simplest ways to protect files with a mutex.
func WithHooks ¶
Hooks registers functions which will be called each time the Logger writes out an Entry. Repeated use of Hooks is additive.
Hooks are useful for simple side effects, like capturing metrics for the number of emitted logs. More complex side effects, including anything that requires access to the Entry's structured fields, should be implemented as a zapcore.Core instead. See zapcore.RegisterHooks for details.
func WithStacktrace ¶
func WithStacktrace(lvl zapcore.LevelEnabler) Option
AddStacktrace configures the Logger to record a stack trace for all messages at or above a given level.