Documentation
¶
Overview ¶
go-coverage:ignore
Index ¶
- type Config
- type Entry
- type GenericLogger
- func (l GenericLogger) Debug(ctx context.Context, msg string)
- func (l GenericLogger) DebugWithData(ctx context.Context, msg string, info map[string]any)
- func (l GenericLogger) Error(ctx context.Context, msg string, err error)
- func (l GenericLogger) ErrorWithData(ctx context.Context, msg string, err error, info map[string]any)
- func (l GenericLogger) Fatal(ctx context.Context, msg string, err error)
- func (l GenericLogger) FatalWithData(ctx context.Context, msg string, err error, info map[string]any)
- func (l GenericLogger) Info(ctx context.Context, msg string)
- func (l GenericLogger) InfoWithData(ctx context.Context, msg string, info map[string]any)
- func (l *GenericLogger) SetLevel(level Level) error
- func (l GenericLogger) Trace(ctx context.Context, msg string)
- func (l GenericLogger) TraceWithData(ctx context.Context, msg string, info map[string]any)
- func (l GenericLogger) Warn(ctx context.Context, msg string, err error)
- func (l GenericLogger) WarnWithData(ctx context.Context, msg string, err error, info map[string]any)
- type Level
- type Logger
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// Level is the level of the logger.
Level Level
}
Config is the configuration of the logger.
type Entry ¶
type Entry struct {
Timestamp int64 `json:"timestamp"`
Level Level `json:"-"`
LevelStr string `json:"level"`
Name string `json:"name,omitempty"`
Version string `json:"version,omitempty"`
Trace trace.Trace `json:"trace"`
Error error `json:"error,omitempty"`
Info map[string]any `json:"info"`
Msg string `json:"msg"`
}
Entry is the json representation of a log entry.
type GenericLogger ¶
type GenericLogger struct {
// Name is the name of the app.
//
// When using the [New] function, it is set to the empty
// string. If it is set to a non-empty string, it is not
// serialized in the logs.
Name string
// Version is the version of the app.
//
// When using the [New] function, it is set to the empty
// string. If it is set to a non-empty string, it is not
// serialized in the logs.
Version string
// contains filtered or unexported fields
}
GenericLogger is an implementation of the Logger interface.
func New ¶
func New() *GenericLogger
New creates a new GenericLogger that implements the Logger interface.
By default, it sets the level of the logger to LEVEL_INFO.
func (GenericLogger) Debug ¶
func (l GenericLogger) Debug(ctx context.Context, msg string)
Debug logs a debug entry.
func (GenericLogger) DebugWithData ¶
DebugWithData logs a debug entry.
func (GenericLogger) Error ¶
func (l GenericLogger) Error(ctx context.Context, msg string, err error)
Error logs an error entry.
func (GenericLogger) ErrorWithData ¶
func (l GenericLogger) ErrorWithData(ctx context.Context, msg string, err error, info map[string]any)
ErrorWithData logs an error entry.
func (GenericLogger) Fatal ¶
func (l GenericLogger) Fatal(ctx context.Context, msg string, err error)
Fatal logs a fatal entry and it's followed by a os.Exit(1) call
func (GenericLogger) FatalWithData ¶
func (l GenericLogger) FatalWithData(ctx context.Context, msg string, err error, info map[string]any)
FatalWithData logs a fatal entry and it's followed by a os.Exit(1) call
func (GenericLogger) Info ¶
func (l GenericLogger) Info(ctx context.Context, msg string)
Info logs an info entry.
func (GenericLogger) InfoWithData ¶
InfoWithData logs an info entry.
func (*GenericLogger) SetLevel ¶
func (l *GenericLogger) SetLevel(level Level) error
SetLevel sets the level of the logger.
If the level is not valid, it returns an error of type errors.Error and leaves the level unchanged.
func (GenericLogger) Trace ¶
func (l GenericLogger) Trace(ctx context.Context, msg string)
Trace logs a debug entry.
func (GenericLogger) TraceWithData ¶
TraceWithData logs a debug entry.
func (GenericLogger) Warn ¶
func (l GenericLogger) Warn(ctx context.Context, msg string, err error)
Warn logs a warn entry.
func (GenericLogger) WarnWithData ¶
func (l GenericLogger) WarnWithData(ctx context.Context, msg string, err error, info map[string]any)
WarnWithData logs a warn entry.
type Level ¶
type Level int
Level is the level of the logger.
const ( // LEVEL_TRACE is the trace level. LEVEL_TRACE Level = (iota + 1) * 10 // LEVEL_DEBUG is the debug level. LEVEL_DEBUG // LEVEL_INFO is the info level. LEVEL_INFO // LEVEL_WARN is the warn level. LEVEL_WARN // LEVEL_ERROR is the error level. LEVEL_ERROR // LEVEL_FATAL is the fatal level. LEVEL_FATAL )
func NewLevelFromString ¶
NewLevelFromString returns a level from a string. If the string is not a valid level, an error of type *errors.Error is returned.
type Logger ¶
type Logger interface {
// Trace logs a message with the LEVEL_TRACE level.
Trace(ctx context.Context, msg string)
// TraceWithData logs a message with the LEVEL_TRACE level
// and the given data.
TraceWithData(ctx context.Context, msg string, data map[string]any)
// Debug logs a message with the LEVEL_DEBUG level.
Debug(ctx context.Context, msg string)
// DebugWithData logs a message with the LEVEL_DEBUG level
// and the given data.
DebugWithData(ctx context.Context, msg string, data map[string]any)
// Info logs a message with the LEVEL_INFO level.
Info(ctx context.Context, msg string)
// InfoWithData logs a message with the LEVEL_INFO level
// and the given data.
InfoWithData(ctx context.Context, msg string, data map[string]any)
// Warn logs a message with the LEVEL_WARN level.
Warn(ctx context.Context, msg string, err error)
// WarnWithData logs a message with the LEVEL_WARN level
// and the given data.
WarnWithData(ctx context.Context, msg string, err error, data map[string]any)
// Error logs a message with the LEVEL_ERROR level.
Error(ctx context.Context, msg string, err error)
// ErrorWithData logs a message with the LEVEL_ERROR level
// and the given data.
ErrorWithData(ctx context.Context, msg string, err error, data map[string]any)
// Fatal logs a message with the LEVEL_FATAL level and it's followed by a
// call to os.Exit(1).
Fatal(ctx context.Context, msg string, err error)
// FatalWithData logs a message with the LEVEL_FATAL level
// and the given data and it's followed by a call to os.Exit(1).
FatalWithData(ctx context.Context, msg string, err error, data map[string]any)
}