Documentation ¶
Index ¶
- Constants
- func ToCtx(ctx context.Context, logger Logger) context.Context
- type Adapter
- type CtxKey
- type Logger
- func (l Logger) Debug(msg string, fs ...fields.Field)
- func (l Logger) DebugE(msg string, err error, fs ...fields.Field)
- func (l Logger) Error(msg string, err error, fs ...fields.Field)
- func (l Logger) Flush() error
- func (l Logger) Info(msg string, fs ...fields.Field)
- func (l Logger) InfoE(msg string, err error, fs ...fields.Field)
- func (l Logger) IsNop() bool
- func (l Logger) IsZero() bool
- func (l Logger) Log(level int, msg string, err error, fs ...fields.Field)
- func (l Logger) Trace(msg string, fs ...fields.Field)
- func (l Logger) TraceE(msg string, err error, fs ...fields.Field)
- func (l Logger) Warning(msg string, fs ...fields.Field)
- func (l Logger) WarningE(msg string, err error, fs ...fields.Field)
- func (l Logger) WithFields(fs ...fields.Field) Logger
- func (l Logger) WithName(name string) Logger
- func (l Logger) WithStackTrace(_ uint) Logger
- type NopAdapter
Constants ¶
const ( LevelError = iota*10 + 10 LevelWarning LevelInfo LevelDebug LevelTrace DefaultLogLevel = math.MaxInt )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Adapter ¶
type Adapter interface { // Log logs a message with the provided level, message, optional error, and an // arbitrary number of fields. Log(level int, msg string, err error, fs ...fields.Field) // WithFields returns a logger adapter with the given fields attached to it. WithFields(fs ...fields.Field) Adapter // WithName returns a logger adapter with the given name attached to it. WithName(name string) Adapter // WithStackTrace returns a logger adapter with the stack trace attached to it. WithStackTrace(trace string) Adapter // Flush all logs to the output. It is a no-op for non-buffered loggers. // // It is application's responsibility to call this method before it exits. Flush() error }
Adapter is an interface that allows to encapsulate any logger inside Logger.
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
func FromCtx ¶
FromCtx attempts to extract logger from the context. In case logger is not present, or it is not of the correct type, it returns empty logger and false.
func FromCtxOrNop ¶
FromCtxOrNop extracts logger from the context. In case logger is not present, or it is not of the correct type, it returns a nop logger.
func (Logger) Debug ¶
Debug logs a message with the LevelDebug log-level.
Use Debug to log detailed information that is useful during development and debugging.
func (Logger) DebugE ¶
DebugE logs a message with the LevelDebug log-level and the provided error.
Use DebugE to log detailed information that is useful during development and debugging along with an error.
func (Logger) Error ¶
Error logs a message with the LevelError log-level.
Use Error to log any unrecoverable error, such as a database query failure where the application cannot continue. It's OK to pass nil as the error. To attach a stack trace, use Logger.WithStackTrace.
func (Logger) Flush ¶
Flush flushes the underlying logger adapter, allowing buffered adapters to write logs to the output.
It is the application's responsibility to call Logger.Flush before exiting.
func (Logger) Info ¶
Info logs a message with the LevelInfo log-level.
Use Info to log informational messages that highlight the progress of the application.
func (Logger) InfoE ¶
InfoE logs a message with the LevelInfo log-level and the provided error.
Use InfoE to log informational messages that highlight the progress of the application along with an error.
func (Logger) IsNop ¶
IsNop returns true if the logger's adapter is a NopAdapter.
func (Logger) Trace ¶
Trace logs a message with the LevelTrace log-level.
Use Trace to log very detailed information, typically of interest only when diagnosing problems.
func (Logger) TraceE ¶
TraceE logs a message with the LevelTrace log-level and the provided error.
Use TraceE to log very detailed information, typically of interest only when diagnosing problems along with an error.
func (Logger) Warning ¶
Warning logs a message with the LevelWarning log-level.
Use WarningE to log any recoverable error, such as an error during a remote API call where the service did not respond and the application will retry.
func (Logger) WarningE ¶
WarningE logs a message with the LevelWarning log-level and the provided error.
Use WarningE to log any recoverable error, such as an error during a remote API call where the service did not respond and the application will retry.
func (Logger) WithFields ¶
WithFields returns a new child-logger with the given fields attached to it.
func (Logger) WithStackTrace ¶
WithStackTrace returns a new child-logger with the stack trace attached to it.
type NopAdapter ¶
type NopAdapter struct{}
NopAdapter is a no-op logger adapter, it does nothing even if any of its methods called.
func (NopAdapter) Flush ¶
func (NopAdapter) Flush() error
func (NopAdapter) WithFields ¶
func (a NopAdapter) WithFields(...fields.Field) Adapter
func (NopAdapter) WithName ¶
func (a NopAdapter) WithName(string) Adapter
func (NopAdapter) WithStackTrace ¶
func (a NopAdapter) WithStackTrace(string) Adapter