Documentation
¶
Overview ¶
Package log provides a logger with different formatter and shipper.
Index ¶
- Constants
- func LogContextWithValues(ctx context.Context, values map[string]string) context.Context
- type DefaultFormatter
- type LogContext
- type LogFormatter
- type LogHandler
- func (logger *LogHandler) Debug(v ...interface{})
- func (logger *LogHandler) Debugf(message string, v ...interface{})
- func (logger *LogHandler) Error(v ...interface{})
- func (logger *LogHandler) Errorf(message string, v ...interface{})
- func (logger *LogHandler) Flush()
- func (logger *LogHandler) Info(v ...interface{})
- func (logger *LogHandler) Infof(message string, v ...interface{})
- func (logger *LogHandler) WithContext(ctx context.Context)
- type LogLevel
- type LogShipper
- type Logger
- type LogzioJsonFormatter
- type LogzioShipper
- type StdoutShipper
Constants ¶
const ( // LogCtxRequestId is a context key used for a request id. LogCtxRequestId = "requestid" // LogCtxLogLevel is a context key for used log level. LogCtxLogLevel = "loglevel" // LogCtxMessage is a context key for log messages. LogCtxMessage = "message" // LogCtxTimestamp is a context key for a timestamp. LogCtxTimestamp = "timestamp" // LogCtxNamespace is a context key for a namespace. LogCtxNamespace = "namespace" // LogCtxDomain is a context key for a domain. LogCtxDomain = "domain" // LogCtxHostname is a context keyfor a hostname. LogCtxHostname = "hostname" // LogCtxIp is a context key for an Ip (v4). LogCtxIp = "ip" // LogCtxK8sNode is a context key for kubernetes node name. LogCtxK8sNode = "k8s_node" // LogCtxK8sPod is a context key for a kubernetes pod name. LogCtxK8sPod = "k8s_pod" )
const ENV_LOGLEVEL = "LOGLEVEL"
ENV_LOGLEVEL defines the environment variable which can be used to set a log level.
const LOGZIO_BATCH_SIZE = 10
LOGZIO_BATCH_SIZE is the default batch size the Logz.io shipper will use. Can be set by config: log.logzio.batchsize
const LOGZIO_TIMESTAMP_FORMAT = "2006-01-02T15:04:05.999Z"
LOGZIO_TIMESTAMP_FORMAT is Logz.io timestamp format which will be used for @timestamp value in a log record.
const LOGZIO_TOKEN_KEY = "LOGZIO_TOKEN"
LOGZIO_TOKEN_KEY defines the key which will be used to obtain the Logz.io token from secrets mananger.
const LOGZIO_URL = "https://listener.logz.io:8071/"
LOGZIO_URL define the endpoint all logs will be shipped to. Can be set by config: log.logzio.url
const MESSAGE_READ_TIMEOUT = 50 * time.Millisecond
MESSAGE_READ_TIMEOUT defines the time a shipper will wait for new messages during reading from message stack. Can be set by config: log.logzio.messagereadtimeout
const MESSAGE_STACK_SIZE = 500
MESSAGE_STACK_SIZE defines the capacity of internal message buffer. Can be set by config: log.logzio.messagestacksize
const SHIPMENT_STACK_SIZE = 2
SHIPMENT_STACK_SIZE defines the number of worker which can ship logs in parallel to Logz.io. Can be set by config: log.logzio.shipmentstacksize
const SHIPMENT_WAIT_TIMEOUT = 1 * time.Second
SHIPMENT_WAIT_TIMEOUT defines the time the shipper will wait to get a slot from shipment stack. Can be set by config: log.logzio.shipmenttimeout
Variables ¶
This section is empty.
Functions ¶
Types ¶
type DefaultFormatter ¶
type DefaultFormatter struct { }
DefaultFormatter is a fallback formatter to convert log values into a message.
type LogContext ¶
type LogContext struct {
// contains filtered or unexported fields
}
LogContext provides context values for logging.
func DefaultContextForK8s ¶
func DefaultContextForK8s() LogContext
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.
func DefaultContextForNodes ¶
func DefaultContextForNodes() LogContext
DefaultContextForNodes returns a log context with hostname and ip (v4).
func (LogContext) AppendValues ¶
func (logContext LogContext) AppendValues(values map[string]string) LogContext
AppendValues reads values from current log context, append passed values and returns a new log context.
func (LogContext) String ¶
func (logContext LogContext) String() string
String creates a string representation of internal values map.
type LogFormatter ¶
type LogFormatter interface {
// contains filtered or unexported methods
}
LogFormatter will convert passed log values into a suitable log message.
type LogHandler ¶
type LogHandler struct {
// contains filtered or unexported fields
}
LogHandler provides methods to log messges with different log level and takes care about formatting and shipping logs.
func (*LogHandler) Debug ¶
func (logger *LogHandler) Debug(v ...interface{})
Debug will create a log message with given values for log level Debug.
func (*LogHandler) Debugf ¶
func (logger *LogHandler) Debugf(message string, v ...interface{})
Debugf format given log message for log level Debug.
func (*LogHandler) Error ¶
func (logger *LogHandler) Error(v ...interface{})
Error will create a log message with given values for log level Error.
func (*LogHandler) Errorf ¶
func (logger *LogHandler) Errorf(message string, v ...interface{})
Errorf format given log message for log level Error.
func (*LogHandler) Flush ¶
func (logger *LogHandler) Flush()
Flush will force it's log shipper to deliver all remaining log messages.
func (*LogHandler) Info ¶
func (logger *LogHandler) Info(v ...interface{})
Info will create a log message with given values for log level Info.
func (*LogHandler) Infof ¶
func (logger *LogHandler) Infof(message string, v ...interface{})
Infof format given log message for log level Info.
func (*LogHandler) WithContext ¶
func (logger *LogHandler) WithContext(ctx context.Context)
WithContext applies the log context.
type LogLevel ¶
type LogLevel int
LogLevel defines the log level, e.g. error or debug.
func LogLevelByName ¶
LogLevelByName will try to convert passed name of a log level into a log level. If there's no suitable log level for a given name, log level None is returned, which disables logging.
func LogLevelFromEnv ¶
func LogLevelFromEnv() LogLevel
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.
type LogShipper ¶
type LogShipper interface {
// contains filtered or unexported methods
}
LogShipper will take care of sending logs to a defined target.
type Logger ¶
type Logger interface { // WithContext sets a given log context. WithContext(context.Context) // Errorf logs a formated message with log level Error. Errorf(message string, v ...interface{}) // Error logs given message with log level Error. Error(v ...interface{}) // Errorf logs a formated message with log level Info. Infof(message string, v ...interface{}) // Error logs given message with log level Info. Info(v ...interface{}) // Errorf logs a formated message with log level Debug. Debugf(message string, v ...interface{}) // Error logs given message with log level Debug. Debug(v ...interface{}) // FLush tells the log shipper to cleat it's internal message queue. Flush() }
Logger is an infterface for different types of logger.
func NewLogger ¶
func NewLogger(logLevel LogLevel, formatter LogFormatter, shipper LogShipper) Logger
NewLogger returns a new logger with passed log level, formatter and shipper. If you omit formatter and shipper the DefaultFormatter and StdoutShipper will be used.
func NewLoggerFromConfig ¶
func NewLoggerFromConfig(conf config.Config, secretsManager secrets.SecretsManager) Logger
NewLoggerFromConfig returns a new logger created depending on passed config.
type LogzioJsonFormatter ¶
type LogzioJsonFormatter struct { }
LogzioJsonFormatter will convert passed values to a JSON record suitlable for an import at Logz.io.
type LogzioShipper ¶
type LogzioShipper struct {
// contains filtered or unexported fields
}
LogzioShipper will deliver log messages to Logz.io.
type StdoutShipper ¶
type StdoutShipper struct { }
StdoutShipper will print given log messages on stdout.