Documentation
¶
Index ¶
- Constants
- Variables
- func AddToLogContext(ctx context.Context, args ...interface{}) context.Context
- func Die(msg string, args ...interface{})
- func LogDebug(ctx context.Context, msg string)
- func LogDebugf(ctx context.Context, msg string, args ...interface{})
- func LogError(ctx context.Context, msg string)
- func LogErrorf(ctx context.Context, msg string, args ...interface{})
- func LogInfo(ctx context.Context, msg string)
- func LogInfof(ctx context.Context, msg string, args ...interface{})
- func LogWarn(ctx context.Context, msg string)
- func LogWarnf(ctx context.Context, msg string, args ...interface{})
- func Logger() log.Logger
- func LoggerAddHandler(ctx context.Context, f func(*log.Record) error) context.Context
- func LoggerDebugFunc(ctx context.Context, f func() string)
- func LoggerDummyContext() context.Context
- func LoggerGetLevel(ctx context.Context) string
- func LoggerNewContext(ctx context.Context) context.Context
- func LoggerNewRequest(ctx context.Context) context.Context
- func LoggerSetLevel(ctx context.Context, levelStr string) context.Context
- func LoggerWContext(ctx context.Context, args ...interface{}) log.Logger
- func SetProcessName(Name string)
- func TranferLogContext(sourceCtx context.Context, destCtx context.Context) context.Context
- type LoggerStruct
- type PfLogger
Constants ¶
const AdditionnalLogElementsKey = "additionnal-log-elements"
const LogLevel = "loglevel"
const LoggerKey = "logger"
const ProcessPidKey = "pid"
const RequestUuidKey = "request-uuid"
Variables ¶
var ProcessName = os.Args[0]
Functions ¶
func AddToLogContext ¶
Add custom fields to the context This supports a tuple for the args
ex: "mykey1", "myval1", "mykey2", "myval2"
func LoggerAddHandler ¶
Add a handler to a logger in the context
func LoggerDebugFunc ¶
Logging helper that allows for lazy evaluation of debug statements The function f will only be executed if the current logger (in the context) is in debug The function f can also log statements on its own If an empty string is returned from f, it will not be logger
func LoggerDummyContext ¶
Get a logger dummy context (empty context)
func LoggerGetLevel ¶
Get the level of a logger from a context
func LoggerNewContext ¶
Create a new logger in a context Will ensure that its initialized with the PID of the current process
func LoggerNewRequest ¶
Generate a new UUID for the current request and add it to the context
func LoggerSetLevel ¶
Set the level of a logger from a context This will Die/panic if the provided level is invalid
func LoggerWContext ¶
Get a logger initialized with the values from the context (pid, request id and additionnal elements)
Types ¶
type LoggerStruct ¶
type LoggerStruct struct { Level string // contains filtered or unexported fields }
Structure that contains the necessary data to make this logger work
func (LoggerStruct) NewLogger ¶
func (l LoggerStruct) NewLogger() LoggerStruct
Create a new logger from an existing one with the same confiuration
func (*LoggerStruct) SetHandler ¶
func (l *LoggerStruct) SetHandler(handler log.Handler)
Set the handler for the logger This should *only* be called to set the handler for the actual backend (syslog, file, ...) and not when leveling the handler as LoggerStruct.handler is the logger non-leveled handler