Documentation ¶
Overview ¶
Package ldlog contains a logging abstraction used by LaunchDarkly SDK components.
These types and methods allow you to customize the logging behavior of the SDK, such as filtering log output by level or redirecting it to another destination.
Index ¶
- type BaseLogger
- type LogLevel
- type Loggers
- func (l Loggers) Debug(values ...interface{})
- func (l Loggers) Debugf(format string, values ...interface{})
- func (l Loggers) Error(values ...interface{})
- func (l Loggers) Errorf(format string, values ...interface{})
- func (l Loggers) ForLevel(level LogLevel) BaseLogger
- func (l Loggers) Info(values ...interface{})
- func (l Loggers) Infof(format string, values ...interface{})
- func (l *Loggers) Init()
- func (l *Loggers) SetBaseLogger(baseLogger BaseLogger)
- func (l *Loggers) SetBaseLoggerForLevel(level LogLevel, baseLogger BaseLogger)
- func (l *Loggers) SetMinLevel(minLevel LogLevel)
- func (l *Loggers) SetPrefix(prefix string)
- func (l Loggers) Warn(values ...interface{})
- func (l Loggers) Warnf(format string, values ...interface{})
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BaseLogger ¶
type BaseLogger interface { // Logs a message on a single line. This is equivalent to log.Logger.Println. Println(values ...interface{}) // Logs a message on a single line, applying a format string. This is equivalent to log.Logger.Printf. Printf(format string, values ...interface{}) }
BaseLogger is a generic logger interface with no level mechanism. Since its methods are a subset of Go's log.Logger, you may use log.New() to create a BaseLogger.
This is identical to the Logger interface in the main SDK package. It is redefined here so the ldlog package does not have to refer back to the main package.
type LogLevel ¶
type LogLevel int
LogLevel describes one of the possible thresholds of log message, from LogDebug to LogError.
const ( // Debug is the least significant logging level, containing verbose output you will normally // not need to see. This level is disabled by default. Debug LogLevel = iota // Info is the logging level for informational messages about normal operations. This level // is enabled by default. Info LogLevel = iota // Warn is the logging level for more significant messages about an uncommon condition that // is not necessarily an error. This level is enabled by default. Warn LogLevel = iota // Error is the logging level for error conditions that should not happen during normal // operation of the SDK. This level is enabled by default. Error LogLevel = iota // None means no messages at all should be logged. None LogLevel = iota )
type Loggers ¶
type Loggers struct {
// contains filtered or unexported fields
}
Loggers is a configurable logging component with a level filter.
By default, Loggers sends output to standard error and enables all levels except Debug. You may call any of its Set methods to change this configuration.
func NewDefaultLoggers ¶
func NewDefaultLoggers() Loggers
NewDefaultLoggers returns a new Loggers instance with default properties.
This is different from an empty Loggers{} instance in that the latter will not produce any output until you call either SetBaseLogger, SetMinLevel, or Init on it. Calling NewDefaultLoggers() ensures that the default minimum level of Info is enabled.
func (Loggers) Debug ¶
func (l Loggers) Debug(values ...interface{})
Debug logs a message at Debug level, if that level is enabled. It calls the BaseLogger's Println.
func (Loggers) Debugf ¶
Debugf logs a message at Debug level with a format string, if that level is enabled. It calls the BaseLogger's Printf.
func (Loggers) Error ¶
func (l Loggers) Error(values ...interface{})
Debug logs a message at Debug level, if that level is enabled. It calls the BaseLogger's Println.
func (Loggers) Errorf ¶
Errorf logs a message at Error level with a format string, if that level is enabled. It calls the BaseLogger's Printf.
func (Loggers) ForLevel ¶
func (l Loggers) ForLevel(level LogLevel) BaseLogger
ForLevel returns a BaseLogger that writes messages at the specified level. Use this if you have code that already uses the Printf/Println methods. All of the existing level configuration still applies, so, for instance, loggers.ForLevel(Debug).Println("x") is exactly the same as loggers.Debug("x").
If the level is not a valid log level, the return value is non-nil but will produce no output.
func (Loggers) Info ¶
func (l Loggers) Info(values ...interface{})
Info logs a message at Info level, if that level is enabled. It calls the BaseLogger's Println.
func (Loggers) Infof ¶
Infof logs a message at Info level with a format string, if that level is enabled. It calls the BaseLogger's Printf.
func (*Loggers) Init ¶
func (l *Loggers) Init()
Init ensures that the Loggers instance is ready to use.
This is necessary only if you have a Loggers instance that was not produced by NewDefaultLoggers and that may not have had SetBaseLogger or SetMinLevel called on it. It ensures that the default properties have been set. If you have already set any properties, Init does nothing.
func (*Loggers) SetBaseLogger ¶
func (l *Loggers) SetBaseLogger(baseLogger BaseLogger)
SetBaseLogger specifies the default destination for output at all log levels. This does not apply to any levels whose BaseLogger has been overridden with SetBaseLoggerForLevel. All messages written to this logger will be prefixed with "NAME: " where NAME is DEBUG, INFO, etc.
If baseLogger is nil, nothing is changed.
func (*Loggers) SetBaseLoggerForLevel ¶
func (l *Loggers) SetBaseLoggerForLevel(level LogLevel, baseLogger BaseLogger)
SetBaseLoggerForLevel specifies the default destination for output at the given log level. All messages written to this logger will be prefixed with "NAME: " where NAME is DEBUG, INFO, etc.
If baseLogger is nil, this level will use the default from SetBaseLogger.
func (*Loggers) SetMinLevel ¶
SetMinLevel specifies the minimum level for log output, where Debug is the lowest and Error is the highest. Log messages at a level lower than this will be suppressed. The default is Info.
func (*Loggers) SetPrefix ¶
SetPrefix specifies a string to be added before every log message, after the LEVEL: prefix. Do not include a trailing space.