...

Package log

import "github.com/dsoprea/go-logging/v2"
Overview
Index

Overview ▾

Index ▾

func AddAdapter(name string, la LogAdapter)
func AddExcludeFilter(noun string)
func AddIncludeFilter(noun string)
func ClearAdapters()
func Errorf(message string, args ...interface{}) *errors.Error
func GetDefaultAdapterName() string
func Is(actual, against error) bool
func IsConfigurationLoaded() bool
func LoadConfiguration(cp ConfigurationProvider)
func Panic(err interface{})
func PanicIf(err interface{})
func Panicf(message string, args ...interface{})
func PrintError(err error)
func PrintErrorf(err error, format string, args ...interface{})
func RemoveExcludeFilter(noun string)
func RemoveIncludeFilter(noun string)
func SetDefaultAdapterName(name string)
func Wrap(err interface{}) *errors.Error
type ConfigurationProvider
type ConsoleLogAdapter
    func (cla *ConsoleLogAdapter) Debugf(lc *LogContext, message *string) error
    func (cla *ConsoleLogAdapter) Errorf(lc *LogContext, message *string) error
    func (cla *ConsoleLogAdapter) Infof(lc *LogContext, message *string) error
    func (cla *ConsoleLogAdapter) Warningf(lc *LogContext, message *string) error
type EnvironmentConfigurationProvider
    func NewEnvironmentConfigurationProvider() *EnvironmentConfigurationProvider
    func (ecp *EnvironmentConfigurationProvider) DefaultAdapterName() string
    func (ecp *EnvironmentConfigurationProvider) ExcludeBypassLevelName() LogLevelName
    func (ecp *EnvironmentConfigurationProvider) ExcludeNouns() string
    func (ecp *EnvironmentConfigurationProvider) Format() string
    func (ecp *EnvironmentConfigurationProvider) IncludeNouns() string
    func (ecp *EnvironmentConfigurationProvider) LevelName() LogLevelName
type LogAdapter
    func NewConsoleLogAdapter() LogAdapter
type LogContext
type LogLevel
type LogLevelName
type Logger
    func NewLogger(noun string) (l *Logger)
    func NewLoggerWithAdapterName(noun string, adapterName string) (l *Logger)
    func (l *Logger) Adapter() LogAdapter
    func (l *Logger) Debugf(ctx context.Context, format string, args ...interface{})
    func (l *Logger) ErrorIff(ctx context.Context, errRaw interface{}, format string, args ...interface{})
    func (l *Logger) Errorf(ctx context.Context, errRaw interface{}, format string, args ...interface{})
    func (l *Logger) Infof(ctx context.Context, format string, args ...interface{})
    func (l *Logger) Noun() string
    func (l *Logger) PanicIff(ctx context.Context, errRaw interface{}, format string, args ...interface{})
    func (l *Logger) Panicf(ctx context.Context, errRaw interface{}, format string, args ...interface{})
    func (l *Logger) Warningf(ctx context.Context, format string, args ...interface{})
type MessageContext
type StaticConfigurationProvider
    func NewStaticConfigurationProvider() *StaticConfigurationProvider
    func (scp *StaticConfigurationProvider) DefaultAdapterName() string
    func (scp *StaticConfigurationProvider) ExcludeBypassLevelName() LogLevelName
    func (scp *StaticConfigurationProvider) ExcludeNouns() string
    func (scp *StaticConfigurationProvider) Format() string
    func (scp *StaticConfigurationProvider) IncludeNouns() string
    func (scp *StaticConfigurationProvider) LevelName() LogLevelName
    func (scp *StaticConfigurationProvider) SetDefaultAdapterName(adapterName string)
    func (scp *StaticConfigurationProvider) SetExcludeBypassLevelName(excludeBypassLevelName LogLevelName)
    func (scp *StaticConfigurationProvider) SetExcludeNouns(excludeNouns string)
    func (scp *StaticConfigurationProvider) SetFormat(format string)
    func (scp *StaticConfigurationProvider) SetIncludeNouns(includeNouns string)
    func (scp *StaticConfigurationProvider) SetLevel(level LogLevel)
    func (scp *StaticConfigurationProvider) SetLevelName(levelName LogLevelName)

