Documentation ¶
Overview ¶
Use conditional logging methods to potentially suppress log messages based on situations orthogonal to log level, with "log sometimes" or "log rarely" semantics. Combine with Composers to avoid expensive message building operations.
Global Logging Infrastructure ¶
By default (following from the standard library logger and other popular logging pacakges,) grip provides a "default" package level logging instance. This logging instance is accessible via a number of package functions which mirror the interface of the Logger type itself.
During init() this logging instance wraps and uses the underlying writer of the standard library's logger. You can use SetGlobalLogger to configure your own logging (and sender!) infrastructure for default operations, though this function is not thread safe.
In many cases, it might make sense to attach a Logger instance to a context, as Logging is a global concern and your application is likely already using contexts. The WithLogger and Context method make it possible to attach and access your logger. The Context method will *always* return a Logging instance, either the instance attached to a context or the global instance if one is not configured.
Basic Logger ¶
The Logger type provides helpers for sending messages at the following levels:
Emergency + (fatal/panic) Alert Critical Error Warning Notice Info Debug Trace
These helpers also include Log* helpers to parameterize the level, as well as the Send method for default logging (or when the level is on the massage itself.)
Index ¶
- func Alert(msg any)
- func AlertWhen(conditional bool, m any)
- func Alertf(msg string, a ...any)
- func Alertln(a ...any)
- func Build() *message.Builder
- func Convert(m any) message.Composer
- func Critical(msg any)
- func CriticalWhen(conditional bool, m any)
- func Criticalf(msg string, a ...any)
- func Criticalln(a ...any)
- func Debug(msg any)
- func DebugWhen(conditional bool, m any)
- func Debugf(msg string, a ...any)
- func Debugln(a ...any)
- func Emergency(msg any)
- func EmergencyFatal(msg any)
- func EmergencyPanic(msg any)
- func EmergencyWhen(conditional bool, m any)
- func Emergencyf(msg string, a ...any)
- func Emergencyln(a ...any)
- func Error(msg any)
- func ErrorWhen(conditional bool, m any)
- func Errorf(msg string, a ...any)
- func Errorln(a ...any)
- func HasContextLogger(ctx context.Context, name string) bool
- func HasLogger(ctx context.Context) bool
- func Info(msg any)
- func InfoWhen(conditional bool, message any)
- func Infof(msg string, a ...any)
- func Infoln(a ...any)
- func Log(l level.Priority, msg any)
- func LogWhen(conditional bool, l level.Priority, m any)
- func Logf(l level.Priority, msg string, a ...any)
- func Logln(l level.Priority, a ...any)
- func Notice(msg any)
- func NoticeWhen(conditional bool, m any)
- func Noticef(msg string, a ...any)
- func Noticeln(a ...any)
- func Sender() send.Sender
- func SetConverter(c message.Converter)
- func SetSender(s send.Sender)
- func Trace(msg any)
- func TraceWhen(conditional bool, m any)
- func Tracef(msg string, a ...any)
- func Traceln(a ...any)
- func Warning(msg any)
- func WarningWhen(conditional bool, m any)
- func Warningf(msg string, a ...any)
- func Warningln(a ...any)
- func WithContextLogger(ctx context.Context, name string, logger Logger) context.Context
- func WithLogger(ctx context.Context, logger Logger) context.Context
- func WithNewContextLogger(ctx context.Context, name string, fn func() send.Sender) context.Context
- type Logger
- func (g Logger) Alert(m any)
- func (g Logger) AlertWhen(c bool, m any)
- func (g Logger) Alertf(m string, a ...any)
- func (g Logger) Alertln(a ...any)
- func (g Logger) Build() *message.Builder
- func (g Logger) Clone() Logger
- func (g Logger) Convert(m any) message.Composer
- func (g Logger) Critical(m any)
- func (g Logger) CriticalWhen(c bool, m any)
- func (g Logger) Criticalf(m string, a ...any)
- func (g Logger) Criticalln(a ...any)
- func (g Logger) Debug(m any)
- func (g Logger) DebugWhen(c bool, m any)
- func (g Logger) Debugf(m string, a ...any)
- func (g Logger) Debugln(a ...any)
- func (g Logger) Emergency(m any)
- func (g Logger) EmergencyFatal(m any)
- func (g Logger) EmergencyPanic(m any)
- func (g Logger) EmergencyWhen(c bool, m any)
- func (g Logger) Emergencyf(m string, a ...any)
- func (g Logger) Emergencyln(a ...any)
- func (g Logger) Error(m any)
- func (g Logger) ErrorWhen(c bool, m any)
- func (g Logger) Errorf(m string, a ...any)
- func (g Logger) Errorln(a ...any)
- func (g Logger) Info(m any)
- func (g Logger) InfoWhen(c bool, m any)
- func (g Logger) Infof(m string, a ...any)
- func (g Logger) Infoln(a ...any)
- func (g Logger) Log(l level.Priority, m any)
- func (g Logger) LogWhen(c bool, l level.Priority, m any)
- func (g Logger) Logf(l level.Priority, msg string, a ...any)
- func (g Logger) Logln(l level.Priority, a ...any)
- func (g Logger) Notice(m any)
- func (g Logger) NoticeWhen(c bool, m any)
- func (g Logger) Noticef(m string, a ...any)
- func (g Logger) Noticeln(a ...any)
- func (g Logger) Sender() send.Sender
- func (g Logger) SetConverter(m message.Converter)
- func (g Logger) SetSender(s send.Sender)
- func (g Logger) Trace(m any)
- func (g Logger) TraceWhen(c bool, m any)
- func (g Logger) Tracef(m string, a ...any)
- func (g Logger) Traceln(a ...any)
- func (g Logger) Warning(m any)
- func (g Logger) WarningWhen(c bool, m any)
- func (g Logger) Warningf(m string, a ...any)
- func (g Logger) Warningln(a ...any)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CriticalWhen ¶
func Criticalln ¶
func Criticalln(a ...any)
func EmergencyFatal ¶
func EmergencyFatal(msg any)
func EmergencyPanic ¶
func EmergencyPanic(msg any)
func EmergencyWhen ¶
func Emergencyf ¶
func Emergencyln ¶
func Emergencyln(a ...any)
func HasContextLogger ¶ added in v0.2.0
HasContextLogger checks the provided context to see if a logger with the given name is attached to the provided context.
func HasLogger ¶ added in v0.2.6
HasLogger returns true when the default context logger is attached.
func NoticeWhen ¶
func SetConverter ¶ added in v0.3.2
func WarningWhen ¶
func WithContextLogger ¶ added in v0.2.0
WithContextLogger attaches a logger with a specific name to the context. Your package should wrap this and use constants for logger names. In most cases, WithLogger to set a default logger, or even just using the standard Context is preferable.
If this logger exists, WitContextLogger is a noop and the existing context is returned directly.
func WithLogger ¶
WithLogger attaches a Logger instance to the context.
func WithNewContextLogger ¶ added in v0.2.8
WithNewContextLogger checks if a logger is configured with a specific name in the current context. If this logger exists, WithNewContextLogger is a noop; otherwise, it constructs a logger with the sender produced by the provided function and attaches it to the context returning that context.
The name provided controls the id of the logger in the context, not the name of the logger.
Types ¶
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger provides the public interface of the grip Logger.
Package level functions mirror all methods on the Logger type to access a "global" Logger instance in the grip package.
func Context ¶
Context resolves a logger from the given context, and if one does not exist (or the context is nil), produces the global Logger instance.
func ContextLogger ¶ added in v0.2.8
ContextLogger produces a logger stored in the context by a given name. If such a context is not stored the standard/default logger is returned.
func MakeLogger ¶ added in v0.3.2
MakeLogger constructs a new sender with the specified converter function.
func (Logger) Clone ¶ added in v0.3.2
Clone creates a new Logger with the same message sender and converter; however they are fully independent loggers.
func (Logger) CriticalWhen ¶
func (Logger) Criticalln ¶
func (Logger) EmergencyFatal ¶
func (Logger) EmergencyPanic ¶
func (Logger) EmergencyWhen ¶
func (Logger) Emergencyf ¶
func (Logger) Emergencyln ¶
func (Logger) NoticeWhen ¶
func (Logger) SetConverter ¶ added in v0.3.2
func (Logger) WarningWhen ¶
Directories ¶
Path | Synopsis |
---|---|
Package level defines a Priority type and some conversion methods for a 7-tiered logging level schema, which mirror syslog and system's logging levels.
|
Package level defines a Priority type and some conversion methods for a 7-tiered logging level schema, which mirror syslog and system's logging levels. |
package message defines the Composer interface and a handful of implementations which represent the structure for messages produced by grip.
|
package message defines the Composer interface and a handful of implementations which represent the structure for messages produced by grip. |
Package recovery provides a number of grip-integrated panic handling tools for capturing and responding to panics using grip loggers.
|
Package recovery provides a number of grip-integrated panic handling tools for capturing and responding to panics using grip loggers. |
Call Site Sender
|
Call Site Sender |
Package series provides tools for collecting and aggregating timeseries events as part of the logging infrastructure.
|
Package series provides tools for collecting and aggregating timeseries events as part of the logging infrastructure. |
x
|
|
desktop
Module
|
|
email
Module
|
|
github
Module
|
|
graphite
Module
|
|
jira
Module
|
|
metrics
Module
|
|
slack
Module
|
|
splunk
Module
|
|
sumologic
Module
|
|
system
Module
|
|
telegram
Module
|
|
twitter
Module
|
|
xmpp
Module
|
|
zap
Module
|
|
zerolog
Module
|