Documentation
¶
Overview ¶
Package logger implements a logging system with a module tag. The module tag represents a scope where the log event is emitted.
Index ¶
- Constants
- Variables
- func AttachNativeSink(s NativeSink) (detach func())
- func Debugf(f string, v ...interface{})
- func Errorf(f string, v ...interface{})
- func Infof(f string, v ...interface{})
- func Init(cfg Logging) (err error)
- func Panicf(f string, v ...interface{})
- func Proto(message proto.Message) []byte
- func RegisterFlags(fs *pflag.FlagSet, logging *Logging)
- func RegisterNativeFlags(fs *pflag.FlagSet, cfg *NativeLogging)
- func RegisterNativeReceiverFlag(fs *pflag.FlagSet, cfg *NativeLogging)
- func Warningf(f string, v ...interface{})
- func WithNativeWrite(ctx context.Context) context.Context
- type Loggable
- type Logger
- type Logging
- type MarshalError
- type NativeLogging
- type NativeSink
Constants ¶
const NativeLogGroup = "_monitoring_log"
NativeLogGroup is the group native log events are stored in.
const NativeWriteModule = "native-log"
NativeWriteModule names the logger of the native log service, and every logger taken from a context marked by WithNativeWrite.
Variables ¶
var ContextKey = contextKey{}
ContextKey is the key to store Logger in the context.
Functions ¶
func AttachNativeSink ¶ added in v0.12.0
func AttachNativeSink(s NativeSink) (detach func())
AttachNativeSink installs s as the destination of native logging and returns the function that detaches it. Admission stops the instant detach returns, which is what lets a shutdown drain publish exactly the set admitted before it. Detach leaves alone a sink attached after s.
func Debugf ¶ added in v0.6.0
func Debugf(f string, v ...interface{})
Debugf logs a message at the debug level. It uses sprintf-style formatting for its message.
func Errorf ¶ added in v0.6.0
func Errorf(f string, v ...interface{})
Errorf logs a message at the error level. It uses sprintf-style formatting for its message.
func Infof ¶ added in v0.6.0
func Infof(f string, v ...interface{})
Infof logs a message at the info level. It uses sprintf-style formatting for its message.
func Init ¶
Init initializes a rs/zerolog logger from user config. The native configuration is resolved first: if it is unusable the root logger is left untouched, so a bad native flag cannot cost the process its logging.
func Panicf ¶ added in v0.6.0
func Panicf(f string, v ...interface{})
Panicf logs a message at the panic level. It panics after logging the message. It uses sprintf-style formatting for its message.
func RegisterFlags ¶ added in v0.12.0
RegisterFlags registers the logging flags shared by every BanyanDB binary.
func RegisterNativeFlags ¶ added in v0.12.0
func RegisterNativeFlags(fs *pflag.FlagSet, cfg *NativeLogging)
RegisterNativeFlags registers the native logging flags. Only the binaries that can reach a storage engine call it: restore and migration run when the data tier is unavailable, so they never offer the flags at all.
func RegisterNativeReceiverFlag ¶ added in v0.12.0
func RegisterNativeReceiverFlag(fs *pflag.FlagSet, cfg *NativeLogging)
RegisterNativeReceiverFlag registers the flag that makes a server the destination of other processes' native logs. Only the server offers it: a producer such as backup or an FODC agent writes to a server, never the other way round.
func Warningf ¶ added in v0.6.0
func Warningf(f string, v ...interface{})
Warningf logs a message at the warning level. It uses sprintf-style formatting for its message.
func WithNativeWrite ¶ added in v0.12.0
WithNativeWrite marks ctx as carrying a native log write. Work done under it that takes its logger from the context with Fetch or FetchOrDefault logs as a child of NATIVE-LOG: the line reaches the console, and never native storage. Other writes in the process, and the lines they log, are not affected.
Types ¶
type Loggable ¶
type Loggable interface {
SetLogger(*Logger)
}
Loggable indicates the implement supports logging.
type Logger ¶
Logger is wrapper for rs/zerolog logger with module, it is singleton.
func FetchOrDefault ¶ added in v0.3.0
FetchOrDefault gets a Logger in a context, then creates a new Logger based on it If the context doesn't include a Logger. The default Logger will be picked.
func ForGroup ¶ added in v0.12.0
ForGroup returns the logger for what a write path logs about an event of group. An event of the native log group is a native log write wherever it came from, so its lines log under NATIVE-LOG, as name, and never reach native storage: a failed write would otherwise log a line that is written, and fails, again. A node that receives the event over the network has no mark from the sender's context, so its write path asks by group. Any other group logs to l.
func (*Logger) DefaultLevel ¶ added in v0.7.0
DefaultLevel sets the default level for the logger. It is the console threshold it sets; the native threshold of the module is left as configured.
func (*Logger) ToZapConfig ¶ added in v0.3.0
ToZapConfig outputs the zap config is derived from l.
The console threshold is what it follows, as before native storage existed: the logger's own level is the admission floor, which native may lower.
type Logging ¶
type Logging struct {
Env string
Level string
Modules []string
Levels []string
// Native configures the native destination, which stores this process's
// own logs in BanyanDB. It is off unless Native.Enabled is set.
Native NativeLogging
}
Logging is the config info.
type MarshalError ¶ added in v0.3.0
type MarshalError struct {
Msg string `json:"msg"`
}
MarshalError is the error raised by marshaling a JSON object.
type NativeLogging ¶ added in v0.12.0
type NativeLogging struct {
Level string
ExcludeModules []string
// Modules and Levels override the native level per module, pairwise, the
// way --logging-modules and --logging-levels do for the console.
Modules []string
Levels []string
TTLDays uint32
Enabled bool
// ReceiverEnabled makes a server own the schema for the other processes
// that write their logs to it, whether or not it collects its own.
ReceiverEnabled bool
}
NativeLogging is the configuration of the native sink. It lives in the --logging-native-* namespace, which inherits nothing from --logging-*. Buffering, batching, write handling and memory bounds are not configured: the native log service keeps them internal.
type NativeSink ¶ added in v0.12.0
NativeSink receives the events admitted for native self-storage. It is implemented outside this package, by the service that owns the buffer and the write path, and attached with AttachNativeSink.
Admit is called on the goroutine that emitted the log line. It must never block, never panic and never report an error the caller has to handle: the logging path cannot be allowed to fail a caller that only wanted to log.