Documentation ¶
Overview ¶
logger.go
zaplogger_structured_messaging.go
logger/zaplogger_logger.go Ref: https://betterstack.com/community/guides/logging/go/zap/#logging-errors-with-zap
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetLogFilepath ¶ added in v0.1.54
EnsureLogFilePath checks the provided path and prepares it for use with the logger. If the path is a directory, it appends a timestamp-based filename. If the path includes a filename, it checks for the existence of the file. If no path is provided, it defaults to creating a log file in the current directory with a timestamp-based name. TODO refactor this it's very confusing.
func GetLoggerBasedOnEnv ¶
GetLoggerBasedOnEnv returns a zap.Logger instance configured for either production or development based on the APP_ENV environment variable. If APP_ENV is set to "development", it returns a development logger. Otherwise, it defaults to a production logger.
func ToZapFields ¶
QUERY What does this do? Why is it in steps of two? Surely we can ammend this to accept a [{k, v}, {k, v}] approach?
Types ¶
type LogLevel ¶
type LogLevel int
func ParseLogLevelFromString ¶ added in v0.0.14
ParseLogLevelFromString takes a string representation of the log level and returns the corresponding LogLevel. Used to convert a string log level from a configuration file to a strongly-typed LogLevel.
type Logger ¶
type Logger interface { GetLogLevel() LogLevel SetLevel(level LogLevel) With(fields ...zapcore.Field) Logger Debug(msg string, fields ...zapcore.Field) Info(msg string, fields ...zapcore.Field) Warn(msg string, fields ...zapcore.Field) Error(msg string, fields ...zapcore.Field) error Panic(msg string, fields ...zapcore.Field) Fatal(msg string, fields ...zapcore.Field) // Updated method signatures to include the 'event' parameter LogRequestStart(event string, requestID string, userID string, method string, url string, headers map[string][]string) LogRequestEnd(event string, method string, url string, statusCode int, duration time.Duration) LogError(event string, method string, url string, statusCode int, serverStatusMessage string, err error, rawResponse string) LogAuthTokenError(event string, method string, url string, statusCode int, err error) LogRetryAttempt(event string, method string, url string, attempt int, reason string, waitDuration time.Duration, err error) LogRateLimiting(event string, method string, url string, retryAfter string, waitDuration time.Duration) LogResponse(event string, method string, url string, statusCode int, responseBody string, responseHeaders map[string][]string, duration time.Duration) LogCookies(direction string, obj interface{}, method, url string) }
Logger interface with structured logging capabilities at various levels.
func BuildLogger ¶
func BuildLogger(logLevel LogLevel, encoding string, logConsoleSeparator string, logFilepath string, exportLogs bool) Logger
BuildLogger creates and returns a new zap logger instance. It configures the logger with JSON formatting and a custom encoder to ensure the 'pid', 'application', and 'timestamp' fields appear at the end of each log message. The function panics if the logger cannot be initialized.