Documentation ¶
Index ¶
Constants ¶
const ( OriginKey string = "origin" MethodKey string = "method" PathKey string = "path" QueryKey string = "query" CodeKey string = "code" CauseKey string = "cause" BodyKey string = "body" ErrorKey string = "err" )
API keys
const ( // The key used in contexts to retrieve the logger that should be used ContextLogKey NmcContextKey = "nmc_logger" // Lumberjack settings MaxLogSize int = 20 MaxLogBackups int = 3 MaxLogAge int = 28 )
Variables ¶
This section is empty.
Functions ¶
func ReplaceTime ¶
Replaces the default time formatting (RFC3339) in a logger with an easier to read format
Types ¶
type Logger ¶
Logger is a simple wrapper for a slog Logger that writes to a file on disk.
func FromContext ¶
Retrieves the logger from the context
func NewDefaultLogger ¶ added in v0.5.0
func NewDefaultLogger() *Logger
Creates a new logger that uses the slog default logger, which writes to the terminal instead of a file. Operations like rotation don't apply to this logger.
func NewLogger ¶
func NewLogger(logFilePath string, options LoggerOptions) (*Logger, error)
Creates a new logger that writes out to a log file on disk.
func (*Logger) CreateContextWithLogger ¶
Creates a copy of the parent context with the logger put into the ContextLogKey value
func (*Logger) CreateSubLogger ¶
Create a clone of the logger that prints each message with the "origin" attribute. The underlying file handle isn't copied, so calling Close() on the sublogger won't do anything.
func (*Logger) GetFilePath ¶
Get the path of the file this logger is writing to
type LoggerOptions ¶
type LoggerOptions struct { // The maximum size (in megabytes) of the log file before it gets rotated MaxSize int // The maximum number of old log files to retain. // Use 0 to retain all backups. MaxBackups int // The maximum number of days to retain old log files based on the timestamp encoded in their filename. // Use 0 to always preserve old logs. MaxAge int // True to format the timestamps in backup files in the computer's local time; false to format in UTC LocalTime bool // True to compress rotated log files using gzip Compress bool // The format to use when printing logs Format LogFormat // The minimum record level that will be logged Level slog.Level // True to include the source code position of the log statement in log messages AddSource bool }
Options for logging
type NmcContextKey ¶
type NmcContextKey string
type TerminalLogger ¶
Simple logger that logs colored messages directly to the terminal (stdout) without time or level. Useful for CLI applications that only log debug messages, where such things aren't relevant.
func NewTerminalLogger ¶
func NewTerminalLogger(debugEnabled bool, logColor color.Attribute) *TerminalLogger
Creates a new TerminalLogger instance