Documentation
¶
Index ¶
- func AllowLevel(level Level, name ...string) bool
- func CallAndLogError(f func() error, task string, log Logger)
- func Configure(verbosity int, path *string)
- func GetWriter() io.Writer
- func Initialize(verbosity int, path string)
- func PathToName(path string) []string
- func SetBackend(backend_ Backend)
- func SetMaxLevel(level Level, name ...string)
- func SetMessageKeysAndValue(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 Level
- type Logger
- 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
- 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 ScopeLogger
- func (self ScopeLogger) AllowLevel(level Level) bool
- func (self ScopeLogger) Critical(message string, keysAndValues ...any)
- func (self ScopeLogger) Criticalf(format string, args ...any)
- func (self ScopeLogger) Debug(message string, keysAndValues ...any)
- func (self ScopeLogger) Debugf(format string, args ...any)
- func (self ScopeLogger) Error(message string, keysAndValues ...any)
- func (self ScopeLogger) Errorf(format string, args ...any)
- func (self ScopeLogger) GetMaxLevel() Level
- func (self ScopeLogger) Info(message string, keysAndValues ...any)
- func (self ScopeLogger) Infof(format string, args ...any)
- func (self ScopeLogger) Log(level Level, depth int, message string, keysAndValues ...any)
- func (self ScopeLogger) Logf(level Level, depth int, format string, args ...any)
- func (self ScopeLogger) NewMessage(level Level, depth int, keysAndValues ...any) Message
- func (self ScopeLogger) Notice(message string, keysAndValues ...any)
- func (self ScopeLogger) Noticef(format string, args ...any)
- func (self ScopeLogger) SetMaxLevel(level Level)
- func (self ScopeLogger) Warning(message string, keysAndValues ...any)
- func (self ScopeLogger) Warningf(format string, args ...any)
- type SendUnstructuredMessageFunc
- type UnstructuredMessage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
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.Errorf].
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.
Can be io.Discard if unsupported by the backend or if no backend was set.
func Initialize ¶ added in v0.1.1
Convenience method to call Configure but automatically override the verbosity with -4 (None) if logging to stdout and terminal.Quiet is set to false.
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 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 SetMessageKeysAndValue ¶ added in v0.2.3
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 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 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 ¶
Creates a BackendLogger for the given path. The path is converted to a name using [string.Split] on ".".
func GetLoggerf ¶
Calls GetLogger with fmt.Sprintf for the path.
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 Set(key string, value any) Message // Sends the message to the backend Send() }
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 with support for 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 ScopeLogger ¶
type ScopeLogger struct {
// contains filtered or unexported fields
}
Wrapping Logger that calls [Message.Set] with a "scope" key on all messages. There is special support for nesting scope loggers such that a nested scope string is appended to the wrapped scope with a "." notation.
func NewScopeLogger ¶
func NewScopeLogger(logger Logger, scope string) ScopeLogger
func (ScopeLogger) AllowLevel ¶
func (self ScopeLogger) AllowLevel(level Level) bool
(Logger interface)
func (ScopeLogger) Critical ¶
func (self ScopeLogger) Critical(message string, keysAndValues ...any)
(Logger interface)
func (ScopeLogger) Criticalf ¶
func (self ScopeLogger) Criticalf(format string, args ...any)
(Logger interface)
func (ScopeLogger) Debug ¶
func (self ScopeLogger) Debug(message string, keysAndValues ...any)
(Logger interface)
func (ScopeLogger) Debugf ¶
func (self ScopeLogger) Debugf(format string, args ...any)
(Logger interface)
func (ScopeLogger) Error ¶
func (self ScopeLogger) Error(message string, keysAndValues ...any)
(Logger interface)
func (ScopeLogger) Errorf ¶
func (self ScopeLogger) Errorf(format string, args ...any)
(Logger interface)
func (ScopeLogger) Info ¶
func (self ScopeLogger) Info(message string, keysAndValues ...any)
(Logger interface)
func (ScopeLogger) Infof ¶
func (self ScopeLogger) Infof(format string, args ...any)
(Logger interface)
func (ScopeLogger) Log ¶
func (self ScopeLogger) Log(level Level, depth int, message string, keysAndValues ...any)
(Logger interface)
func (ScopeLogger) Logf ¶
func (self ScopeLogger) Logf(level Level, depth int, format string, args ...any)
(Logger interface)
func (ScopeLogger) NewMessage ¶
func (self ScopeLogger) NewMessage(level Level, depth int, keysAndValues ...any) Message
(Logger interface)
func (ScopeLogger) Notice ¶
func (self ScopeLogger) Notice(message string, keysAndValues ...any)
(Logger interface)
func (ScopeLogger) Noticef ¶
func (self ScopeLogger) Noticef(format string, args ...any)
(Logger interface)
func (ScopeLogger) SetMaxLevel ¶
func (self ScopeLogger) SetMaxLevel(level Level)
(Logger interface)
type SendUnstructuredMessageFunc ¶
type SendUnstructuredMessageFunc func(message string)
type UnstructuredMessage ¶
type UnstructuredMessage struct {
// contains filtered or unexported fields
}
Convenience type for implementing unstructured backends. Converts a structured message to an unstructured string.
func NewUnstructuredMessage ¶
func NewUnstructuredMessage(send SendUnstructuredMessageFunc) *UnstructuredMessage