Documentation
¶
Overview ¶
Package logging provides logging functionalities for GoFr applications.
Index ¶
- type ContextLogger
- func (l *ContextLogger) ChangeLevel(level Level)
- func (l *ContextLogger) Debug(args ...any)
- func (l *ContextLogger) Debugf(f string, args ...any)
- func (l *ContextLogger) Error(args ...any)
- func (l *ContextLogger) Errorf(f string, args ...any)
- func (l *ContextLogger) Fatal(args ...any)
- func (l *ContextLogger) Fatalf(f string, args ...any)
- func (l *ContextLogger) Info(args ...any)
- func (l *ContextLogger) Infof(f string, args ...any)
- func (l *ContextLogger) Log(args ...any)
- func (l *ContextLogger) Logf(f string, args ...any)
- func (l *ContextLogger) Notice(args ...any)
- func (l *ContextLogger) Noticef(f string, args ...any)
- func (l *ContextLogger) Warn(args ...any)
- func (l *ContextLogger) Warnf(f string, args ...any)
- type Level
- type LogLevelResponder
- type Logger
- type MockLogger
- func (m *MockLogger) ChangeLevel(level Level)
- func (m *MockLogger) Debug(args ...any)
- func (m *MockLogger) Debugf(format string, args ...any)
- func (m *MockLogger) Error(args ...any)
- func (m *MockLogger) Errorf(format string, args ...any)
- func (m *MockLogger) Fatal(args ...any)
- func (m *MockLogger) Fatalf(format string, args ...any)
- func (m *MockLogger) Info(args ...any)
- func (m *MockLogger) Infof(format string, args ...any)
- func (m *MockLogger) Log(args ...any)
- func (m *MockLogger) Logf(format string, args ...any)
- func (m *MockLogger) Notice(args ...any)
- func (m *MockLogger) Noticef(format string, args ...any)
- func (m *MockLogger) Warn(args ...any)
- func (m *MockLogger) Warnf(format string, args ...any)
- type PrettyPrint
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ContextLogger ¶ added in v1.39.1
type ContextLogger struct {
// contains filtered or unexported fields
}
ContextLogger is a wrapper around a base Logger that injects the current trace ID (if present in the context) into log messages automatically.
It is intended for use within request-scoped contexts where OpenTelemetry trace information is available.
func NewContextLogger ¶ added in v1.39.1
func NewContextLogger(ctx context.Context, base Logger) *ContextLogger
NewContextLogger creates a new ContextLogger that wraps the provided base logger and automatically appends OpenTelemetry trace information (trace ID) to log output when available in the context.
func (*ContextLogger) ChangeLevel ¶ added in v1.39.1
func (l *ContextLogger) ChangeLevel(level Level)
func (*ContextLogger) Debug ¶ added in v1.39.1
func (l *ContextLogger) Debug(args ...any)
func (*ContextLogger) Debugf ¶ added in v1.39.1
func (l *ContextLogger) Debugf(f string, args ...any)
func (*ContextLogger) Error ¶ added in v1.39.1
func (l *ContextLogger) Error(args ...any)
func (*ContextLogger) Errorf ¶ added in v1.39.1
func (l *ContextLogger) Errorf(f string, args ...any)
func (*ContextLogger) Fatal ¶ added in v1.39.1
func (l *ContextLogger) Fatal(args ...any)
func (*ContextLogger) Fatalf ¶ added in v1.39.1
func (l *ContextLogger) Fatalf(f string, args ...any)
func (*ContextLogger) Info ¶ added in v1.39.1
func (l *ContextLogger) Info(args ...any)
func (*ContextLogger) Infof ¶ added in v1.39.1
func (l *ContextLogger) Infof(f string, args ...any)
func (*ContextLogger) Log ¶ added in v1.39.1
func (l *ContextLogger) Log(args ...any)
func (*ContextLogger) Logf ¶ added in v1.39.1
func (l *ContextLogger) Logf(f string, args ...any)
func (*ContextLogger) Notice ¶ added in v1.39.1
func (l *ContextLogger) Notice(args ...any)
func (*ContextLogger) Noticef ¶ added in v1.39.1
func (l *ContextLogger) Noticef(f string, args ...any)
func (*ContextLogger) Warn ¶ added in v1.39.1
func (l *ContextLogger) Warn(args ...any)
func (*ContextLogger) Warnf ¶ added in v1.39.1
func (l *ContextLogger) Warnf(f string, args ...any)
type Level ¶
type Level int
Level represents different logging levels.
func GetLevelFromString ¶
GetLevelFromString converts a string to a logging level.
func GetLogLevelForError ¶ added in v1.29.0
GetLogLevelForError extracts the log level from an error if it implements LogLevelResponder. If the error does not implement this interface, it defaults to ERROR level. This is useful for determining the appropriate log level when handling errors.
func (Level) MarshalJSON ¶
type LogLevelResponder ¶ added in v1.29.0
type LogLevelResponder interface {
LogLevel() Level
}
LogLevelResponder provides a method to get the log level.
type Logger ¶
type Logger interface {
Debug(args ...any)
Debugf(format string, args ...any)
Log(args ...any)
Logf(format string, args ...any)
Info(args ...any)
Infof(format string, args ...any)
Notice(args ...any)
Noticef(format string, args ...any)
Warn(args ...any)
Warnf(format string, args ...any)
Error(args ...any)
Errorf(format string, args ...any)
Fatal(args ...any)
Fatalf(format string, args ...any)
ChangeLevel(level Level)
}
Logger defines the interface for structured logging across different log levels such as Debug, Info, Warn, Error, and Fatal. It allows formatted logs and log level control.
func NewFileLogger ¶ added in v1.1.1
NewFileLogger creates a new Logger instance that writes logs to the specified file. If the file cannot be opened or created, logs are discarded.
func NewLogger ¶
NewLogger creates a new Logger instance configured with the given log level. Logs will be printed to stdout and stderr depending on the level.
func NewMockLogger ¶ added in v1.6.0
type MockLogger ¶ added in v1.6.0
type MockLogger struct {
// contains filtered or unexported fields
}
func (*MockLogger) ChangeLevel ¶ added in v1.6.0
func (m *MockLogger) ChangeLevel(level Level)
func (*MockLogger) Debug ¶ added in v1.6.0
func (m *MockLogger) Debug(args ...any)
func (*MockLogger) Debugf ¶ added in v1.6.0
func (m *MockLogger) Debugf(format string, args ...any)
func (*MockLogger) Error ¶ added in v1.6.0
func (m *MockLogger) Error(args ...any)
func (*MockLogger) Errorf ¶ added in v1.6.0
func (m *MockLogger) Errorf(format string, args ...any)
func (*MockLogger) Fatal ¶ added in v1.6.0
func (m *MockLogger) Fatal(args ...any)
func (*MockLogger) Fatalf ¶ added in v1.6.0
func (m *MockLogger) Fatalf(format string, args ...any)
func (*MockLogger) Info ¶ added in v1.6.0
func (m *MockLogger) Info(args ...any)
func (*MockLogger) Infof ¶ added in v1.6.0
func (m *MockLogger) Infof(format string, args ...any)
func (*MockLogger) Log ¶ added in v1.6.0
func (m *MockLogger) Log(args ...any)
func (*MockLogger) Logf ¶ added in v1.6.0
func (m *MockLogger) Logf(format string, args ...any)
func (*MockLogger) Notice ¶ added in v1.6.0
func (m *MockLogger) Notice(args ...any)
func (*MockLogger) Noticef ¶ added in v1.6.0
func (m *MockLogger) Noticef(format string, args ...any)
func (*MockLogger) Warn ¶ added in v1.6.0
func (m *MockLogger) Warn(args ...any)
func (*MockLogger) Warnf ¶ added in v1.6.0
func (m *MockLogger) Warnf(format string, args ...any)
type PrettyPrint ¶ added in v1.4.0
PrettyPrint defines an interface for objects that can render themselves in a human-readable format to the provided writer.