log

package module
v0.59.0 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2024 License: Apache-2.0 Imports: 2 Imported by: 9

Documentation

Overview

Package log implements a component to handle logging internal to the agent.

The component uses a number of values in BundleParams to decide how to initialize itself, reading values from the comp/core/config component when necessary. At present, it configures and wraps the global logger in pkg/util/log, but will eventually be self-sufficient.

The mock component does not read any configuration values, and redirects logging output to `t.Log(..)`, for ease of investigation when a test fails.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Component

type Component interface {
	// Trace logs the given arguments, separated by spaces, at the trace level
	Trace(v ...interface{})
	// Tracef logs the given formatted arguments at the trace level
	Tracef(format string, params ...interface{})

	// Debug logs the given arguments, separated by spaces, at the debug level
	Debug(v ...interface{})
	// Debugf logs the given formatted arguments at the debug level
	Debugf(format string, params ...interface{})

	// Info logs the given arguments, separated by spaces, at the info level
	Info(v ...interface{})
	// Infof logs the given formatted arguments at the info level
	Infof(format string, params ...interface{})

	// Warn logs the given arguments, separated by spaces, at the warn level,
	// and returns an error containing the messages.
	Warn(v ...interface{}) error
	// Warnf logs the given formatted arguments at the warn level, and returns
	// an error containing the message.
	Warnf(format string, params ...interface{}) error

	// Error logs the given arguments, separated by spaces, at the error level,
	// and returns an error containing the messages.
	Error(v ...interface{}) error
	// Errorf logs the given formatted arguments at the error level, and returns
	// an error containing the message.
	Errorf(format string, params ...interface{}) error

	// Critical logs the given arguments, separated by spaces, at the critical level,
	// an error containing the message.
	Critical(v ...interface{}) error
	// Criticalf logs the given formatted arguments at the critical level, and returns
	// an error containing the message.
	Criticalf(format string, params ...interface{}) error

	// Flush will flush the contents of the logs to the sinks
	Flush()
}

Component is the component type.

type Params

type Params struct {
	// contains filtered or unexported fields
}

Params defines the parameters for this log component.

Logs-related parameters are implemented as unexported fields containing callbacks. These fields can be set with the `LogXxx()` methods, which return the updated LogParams. One of `logimpl.ForOneShot` or `logimpl.ForDaemon` must be called.

func ForDaemon

func ForDaemon(loggerName, logFileConfig, defaultLogFile string) Params

ForDaemon sets up logging parameters for a daemon app.

The log level is set based on the `log_level` config parameter.

The log file is set based on the logFileConfig config parameter, or disabled if `disable_file_logging` is set.

On platforms which support it, syslog is enabled if `log_to_syslog` is set, using `syslog_uri` or defaulting to "unixgram:///dev/log" if that is empty. The `syslog_rfc` config parameter determines whether this produces 5424-compliant output.

Console logging is enabled if `log_to_console` is set. Lots are formatted as JSON if `log_format_json` is set.

func ForOneShot

func ForOneShot(loggerName, level string, overrideFromEnv bool) Params

ForOneShot sets up logging parameters for a one-shot app.

If overrideFromEnv is set, then DD_LOG_LEVEL will override the given level.

Otherwise, file logging is disabled, syslog is disabled, console logging is enabled, and JSON formatting is disabled.

func (Params) IsLogLevelFnSet

func (params Params) IsLogLevelFnSet() bool

IsLogLevelFnSet returns whether the logLevelFn field is set

func (Params) LogFileFn

func (params Params) LogFileFn(c configGetter) string

LogFileFn returns the log file

func (Params) LogFormatJSONFn

func (params Params) LogFormatJSONFn(c configGetter) bool

LogFormatJSONFn returns a boolean determining whether logs should be written in JSON format

func (Params) LogLevelFn

func (params Params) LogLevelFn(c configGetter) string

LogLevelFn returns the log level

func (Params) LogSyslogRFCFn

func (params Params) LogSyslogRFCFn(c configGetter) bool

LogSyslogRFCFn returns a boolean determining whether to use syslog RFC 5424

func (Params) LogSyslogURIFn

func (params Params) LogSyslogURIFn(c configGetter) string

LogSyslogURIFn returns the syslog URI

func (*Params) LogToConsole

func (params *Params) LogToConsole(logToConsole bool)

LogToConsole modifies the parameters to toggle logging to console

func (Params) LogToConsoleFn

func (params Params) LogToConsoleFn(c configGetter) bool

LogToConsoleFn returns a boolean determining whether to write logs to the console

func (*Params) LogToFile

func (params *Params) LogToFile(logFile string)

LogToFile modifies the parameters to set the destination log file, overriding any previous logfile parameter.

func (Params) LoggerName

func (params Params) LoggerName() string

LoggerName is the name that appears in the logfile

Jump to

Keyboard shortcuts

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