log

package
v0.0.0-...-6c624c4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 21, 2022 License: MIT Imports: 10 Imported by: 43

Documentation

Index

Constants

View Source
const AdditionnalLogElementsKey = "additionnal-log-elements"
View Source
const LogLevel = "loglevel"
View Source
const LoggerKey = "logger"
View Source
const ProcessPidKey = "pid"
View Source
const RequestUuidKey = "request-uuid"

Variables

View Source
var ProcessName = os.Args[0]

Functions

func AddToLogContext

func AddToLogContext(ctx context.Context, args ...interface{}) context.Context

Add custom fields to the context This supports a tuple for the args

ex: "mykey1", "myval1", "mykey2", "myval2"

func Die

func Die(msg string, args ...interface{})

panic while logging a problem as critical

func LogDebug

func LogDebug(ctx context.Context, msg string)

func LogDebugf

func LogDebugf(ctx context.Context, msg string, args ...interface{})

func LogError

func LogError(ctx context.Context, msg string)

func LogErrorf

func LogErrorf(ctx context.Context, msg string, args ...interface{})

func LogInfo

func LogInfo(ctx context.Context, msg string)

func LogInfof

func LogInfof(ctx context.Context, msg string, args ...interface{})

func LogWarn

func LogWarn(ctx context.Context, msg string)

func LogWarnf

func LogWarnf(ctx context.Context, msg string, args ...interface{})

func Logger

func Logger() log.Logger

Get a logger that isn't tied to any specific context

func LoggerAddHandler

func LoggerAddHandler(ctx context.Context, f func(*log.Record) error) context.Context

Add a handler to a logger in the context

func LoggerDebugFunc

func LoggerDebugFunc(ctx context.Context, f func() string)

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

func LoggerDummyContext() context.Context

Get a logger dummy context (empty context)

func LoggerGetLevel

func LoggerGetLevel(ctx context.Context) string

Get the level of a logger from a context

func LoggerNewContext

func LoggerNewContext(ctx context.Context) context.Context

Create a new logger in a context Will ensure that its initialized with the PID of the current process

func LoggerNewRequest

func LoggerNewRequest(ctx context.Context) context.Context

Generate a new UUID for the current request and add it to the context

func LoggerSetLevel

func LoggerSetLevel(ctx context.Context, levelStr string) context.Context

Set the level of a logger from a context This will Die/panic if the provided level is invalid

func LoggerWContext

func LoggerWContext(ctx context.Context, args ...interface{}) log.Logger

Get a logger initialized with the values from the context (pid, request id and additionnal elements)

func SetProcessName

func SetProcessName(Name string)

Set the ProcessName

func TranferLogContext

func TranferLogContext(sourceCtx context.Context, destCtx context.Context) context.Context

Transfer the logger from a context to another

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

type PfLogger

type PfLogger = log.Logger

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL