Documentation ¶
Index ¶
- Constants
- Variables
- func AllowLevel(level Level, name ...string) bool
- func CallAndLogError(f func() error, task string, log Logger)
- func CallAndLogWarning(f func() error, task string, log Logger)
- func Configure(verbosity int, path *string)
- func GetKeyValue(key any, keysAndValues ...any) (any, bool)
- func GetWriter() io.Writer
- func Initialize(verbosity int, path string)
- func MergeKeysAndValues(toKeysAndValues []any, fromKeysAndValues []any) ([]any, bool)
- func PathToName(path string) []string
- func SetBackend(backend_ Backend)
- func SetKeyValue(key any, value any, keysAndValues ...any) ([]any, bool)
- func SetMaxLevel(level Level, name ...string)
- func SetMessageKeysAndValues(message Message, keysAndValues ...any)
- type Backend
- type BackendLogger
- func (self BackendLogger) AllowLevel(level Level) bool
- func (self BackendLogger) Critical(message string, keysAndValues ...any)
- func (self BackendLogger) Criticalf(format string, args ...any)
- func (self BackendLogger) Debug(message string, keysAndValues ...any)
- func (self BackendLogger) Debugf(format string, args ...any)
- func (self BackendLogger) Error(message string, keysAndValues ...any)
- func (self BackendLogger) Errorf(format string, args ...any)
- func (self BackendLogger) GetMaxLevel() Level
- func (self BackendLogger) Info(message string, keysAndValues ...any)
- func (self BackendLogger) Infof(format string, args ...any)
- func (self BackendLogger) Log(level Level, depth int, message string, keysAndValues ...any)
- func (self BackendLogger) Logf(level Level, depth int, format string, args ...any)
- func (self BackendLogger) NewMessage(level Level, depth int, keysAndValues ...any) Message
- func (self BackendLogger) Notice(message string, keysAndValues ...any)
- func (self BackendLogger) Noticef(format string, args ...any)
- func (self BackendLogger) SetMaxLevel(level Level)
- func (self BackendLogger) Warning(message string, keysAndValues ...any)
- func (self BackendLogger) Warningf(format string, args ...any)
- type KeyValueLogger
- func (self KeyValueLogger) AllowLevel(level Level) bool
- func (self KeyValueLogger) Critical(message string, keysAndValues ...any)
- func (self KeyValueLogger) Criticalf(format string, args ...any)
- func (self KeyValueLogger) Debug(message string, keysAndValues ...any)
- func (self KeyValueLogger) Debugf(format string, args ...any)
- func (self KeyValueLogger) Error(message string, keysAndValues ...any)
- func (self KeyValueLogger) Errorf(format string, args ...any)
- func (self KeyValueLogger) GetMaxLevel() Level
- func (self KeyValueLogger) Info(message string, keysAndValues ...any)
- func (self KeyValueLogger) Infof(format string, args ...any)
- func (self KeyValueLogger) Log(level Level, depth int, message string, keysAndValues ...any)
- func (self KeyValueLogger) Logf(level Level, depth int, format string, args ...any)
- func (self KeyValueLogger) NewMessage(level Level, depth int, keysAndValues ...any) Message
- func (self KeyValueLogger) Notice(message string, keysAndValues ...any)
- func (self KeyValueLogger) Noticef(format string, args ...any)
- func (self KeyValueLogger) SetMaxLevel(level Level)
- func (self KeyValueLogger) Warning(message string, keysAndValues ...any)
- func (self KeyValueLogger) Warningf(format string, args ...any)
- type Level
- type LinearMessage
- func (self *LinearMessage) LocationString() string
- func (self *LinearMessage) Prefix(name ...string) string
- func (self *LinearMessage) Send()
- func (self *LinearMessage) Set(key string, value any) Message
- func (self *LinearMessage) String() string
- func (self *LinearMessage) StringWithPrefix(name ...string) string
- func (self *LinearMessage) ValuesString(withLocation bool) string
- type LinearMessageValue
- type Logger
- type LoggerFIFO
- type LoggerServer
- type Message
- func NewCriticalMessage(depth int, name ...string) Message
- func NewDebugMessage(depth int, name ...string) Message
- func NewErrorMessage(depth int, name ...string) Message
- func NewInfoMessage(depth int, name ...string) Message
- func NewMessage(level Level, depth int, name ...string) Message
- func NewNoticeMessage(depth int, name ...string) Message
- func NewWarningMessage(depth int, name ...string) Message
- func TraceMessage(message Message, depth int) Message
- type MockLogger
- func (self MockLogger) AllowLevel(level Level) bool
- func (self MockLogger) Critical(message string, keysAndValues ...any)
- func (self MockLogger) Criticalf(format string, args ...any)
- func (self MockLogger) Debug(message string, keysAndValues ...any)
- func (self MockLogger) Debugf(format string, args ...any)
- func (self MockLogger) Error(message string, keysAndValues ...any)
- func (self MockLogger) Errorf(format string, args ...any)
- func (self MockLogger) GetMaxLevel() Level
- func (self MockLogger) Info(message string, keysAndValues ...any)
- func (self MockLogger) Infof(format string, args ...any)
- func (self MockLogger) Log(level Level, depth int, message string, keysAndValues ...any)
- func (self MockLogger) Logf(level Level, depth int, format string, args ...any)
- func (self MockLogger) NewMessage(level Level, depth int, keysAndValues ...any) Message
- func (self MockLogger) Notice(message string, keysAndValues ...any)
- func (self MockLogger) Noticef(format string, args ...any)
- func (self MockLogger) SetMaxLevel(level Level)
- func (self MockLogger) Warning(message string, keysAndValues ...any)
- func (self MockLogger) Warningf(format string, args ...any)
- type NameHierarchy
- type SendLinearMessageFunc
Constants ¶
const ( MESSAGE = "_message" SCOPE = "_scope" FILE = "_file" LINE = "_line" )
Variables ¶
var Trace bool
Functions ¶
func AllowLevel ¶
Returns true if a level is loggable for the given name on the current backend.
Returns false if no backend was set.
func CallAndLogError ¶
Convenience method to call a function and log the error, if returned, using [Logger.Error]. If task is not empty it will be prefixed to the error message.
func CallAndLogWarning ¶ added in v0.2.7
Convenience method to call a function and log the error, if returned, using [Logger.Warning]. If task is not empty it will be prefixed to the error message.
func Configure ¶
Configures the current backend. Verbosity is mapped to maximum loggable level as follows:
Note that -4 (None) is a special case that is often optimized to turn off as much processing as possible.
No-op if no backend was set.
func GetWriter ¶
Gets the current backend's io.Writer. Guaranteed to always return a valid non-nil value.
Will be io.Discard if writing is unsupported by the backend or if no backend was set.
func Initialize ¶ added in v0.1.1
Convenience method to call Configure while automatically overriding the verbosity with -4 (None) if terminal.Quiet is set to false and the path is empty (meaning we want to log to stdout).
func MergeKeysAndValues ¶ added in v0.2.6
func PathToName ¶ added in v0.2.5
func SetBackend ¶
func SetBackend(backend_ Backend)
Sets the current backend.
A nil backend will disable all logging (but the APIs would still not fail).
func SetKeyValue ¶ added in v0.2.9
func SetMaxLevel ¶
Sets the maximum loggable level for the given name on the current backend. Will become the default maximum level for names deeper in the hierarchy unless explicitly set for them.
No-op if no backend was set.
func SetMessageKeysAndValues ¶ added in v0.2.6
Calls [Message.Set] on a provided sequence of key-value pairs. Thus keysAndValues must have an even length.
Non-string keys are converted to strings using util.ToString.
Types ¶
type Backend ¶
type Backend interface { // Configures the backend. Verbosity is mapped to maximum // loggable level as follows: // // - -4 and below: [None] // - -3: [Critical] // - -2: [Error] // - -1: [Warning] // - 0: [Notice] // - 1: [Info] // - 2 and above: [Debug] // // Note that -4 ([None]) is a special case that is often optimized to turn // off as much processing as possible. Configure(verbosity int, path *string) // Gets the backend's [io.Writer]. Can be nil if unsupported. GetWriter() io.Writer NewMessage(level Level, depth int, name ...string) Message // Returns true if a level is loggable for the given name. AllowLevel(level Level, name ...string) bool // Sets the maximum loggable level for the given name. Will become the // default maximum level for names deeper in the hierarchy unless // explicitly set for them. SetMaxLevel(level Level, name ...string) // Gets the maximum loggable level for the given name. GetMaxLevel(name ...string) Level }
type BackendLogger ¶
type BackendLogger struct {
// contains filtered or unexported fields
}
Default Logger implementation that logs to the current backend set with SetBackend.
func NewBackendLogger ¶
func NewBackendLogger(name ...string) BackendLogger
func (BackendLogger) AllowLevel ¶
func (self BackendLogger) AllowLevel(level Level) bool
(Logger interface)
func (BackendLogger) Critical ¶
func (self BackendLogger) Critical(message string, keysAndValues ...any)
(Logger interface)
func (BackendLogger) Criticalf ¶
func (self BackendLogger) Criticalf(format string, args ...any)
(Logger interface)
func (BackendLogger) Debug ¶
func (self BackendLogger) Debug(message string, keysAndValues ...any)
(Logger interface)
func (BackendLogger) Debugf ¶
func (self BackendLogger) Debugf(format string, args ...any)
(Logger interface)
func (BackendLogger) Error ¶
func (self BackendLogger) Error(message string, keysAndValues ...any)
(Logger interface)
func (BackendLogger) Errorf ¶
func (self BackendLogger) Errorf(format string, args ...any)
(Logger interface)
func (BackendLogger) Info ¶
func (self BackendLogger) Info(message string, keysAndValues ...any)
(Logger interface)
func (BackendLogger) Infof ¶
func (self BackendLogger) Infof(format string, args ...any)
(Logger interface)
func (BackendLogger) Log ¶
func (self BackendLogger) Log(level Level, depth int, message string, keysAndValues ...any)
(Logger interface)
func (BackendLogger) Logf ¶
func (self BackendLogger) Logf(level Level, depth int, format string, args ...any)
(Logger interface)
func (BackendLogger) NewMessage ¶
func (self BackendLogger) NewMessage(level Level, depth int, keysAndValues ...any) Message
(Logger interface)
func (BackendLogger) Notice ¶
func (self BackendLogger) Notice(message string, keysAndValues ...any)
(Logger interface)
func (BackendLogger) Noticef ¶
func (self BackendLogger) Noticef(format string, args ...any)
(Logger interface)
func (BackendLogger) SetMaxLevel ¶
func (self BackendLogger) SetMaxLevel(level Level)
(Logger interface)
type KeyValueLogger ¶ added in v0.2.6
type KeyValueLogger struct {
// contains filtered or unexported fields
}
Wrapping Logger that calls [Message.Set] with keys and values on all messages.
If we're wrapping another KeyValueLogger then our keys and values will be merged into the wrapped keys and values.
func NewKeyValueLogger ¶ added in v0.2.6
func NewKeyValueLogger(logger Logger, keysAndValues ...any) KeyValueLogger
func NewScopeLogger ¶
func NewScopeLogger(logger Logger, scope string) KeyValueLogger
Wrapping Logger that calls [Message.Set] with a "_scope" key on all messages.
If we're wrapping another KeyValueLogger then our "_scope" key will be appended to the wrapped "_scope" key with a "." notation.
func (KeyValueLogger) AllowLevel ¶ added in v0.2.6
func (self KeyValueLogger) AllowLevel(level Level) bool
(Logger interface)
func (KeyValueLogger) Critical ¶ added in v0.2.6
func (self KeyValueLogger) Critical(message string, keysAndValues ...any)
(Logger interface)
func (KeyValueLogger) Criticalf ¶ added in v0.2.6
func (self KeyValueLogger) Criticalf(format string, args ...any)
(Logger interface)
func (KeyValueLogger) Debug ¶ added in v0.2.6
func (self KeyValueLogger) Debug(message string, keysAndValues ...any)
(Logger interface)
func (KeyValueLogger) Debugf ¶ added in v0.2.6
func (self KeyValueLogger) Debugf(format string, args ...any)
(Logger interface)
func (KeyValueLogger) Error ¶ added in v0.2.6
func (self KeyValueLogger) Error(message string, keysAndValues ...any)
(Logger interface)
func (KeyValueLogger) Errorf ¶ added in v0.2.6
func (self KeyValueLogger) Errorf(format string, args ...any)
(Logger interface)
func (KeyValueLogger) GetMaxLevel ¶ added in v0.2.6
func (self KeyValueLogger) GetMaxLevel() Level
(Logger interface)
func (KeyValueLogger) Info ¶ added in v0.2.6
func (self KeyValueLogger) Info(message string, keysAndValues ...any)
(Logger interface)
func (KeyValueLogger) Infof ¶ added in v0.2.6
func (self KeyValueLogger) Infof(format string, args ...any)
(Logger interface)
func (KeyValueLogger) Log ¶ added in v0.2.6
func (self KeyValueLogger) Log(level Level, depth int, message string, keysAndValues ...any)
(Logger interface)
func (KeyValueLogger) Logf ¶ added in v0.2.6
func (self KeyValueLogger) Logf(level Level, depth int, format string, args ...any)
(Logger interface)
func (KeyValueLogger) NewMessage ¶ added in v0.2.6
func (self KeyValueLogger) NewMessage(level Level, depth int, keysAndValues ...any) Message
(Logger interface)
func (KeyValueLogger) Notice ¶ added in v0.2.6
func (self KeyValueLogger) Notice(message string, keysAndValues ...any)
(Logger interface)
func (KeyValueLogger) Noticef ¶ added in v0.2.6
func (self KeyValueLogger) Noticef(format string, args ...any)
(Logger interface)
func (KeyValueLogger) SetMaxLevel ¶ added in v0.2.6
func (self KeyValueLogger) SetMaxLevel(level Level)
(Logger interface)
type Level ¶
type Level int
func GetMaxLevel ¶
Gets the maximum loggable level for the given name on the current backend.
Returns None if no backend was set.
func VerbosityToMaxLevel ¶
Translates a verbosity number to a maximum loggable level as follows:
type LinearMessage ¶ added in v0.2.17
type LinearMessage struct { Scope string Message string Values []LinearMessageValue File string Line int64 // contains filtered or unexported fields }
An implementation of Message optimized for representation as a single line of text.
func NewLinearMessage ¶ added in v0.2.17
func NewLinearMessage(send SendLinearMessageFunc) *LinearMessage
func (*LinearMessage) LocationString ¶ added in v0.2.17
func (self *LinearMessage) LocationString() string
func (*LinearMessage) Prefix ¶ added in v0.2.17
func (self *LinearMessage) Prefix(name ...string) string
func (*LinearMessage) Set ¶ added in v0.2.17
func (self *LinearMessage) Set(key string, value any) Message
(Message interface)
func (*LinearMessage) String ¶ added in v0.2.17
func (self *LinearMessage) String() string
(fmt.Stringify interface)
func (*LinearMessage) StringWithPrefix ¶ added in v0.2.17
func (self *LinearMessage) StringWithPrefix(name ...string) string
func (*LinearMessage) ValuesString ¶ added in v0.2.17
func (self *LinearMessage) ValuesString(withLocation bool) string
type LinearMessageValue ¶ added in v0.2.17
type Logger ¶
type Logger interface { // Returns true if a level is loggable for this logger. AllowLevel(level Level) bool // Sets the maximum loggable level for this logger. SetMaxLevel(level Level) // Gets the maximum loggable level for this logger. GetMaxLevel() Level // Creates a new message for this logger. Will return nil if // the level is not loggable. // // The depth argument is used for skipping frames in callstack // logging, if supported. NewMessage(level Level, depth int, keysAndValues ...any) Message // Convenience method to create and send a message with at least // the "_message" key. Additional keys can be set by providing // a sequence of key-value pairs. Log(level Level, depth int, message string, keysAndValues ...any) // Convenience method to create and send a message with just // the "_message" key, where the message is created via the format // and args similarly to fmt.Printf. Logf(level Level, depth int, format string, args ...any) Critical(message string, keysAndValues ...any) Criticalf(format string, args ...any) Error(message string, keysAndValues ...any) Errorf(format string, args ...any) Warning(message string, keysAndValues ...any) Warningf(format string, args ...any) Notice(message string, keysAndValues ...any) Noticef(format string, args ...any) Info(message string, keysAndValues ...any) Infof(format string, args ...any) Debug(message string, keysAndValues ...any) Debugf(format string, args ...any) }
While NewMessage is the "true" API entry point, this interface enables a familiar logger API. Because it's an interface, references can easily replace the implementation, for example setting a reference to MOCK_LOGGER will disable the logger.
See GetLogger.
func GetLogger ¶
Provides a BackendLogger instance for the given path. The path is converted to a name using PathToName.
Note that this function will always return a new instance and that instances for the same path are functionally equivalent.
func GetLoggerf ¶
Calls GetLogger with fmt.Sprintf for the path.
type LoggerFIFO ¶ added in v0.2.14
A Linux FIFO file that forwards all lines written to it to a Logger.
func NewLoggerFIFO ¶ added in v0.2.14
func NewLoggerFIFO(prefix string, log Logger, level Level) *LoggerFIFO
func (*LoggerFIFO) Start ¶ added in v0.2.14
func (self *LoggerFIFO) Start() error
type LoggerServer ¶ added in v0.2.14
type LoggerServer struct { IPStack util.IPStack Address string Port int Log Logger Level Level ClientAddressPorts []string // contains filtered or unexported fields }
A TCP server file that forwards all lines written to it to a Logger.
func NewLoggerServer ¶ added in v0.2.14
func (*LoggerServer) Start ¶ added in v0.2.14
func (self *LoggerServer) Start() error
func (*LoggerServer) Stop ¶ added in v0.2.14
func (self *LoggerServer) Stop()
type Message ¶
type Message interface { // Sets a value on the message and returns the same message // object. // // These keys are often specially supported: // // "_message": the base text of the message // "_scope": the scope of the message // "_file": filename in which the message was created // "_line": line number in the "_file" Set(key string, value any) Message // Sends the message to the backend. Send() }
The entry point into the CommonLog API.
Also see Logger as a more familiar, alternative API.
func NewCriticalMessage ¶ added in v0.2.0
Calls NewMessage with Critical level.
func NewDebugMessage ¶ added in v0.2.0
Calls NewMessage with Debug level.
func NewErrorMessage ¶ added in v0.2.0
Calls NewMessage with Error level.
func NewInfoMessage ¶ added in v0.2.0
Calls NewMessage with Info level.
func NewMessage ¶
Creates a new message for the given name on the current backend. Will return nil if the level is not loggable for the name, is None, or if no backend was set.
The depth argument is used for skipping frames in callstack logging, if supported.
func NewNoticeMessage ¶ added in v0.2.0
Calls NewMessage with Notice level.
func NewWarningMessage ¶ added in v0.2.0
Calls NewMessage with Warning level.
type MockLogger ¶
type MockLogger struct{}
Logger that does nothing.
var MOCK_LOGGER MockLogger
func (MockLogger) AllowLevel ¶
func (self MockLogger) AllowLevel(level Level) bool
(Logger interface)
func (MockLogger) Critical ¶
func (self MockLogger) Critical(message string, keysAndValues ...any)
(Logger interface)
func (MockLogger) Criticalf ¶
func (self MockLogger) Criticalf(format string, args ...any)
(Logger interface)
func (MockLogger) Debug ¶
func (self MockLogger) Debug(message string, keysAndValues ...any)
(Logger interface)
func (MockLogger) Debugf ¶
func (self MockLogger) Debugf(format string, args ...any)
(Logger interface)
func (MockLogger) Error ¶
func (self MockLogger) Error(message string, keysAndValues ...any)
(Logger interface)
func (MockLogger) Errorf ¶
func (self MockLogger) Errorf(format string, args ...any)
(Logger interface)
func (MockLogger) Info ¶
func (self MockLogger) Info(message string, keysAndValues ...any)
(Logger interface)
func (MockLogger) Infof ¶
func (self MockLogger) Infof(format string, args ...any)
(Logger interface)
func (MockLogger) Log ¶
func (self MockLogger) Log(level Level, depth int, message string, keysAndValues ...any)
(Logger interface)
func (MockLogger) Logf ¶
func (self MockLogger) Logf(level Level, depth int, format string, args ...any)
(Logger interface)
func (MockLogger) NewMessage ¶
func (self MockLogger) NewMessage(level Level, depth int, keysAndValues ...any) Message
(Logger interface)
func (MockLogger) Notice ¶
func (self MockLogger) Notice(message string, keysAndValues ...any)
(Logger interface)
func (MockLogger) Noticef ¶
func (self MockLogger) Noticef(format string, args ...any)
(Logger interface)
type NameHierarchy ¶ added in v0.2.0
type NameHierarchy struct {
// contains filtered or unexported fields
}
Convenience type for implementing maximum level per name in backends. Supports level inheritance.
func NewNameHierarchy ¶ added in v0.2.0
func NewNameHierarchy() *NameHierarchy
func (*NameHierarchy) AllowLevel ¶ added in v0.2.0
func (self *NameHierarchy) AllowLevel(level Level, name ...string) bool
func (*NameHierarchy) GetMaxLevel ¶ added in v0.2.0
func (self *NameHierarchy) GetMaxLevel(name ...string) Level
func (*NameHierarchy) SetMaxLevel ¶ added in v0.2.0
func (self *NameHierarchy) SetMaxLevel(level Level, name ...string)
type SendLinearMessageFunc ¶ added in v0.2.17
type SendLinearMessageFunc func(message *LinearMessage)