go-server-sdk.v4: gopkg.in/launchdarkly/go-server-sdk.v4/ldlog Index | Files

package ldlog

import "gopkg.in/launchdarkly/go-server-sdk.v4/ldlog"

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

Package Files

logging.go

type BaseLogger Uses

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 Uses

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
)

func (LogLevel) Name Uses

func (level LogLevel) Name() string

Name returns a descriptive name for this log level.

func (LogLevel) String Uses

func (level LogLevel) String() string

String is the default string representation of LogLevel, which is the same as Name().

type Loggers Uses

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 Uses

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 Uses

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 Uses

func (l Loggers) Debugf(format string, values ...interface{})

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 Uses

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 Uses

func (l Loggers) Errorf(format string, values ...interface{})

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 Uses

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 Uses

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 Uses

func (l Loggers) Infof(format string, values ...interface{})

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 Uses

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 Uses

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 Uses

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 Uses

func (l *Loggers) SetMinLevel(minLevel LogLevel)

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 Uses

func (l *Loggers) SetPrefix(prefix string)

SetPrefix specifies a string to be added before every log message, after the LEVEL: prefix. Do not include a trailing space.

func (Loggers) Warn Uses

func (l Loggers) Warn(values ...interface{})

Warn logs a message at Warn level, if that level is enabled. It calls the BaseLogger's Println.

func (Loggers) Warnf Uses

func (l Loggers) Warnf(format string, values ...interface{})

Warnf logs a message at Warn level with a format string, if that level is enabled. It calls the BaseLogger's Printf.

Package ldlog imports 3 packages (graph) and is imported by 27 packages. Updated 2020-04-02. Refresh now. Tools for package owners.