Package files

config.go console_adapter.go log.go

func AddAdapter

func AddAdapter(name string, la LogAdapter)

AddAdapter registers a new adapter.

func AddExcludeFilter

func AddExcludeFilter(noun string)

AddExcludeFilter adds global exclude filter.

func AddIncludeFilter

func AddIncludeFilter(noun string)

AddIncludeFilter adds global include filter.

func ClearAdapters

func ClearAdapters()

ClearAdapters deregisters all adapters.

func Errorf

func Errorf(message string, args ...interface{}) *errors.Error

Errorf returns a stack-wrapped error with a string-substituted message.

func GetDefaultAdapterName

func GetDefaultAdapterName() string

GetDefaultAdapterName returns the default adapter name. May be empty.

func Is

func Is(actual, against error) bool

Is checks if the left ("actual") error equals the right ("against") error. The right must be an unwrapped error (the kind that you'd initialize as a global variable). The left can be a wrapped or unwrapped error.

func IsConfigurationLoaded

func IsConfigurationLoaded() bool

IsConfigurationLoaded indicates whether a config has been loaded.

func LoadConfiguration

func LoadConfiguration(cp ConfigurationProvider)

LoadConfiguration loads the effective configuration.

func Panic

func Panic(err interface{})

Panic panics with the error. Wrap if not already stack-wrapped.

func PanicIf

func PanicIf(err interface{})

PanicIf panics if err is non-nil.

func Panicf

func Panicf(message string, args ...interface{})

Panicf panics a stack-wrapped error with a string-substituted message.

func PrintError

func PrintError(err error)

PrintError is a utility function to prevent the caller from having to import the third-party library.

func PrintErrorf

func PrintErrorf(err error, format string, args ...interface{})

PrintErrorf is a utility function to prevent the caller from having to import the third-party library.

func RemoveExcludeFilter

func RemoveExcludeFilter(noun string)

RemoveExcludeFilter removes global exclude filter.

func RemoveIncludeFilter

func RemoveIncludeFilter(noun string)

RemoveIncludeFilter removes global include filter.

func SetDefaultAdapterName

func SetDefaultAdapterName(name string)

SetDefaultAdapterName sets the default adapter. If not set, the first one registered will be used.

func Wrap

func Wrap(err interface{}) *errors.Error

Wrap returns a stack-wrapped error. If already stack-wrapped this is a no-op.

type ConfigurationProvider

ConfigurationProvider describes minimal configuration implementation.

type ConfigurationProvider interface {
    // Alternative format (defaults to .
    Format() string

    // Alternative adapter (defaults to "appengine").
    DefaultAdapterName() string

    // Alternative level at which to display log-items (defaults to
    // "info").
    LevelName() LogLevelName

    // Configuration-driven comma-separated list of nouns to include. Defaults
    // to empty.
    IncludeNouns() string

    // Configuration-driven comma-separated list of nouns to exclude. Defaults
    // to empty.
    ExcludeNouns() string

    // Level at which to disregard exclusion (if the severity of a message
    // meets or exceed this, always display). Defaults to empty.
    ExcludeBypassLevelName() LogLevelName
}

type ConsoleLogAdapter

ConsoleLogAdapter prints logging to STDOUT.

type ConsoleLogAdapter struct {
}

func (*ConsoleLogAdapter) Debugf

func (cla *ConsoleLogAdapter) Debugf(lc *LogContext, message *string) error

Debugf logs a debugging message.

func (*ConsoleLogAdapter) Errorf

func (cla *ConsoleLogAdapter) Errorf(lc *LogContext, message *string) error

Errorf logs an error message.

func (*ConsoleLogAdapter) Infof

func (cla *ConsoleLogAdapter) Infof(lc *LogContext, message *string) error

Infof logs an info message.

func (*ConsoleLogAdapter) Warningf

func (cla *ConsoleLogAdapter) Warningf(lc *LogContext, message *string) error

Warningf logs a warning message.

type EnvironmentConfigurationProvider

EnvironmentConfigurationProvider configuration-provider.

type EnvironmentConfigurationProvider struct {
}

func NewEnvironmentConfigurationProvider

func NewEnvironmentConfigurationProvider() *EnvironmentConfigurationProvider

NewEnvironmentConfigurationProvider returns a new EnvironmentConfigurationProvider.

func (*EnvironmentConfigurationProvider) DefaultAdapterName

func (ecp *EnvironmentConfigurationProvider) DefaultAdapterName() string

DefaultAdapterName returns the name of the default-adapter.

func (*EnvironmentConfigurationProvider) ExcludeBypassLevelName

func (ecp *EnvironmentConfigurationProvider) ExcludeBypassLevelName() LogLevelName

ExcludeBypassLevelName returns the level, if any, of the current bypass level for the excluded nouns.

func (*EnvironmentConfigurationProvider) ExcludeNouns

func (ecp *EnvironmentConfigurationProvider) ExcludeNouns() string

ExcludeNouns returns inlined set of effective exclude nouns.

func (*EnvironmentConfigurationProvider) Format

func (ecp *EnvironmentConfigurationProvider) Format() string

Format returns the format string.

func (*EnvironmentConfigurationProvider) IncludeNouns

func (ecp *EnvironmentConfigurationProvider) IncludeNouns() string

IncludeNouns returns inlined set of effective include nouns.

func (*EnvironmentConfigurationProvider) LevelName

func (ecp *EnvironmentConfigurationProvider) LevelName() LogLevelName

LevelName returns the current level-name.

type LogAdapter

LogAdapter describes minimal log-adapter functionality.

type LogAdapter interface {
    // Debugf logs a debug message.
    Debugf(lc *LogContext, message *string) error

    // Infof logs an info message.
    Infof(lc *LogContext, message *string) error

    // Warningf logs a warning message.
    Warningf(lc *LogContext, message *string) error

    // Errorf logs an error message.
    Errorf(lc *LogContext, message *string) error
}

func NewConsoleLogAdapter

func NewConsoleLogAdapter() LogAdapter

NewConsoleLogAdapter returns a new ConsoleLogAdapter.

type LogContext

LogContext encapsulates the current context for passing to the adapter.

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

type LogLevel

LogLevel describes a log-level.

type LogLevel int

Config severity integers.

const (
    // LevelDebug exposes debug logging an above. This exposes all logging.
    LevelDebug LogLevel = iota

    // LevelInfo exposes info logging and above.
    LevelInfo LogLevel = iota

    // LevelWarning exposes warning logging and above.
    LevelWarning LogLevel = iota

    // LevelError exposes error logging and above. This is the most restrictive.
    LevelError LogLevel = iota
)

type LogLevelName

LogLevelName describes the name of a log-level.

type LogLevelName string

type Logger

Logger is the main logger type.

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

func NewLogger

func NewLogger(noun string) (l *Logger)

NewLogger returns a new logger struct.

func NewLoggerWithAdapterName

func NewLoggerWithAdapterName(noun string, adapterName string) (l *Logger)

NewLoggerWithAdapterName initializes a logger struct to log to a specific adapter.

func (*Logger) Adapter

func (l *Logger) Adapter() LogAdapter

Adapter returns the adapter used by this logger struct.

func (*Logger) Debugf

func (l *Logger) Debugf(ctx context.Context, format string, args ...interface{})

Debugf forwards debug-logging to the underlying adapter.

func (*Logger) ErrorIff

func (l *Logger) ErrorIff(ctx context.Context, errRaw interface{}, format string, args ...interface{})

ErrorIff logs a string-substituted message if errRaw is non-nil.

func (*Logger) Errorf

func (l *Logger) Errorf(ctx context.Context, errRaw interface{}, format string, args ...interface{})

Errorf forwards debug-logging to the underlying adapter.

func (*Logger) Infof

func (l *Logger) Infof(ctx context.Context, format string, args ...interface{})

Infof forwards debug-logging to the underlying adapter.

func (*Logger) Noun

func (l *Logger) Noun() string

Noun returns the noun that this logger represents.

func (*Logger) PanicIff

func (l *Logger) PanicIff(ctx context.Context, errRaw interface{}, format string, args ...interface{})

PanicIff panics with a string-substituted message if errRaw is non-nil.

func (*Logger) Panicf

func (l *Logger) Panicf(ctx context.Context, errRaw interface{}, format string, args ...interface{})

Panicf logs a string-substituted message.

func (*Logger) Warningf

func (l *Logger) Warningf(ctx context.Context, format string, args ...interface{})

Warningf forwards debug-logging to the underlying adapter.

type MessageContext

MessageContext describes the current logging context and can be used for substitution in a template string.

type MessageContext struct {
    Level         *LogLevelName
    Noun          *string
    Message       *string
    ExcludeBypass bool
}

type StaticConfigurationProvider

StaticConfigurationProvider configuration-provider.

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

func NewStaticConfigurationProvider

func NewStaticConfigurationProvider() *StaticConfigurationProvider

NewStaticConfigurationProvider returns a new StaticConfigurationProvider struct.

func (*StaticConfigurationProvider) DefaultAdapterName

func (scp *StaticConfigurationProvider) DefaultAdapterName() string

DefaultAdapterName returns the name of the default-adapter.

func (*StaticConfigurationProvider) ExcludeBypassLevelName

func (scp *StaticConfigurationProvider) ExcludeBypassLevelName() LogLevelName

ExcludeBypassLevelName returns the level, if any, of the current bypass level for the excluded nouns.

func (*StaticConfigurationProvider) ExcludeNouns

func (scp *StaticConfigurationProvider) ExcludeNouns() string

ExcludeNouns returns inlined set of effective exclude nouns.

func (*StaticConfigurationProvider) Format

func (scp *StaticConfigurationProvider) Format() string

Format returns the format string.

func (*StaticConfigurationProvider) IncludeNouns

func (scp *StaticConfigurationProvider) IncludeNouns() string

IncludeNouns returns inlined set of effective include nouns.

func (*StaticConfigurationProvider) LevelName

func (scp *StaticConfigurationProvider) LevelName() LogLevelName

LevelName returns the current level-name.

func (*StaticConfigurationProvider) SetDefaultAdapterName

func (scp *StaticConfigurationProvider) SetDefaultAdapterName(adapterName string)

SetDefaultAdapterName sets the default adapter name.

func (*StaticConfigurationProvider) SetExcludeBypassLevelName

func (scp *StaticConfigurationProvider) SetExcludeBypassLevelName(excludeBypassLevelName LogLevelName)

SetExcludeBypassLevelName sets a specific level to for the noun exclusions (e.g. hide them at/below INFO but show ERROR logging for everything).

func (*StaticConfigurationProvider) SetExcludeNouns

func (scp *StaticConfigurationProvider) SetExcludeNouns(excludeNouns string)

SetExcludeNouns sets an inlined set of nouns to exclude.

func (*StaticConfigurationProvider) SetFormat

func (scp *StaticConfigurationProvider) SetFormat(format string)

SetFormat sets the message format/layout.

func (*StaticConfigurationProvider) SetIncludeNouns

func (scp *StaticConfigurationProvider) SetIncludeNouns(includeNouns string)

SetIncludeNouns sets an inlined set of nouns to include.

func (*StaticConfigurationProvider) SetLevel

func (scp *StaticConfigurationProvider) SetLevel(level LogLevel)

SetLevel sets the effective level (using the constant).

func (*StaticConfigurationProvider) SetLevelName

func (scp *StaticConfigurationProvider) SetLevelName(levelName LogLevelName)

SetLevelName sets the effective level (using the name).