Categorygithub.com/tommzn/go-log
modulepackage
1.2.2
Repository: https://github.com/tommzn/go-log.git
Documentation: pkg.go.dev

# README

Go Reference GitHub go.mod Go version GitHub tag (latest SemVer) Go Report Card

Logger

Provides a logger with different formatter and shipper. By default it logs to stdoutm but you can use log shipping to Logz.io as well.

# Functions

appendContextValues adds passed values to context fo given logger.
AppendFromLambdaContext appends some values from given context, e.g.
DefaultContextForK8s returns a log context with kubernetes node and pod name if both has benn set as K8S_NODE_NAME and K8S_POD_NAME during deployment.
DefaultContextForNodes returns a log context with hostname and ip (v4).
LogContextWithValues adds passed log values to passed context.
LogLevelByName will try to convert passed name of a log level into a log level.
LogLevelFromConfig reads log level from config using "log.loglevel" as key.
LogLevelFromEnv will lookup for environment variable defined by ENV_LOGLEVEL and if it exists call LogLevelByName to convert it's value to a log level.
NewLogger returns a new logger with passed log level, formatter and shipper.
NewLoggerFromConfig returns a new logger created depending on passed config.
WithK8sContext appends kubernetes values from environment variables as context At the moment following environment variables are supported: K8S_NODE_NAME - Node name K8S_POD_NAME - Pod name.
WithNameSpace appends passed namespace as log context.

# Constants

Debug is a log level for dev outputs.
ENV_LOGLEVEL defines the environment variable which can be used to set a log level.
Error is a log level for errors.
Info is a log level for status information.
LogCtxDomain is a context key for a domain.
LogCtxHostname is a context keyfor a hostname.
LogCtxIp is a context key for an Ip (v4).
LogCtxK8sNode is a context key for kubernetes node name.
LogCtxK8sPod is a context key for a kubernetes pod name.
LogCtxLogLevel is a context key for used log level.
LogCtxMessage is a context key for log messages.
LogCtxNamespace is a context key for a namespace.
LogCtxRequestId is a context key used for a request id.
LogCtxTimestamp is a context key for a timestamp.
LOGZIO_BATCH_SIZE is the default batch size the Logz.io shipper will use.
LOGZIO_TIMESTAMP_FORMAT is Logz.io timestamp format which will be used for @timestamp value in a log record.
LOGZIO_TOKEN_KEY defines the key which will be used to obtain the Logz.io token from secrets mananger.
LOGZIO_URL define the endpoint all logs will be shipped to.
MESSAGE_READ_TIMEOUT defines the time a shipper will wait for new messages during reading from message stack.
MESSAGE_STACK_SIZE defines the capacity of internal message buffer.
None diables logging.
SHIPMENT_STACK_SIZE defines the number of worker which can ship logs in parallel to Logz.io.
SHIPMENT_WAIT_TIMEOUT defines the time the shipper will wait to get a slot from shipment stack.
Status can be used to log messages.

# Structs

DefaultFormatter is a fallback formatter to convert log values into a message.
LogContext provides context values for logging.
LogHandler provides methods to log messges with different log level and takes care about formatting and shipping logs.
LogzioJsonFormatter will convert passed values to a JSON record suitlable for an import at Logz.io.
LogzioShipper will deliver log messages to Logz.io.
StdoutShipper will print given log messages on stdout.

# Interfaces

LogFormatter will convert passed log values into a suitable log message.
Logger is an infterface for different types of logger.
LogShipper will take care of sending logs to a defined target.

# Type aliases

LogLevel defines the log level, e.g.