Documentation ¶
Index ¶
- Constants
- func ActivateSpec(spec string)
- func DefaultLevel() string
- func GetLoggerLevel(loggerName string) string
- func Init(config Config)
- func InitBackend(formatter logging.Formatter, output io.Writer)
- func InitFromSpec(spec string) string
- func IsValidLevel(level string) bool
- func NameToLevel(level string) zapcore.Level
- func NewGRPCLogger(l *zap.Logger) *zapgrpc.Logger
- func NewZapLogger(core zapcore.Core, options ...zap.Option) *zap.Logger
- func Reset()
- func SetFormat(formatSpec string) logging.Formatter
- type Config
- type Core
- type Encoding
- type EncodingSelector
- type FabricLogger
- func (f *FabricLogger) Critical(args ...interface{})
- func (f *FabricLogger) Criticalf(template string, args ...interface{})
- func (f *FabricLogger) DPanic(args ...interface{})
- func (f *FabricLogger) DPanicf(template string, args ...interface{})
- func (f *FabricLogger) DPanicw(msg string, kvPairs ...interface{})
- func (f *FabricLogger) Debug(args ...interface{})
- func (f *FabricLogger) Debugf(template string, args ...interface{})
- func (f *FabricLogger) Debugw(msg string, kvPairs ...interface{})
- func (f *FabricLogger) Error(args ...interface{})
- func (f *FabricLogger) Errorf(template string, args ...interface{})
- func (f *FabricLogger) Errorw(msg string, kvPairs ...interface{})
- func (f *FabricLogger) Fatal(args ...interface{})
- func (f *FabricLogger) Fatalf(template string, args ...interface{})
- func (f *FabricLogger) Fatalw(msg string, kvPairs ...interface{})
- func (f *FabricLogger) Info(args ...interface{})
- func (f *FabricLogger) Infof(template string, args ...interface{})
- func (f *FabricLogger) Infow(msg string, kvPairs ...interface{})
- func (f *FabricLogger) IsEnabledFor(level zapcore.Level) bool
- func (f *FabricLogger) Named(name string) *FabricLogger
- func (f *FabricLogger) Notice(args ...interface{})
- func (f *FabricLogger) Noticef(template string, args ...interface{})
- func (f *FabricLogger) Panic(args ...interface{})
- func (f *FabricLogger) Panicf(template string, args ...interface{})
- func (f *FabricLogger) Panicw(msg string, kvPairs ...interface{})
- func (f *FabricLogger) Sync() error
- func (f *FabricLogger) Warn(args ...interface{})
- func (f *FabricLogger) Warnf(template string, args ...interface{})
- func (f *FabricLogger) Warning(args ...interface{})
- func (f *FabricLogger) Warningf(template string, args ...interface{})
- func (f *FabricLogger) Warnw(msg string, kvPairs ...interface{})
- func (f *FabricLogger) With(args ...interface{}) *FabricLogger
- func (f *FabricLogger) WithOptions(opts ...zap.Option) *FabricLogger
- func (f *FabricLogger) Zap() *zap.Logger
- type LoggerLevels
- type Logging
- func (s *Logging) Apply(c Config) error
- func (s *Logging) Check(e zapcore.Entry, ce *zapcore.CheckedEntry)
- func (s *Logging) Encoding() Encoding
- func (s *Logging) Logger(name string) *FabricLogger
- func (s *Logging) SetFormat(format string) error
- func (s *Logging) SetObserver(observer Observer)
- func (s *Logging) SetWriter(w io.Writer)
- func (s *Logging) Sync() error
- func (s *Logging) Write(b []byte) (int, error)
- func (s *Logging) WriteEntry(e zapcore.Entry, fields []zapcore.Field)
- func (s *Logging) ZapLogger(name string) *zap.Logger
- type Observer
Constants ¶
const ( CONSOLE = iota JSON LOGFMT )
const ( // DisabledLevel represents a disabled log level. Logs at this level should // never be emitted. DisabledLevel = zapcore.Level(math.MinInt8) // PayloadLevel is used to log the extremely detailed message level debug // information. PayloadLevel = zapcore.Level(zapcore.DebugLevel - 1) )
Variables ¶
This section is empty.
Functions ¶
func ActivateSpec ¶
func ActivateSpec(spec string)
ActivateSpec is used to activate a logging specification.
func DefaultLevel ¶
func DefaultLevel() string
DefaultLevel returns the fallback value for loggers to use if parsing fails.
func GetLoggerLevel ¶
GetLoggerLevel gets the current logging level for the logger with the provided name.
func InitBackend ¶
InitBackend sets up the logging backend based on the provided logging formatter and I/O writer.
func InitFromSpec ¶
InitFromSpec initializes the logging based on the supplied spec. It is exposed externally so that consumers of the flogging package may parse their own logging specification. The logging specification has the following form:
[<logger>[,<logger>...]=]<level>[:[<logger>[,<logger>...]=]<logger>...]
func IsValidLevel ¶
func NameToLevel ¶
NameToLevel converts a level name to a zapcore.Level. If the level name is unknown, zapcore.InfoLevel is returned.
func NewGRPCLogger ¶
NewGRPCLogger creates a grpc.Logger that delegates to a zap.Logger.
func NewZapLogger ¶
NewZapLogger creates a zap logger around a new zap.Core. The core will use the provided encoder and sinks and a level enabler that is associated with the provided logger name. The logger that is returned will be named the same as the logger.
Types ¶
type Config ¶
type Config struct { // Format is the log record format specifier for the Logging instance. If the // spec is the string "json", log records will be formatted as JSON. Any // other string will be provided to the FormatEncoder. Please see // fabenc.ParseFormat for details on the supported verbs. // // If Format is not provided, a default format that provides basic information will // be used. Format string // LogSpec determines the log levels that are enabled for the logging system. The // spec must be in a format that can be processed by ActivateSpec. // // If LogSpec is not provided, loggers will be enabled at the INFO level. LogSpec string // Writer is the sink for encoded and formatted log records. // // If a Writer is not provided, os.Stderr will be used as the log sink. Writer io.Writer }
Config is used to provide dependencies to a Logging instance.
type Core ¶
type Core struct { zapcore.LevelEnabler Levels *LoggerLevels Encoders map[Encoding]zapcore.Encoder Selector EncodingSelector Output zapcore.WriteSyncer Observer Observer }
Core is a custom implementation of a zapcore.Core. It's a terrible hack that only exists to work around the intersection of state associated with encoders, implementation hiding in zapcore, and implicit, ad-hoc logger initialization within fabric.
In addition to encoding log entries and fields to a buffer, zap Encoder implementations also need to maintain field state. When zapcore.Core.With is used, the associated encoder is cloned and the fields are added to the encoder. This means that encoder instances cannot be shared across cores.
In terms of implementation hiding, it's difficult for our FormatEncoder to cleanly wrap the JSON and console implementations from zap as all methods from the zapcore.ObjectEncoder would need to be implemented to delegate to the correct backend.
This implementation works by associating multiple encoders with a core. When fields are added to the core, the fields are added to all of the encoder implementations. The core also references the logging configuration to determine the proper encoding to use, the writer to delegate to, and the enabled levels.
func (*Core) Check ¶
func (c *Core) Check(e zapcore.Entry, ce *zapcore.CheckedEntry) *zapcore.CheckedEntry
type EncodingSelector ¶
type EncodingSelector interface {
Encoding() Encoding
}
EncodingSelector is used to determine whether log records are encoded as JSON or in human readable CONSOLE or LOGFMT formats.
type FabricLogger ¶
type FabricLogger struct {
// contains filtered or unexported fields
}
A FabricLogger is an adapter around a zap.SugaredLogger that provides structured logging capabilities while preserving much of the legacy logging behavior.
The most significant difference between the FabricLogger and the zap.SugaredLogger is that methods without a formatting suffix (f or w) build the log entry message with fmt.Sprintln instead of fmt.Sprint. Without this change, arguments are not separated by spaces.
func MustGetLogger ¶
func MustGetLogger(loggerName string) *FabricLogger
MustGetLogger creates a logger with the specified name. If an invalid name is provided, the operation will panic.
func NewFabricLogger ¶
func NewFabricLogger(l *zap.Logger, options ...zap.Option) *FabricLogger
NewFabricLogger creates a logger that delegates to the zap.SugaredLogger.
func (*FabricLogger) Critical ¶
func (f *FabricLogger) Critical(args ...interface{})
for backwards compatibility
func (*FabricLogger) Criticalf ¶
func (f *FabricLogger) Criticalf(template string, args ...interface{})
func (*FabricLogger) DPanic ¶
func (f *FabricLogger) DPanic(args ...interface{})
func (*FabricLogger) DPanicf ¶
func (f *FabricLogger) DPanicf(template string, args ...interface{})
func (*FabricLogger) DPanicw ¶
func (f *FabricLogger) DPanicw(msg string, kvPairs ...interface{})
func (*FabricLogger) Debug ¶
func (f *FabricLogger) Debug(args ...interface{})
func (*FabricLogger) Debugf ¶
func (f *FabricLogger) Debugf(template string, args ...interface{})
func (*FabricLogger) Debugw ¶
func (f *FabricLogger) Debugw(msg string, kvPairs ...interface{})
func (*FabricLogger) Error ¶
func (f *FabricLogger) Error(args ...interface{})
func (*FabricLogger) Errorf ¶
func (f *FabricLogger) Errorf(template string, args ...interface{})
func (*FabricLogger) Errorw ¶
func (f *FabricLogger) Errorw(msg string, kvPairs ...interface{})
func (*FabricLogger) Fatal ¶
func (f *FabricLogger) Fatal(args ...interface{})
func (*FabricLogger) Fatalf ¶
func (f *FabricLogger) Fatalf(template string, args ...interface{})
func (*FabricLogger) Fatalw ¶
func (f *FabricLogger) Fatalw(msg string, kvPairs ...interface{})
func (*FabricLogger) Info ¶
func (f *FabricLogger) Info(args ...interface{})
func (*FabricLogger) Infof ¶
func (f *FabricLogger) Infof(template string, args ...interface{})
func (*FabricLogger) Infow ¶
func (f *FabricLogger) Infow(msg string, kvPairs ...interface{})
func (*FabricLogger) IsEnabledFor ¶
func (f *FabricLogger) IsEnabledFor(level zapcore.Level) bool
func (*FabricLogger) Named ¶
func (f *FabricLogger) Named(name string) *FabricLogger
func (*FabricLogger) Notice ¶
func (f *FabricLogger) Notice(args ...interface{})
func (*FabricLogger) Noticef ¶
func (f *FabricLogger) Noticef(template string, args ...interface{})
func (*FabricLogger) Panic ¶
func (f *FabricLogger) Panic(args ...interface{})
func (*FabricLogger) Panicf ¶
func (f *FabricLogger) Panicf(template string, args ...interface{})
func (*FabricLogger) Panicw ¶
func (f *FabricLogger) Panicw(msg string, kvPairs ...interface{})
func (*FabricLogger) Sync ¶
func (f *FabricLogger) Sync() error
func (*FabricLogger) Warn ¶
func (f *FabricLogger) Warn(args ...interface{})
func (*FabricLogger) Warnf ¶
func (f *FabricLogger) Warnf(template string, args ...interface{})
func (*FabricLogger) Warning ¶
func (f *FabricLogger) Warning(args ...interface{})
func (*FabricLogger) Warningf ¶
func (f *FabricLogger) Warningf(template string, args ...interface{})
func (*FabricLogger) Warnw ¶
func (f *FabricLogger) Warnw(msg string, kvPairs ...interface{})
func (*FabricLogger) With ¶
func (f *FabricLogger) With(args ...interface{}) *FabricLogger
func (*FabricLogger) WithOptions ¶
func (f *FabricLogger) WithOptions(opts ...zap.Option) *FabricLogger
func (*FabricLogger) Zap ¶
func (f *FabricLogger) Zap() *zap.Logger
type LoggerLevels ¶
type LoggerLevels struct {
// contains filtered or unexported fields
}
LoggerLevels tracks the logging level of named loggers.
func (*LoggerLevels) ActivateSpec ¶
func (l *LoggerLevels) ActivateSpec(spec string) error
ActivateSpec is used to modify logging levels.
The logging specification has the following form:
[<logger>[,<logger>...]=]<level>[:[<logger>[,<logger>...]=]<level>...]
func (*LoggerLevels) DefaultLevel ¶
func (l *LoggerLevels) DefaultLevel() zapcore.Level
DefaultLevel returns the default logging level for loggers that do not have an explicit level set.
func (*LoggerLevels) Level ¶
func (l *LoggerLevels) Level(loggerName string) zapcore.Level
Level returns the effective logging level for a logger. If a level has not been explicitly set for the logger, the default logging level will be returned.
func (*LoggerLevels) Spec ¶
func (l *LoggerLevels) Spec() string
Spec returns a normalized version of the active logging spec.
type Logging ¶
type Logging struct { *LoggerLevels // contains filtered or unexported fields }
Logging maintains the state associated with the fabric logging system. It is intended to bridge between the legacy logging infrastructure built around go-logging and the structured, level logging provided by zap.
var Global *Logging
func (*Logging) Encoding ¶
Encoding satisfies the Encoding interface. It determines whether the JSON or CONSOLE encoder should be used by the Core when log records are written.
func (*Logging) Logger ¶
func (s *Logging) Logger(name string) *FabricLogger
Logger instantiates a new FabricLogger with the specified name. The name is used to determine which log levels are enabled.
func (*Logging) SetFormat ¶
SetFormat updates how log records are formatted and encoded. Log entries created after this method has completed will use the new format.
An error is returned if the log format specification cannot be parsed.
func (*Logging) SetObserver ¶
SetObserver is used to provide a log observer that will be called as log levels are checked or written.. Only a single observer is supported.
func (*Logging) SetWriter ¶
SetWriter controls which writer formatted log records are written to. Writers, with the exception of an *os.File, need to be safe for concurrent use by multiple go routines.
func (*Logging) Sync ¶
Sync satisfies the zapcore.WriteSyncer interface. It is used by the Core to flush log records before terminating the process.