Documentation
¶
Overview ¶
Package logging provides tools for easy logging errors with traceback. Logging package is written over slog.Logger.
Index ¶
- Variables
- func GetLogTraceback(skipLevel int) string
- func LogError(logger Logger, msg string, err error, args ...any)
- func LogErrorContext(ctx context.Context, logger Logger, msg string, err error, args ...any)
- func LogInfo(logger Logger, msg string, args ...any)
- func LogInfoContext(ctx context.Context, logger Logger, msg string, args ...any)
- type Config
- type Level
- type Logger
Constants ¶
This section is empty.
Variables ¶
View Source
var Levels = struct { INFO, DEBUG, WARN, ERROR Level }{ INFO: Level(slog.LevelInfo), DEBUG: Level(slog.LevelDebug), WARN: Level(slog.LevelWarn), ERROR: Level(slog.LevelError), }
Levels are a simple abstractions on slog.Level.
Functions ¶
func GetLogTraceback ¶
GetLogTraceback return a string with info about filename, function name and line https://stackoverflow.com/questions/25927660/how-to-get-the-current-function-name
func LogErrorContext ¶ added in v1.0.5
LogErrorContext uses provided logger to save error with message info and context. Context is used to get request ID and connect it with error.
Types ¶
type Logger ¶ added in v1.5.0
type Logger interface {
Debug(msg string, args ...any)
DebugContext(ctx context.Context, msg string, args ...any)
Info(msg string, args ...any)
InfoContext(ctx context.Context, msg string, args ...any)
Warn(msg string, args ...any)
WarnContext(ctx context.Context, msg string, args ...any)
Error(msg string, args ...any)
ErrorContext(ctx context.Context, msg string, args ...any)
}
Logger interface is created for usage in external application according to "dependency inversion principle" of SOLID due to working via abstractions.
Click to show internal directories.
Click to hide internal directories.