func AddAdapter(name string, la LogAdapter)
AddAdapter registers a new adapter.
func AddExcludeFilter(noun string)
AddExcludeFilter adds global exclude filter.
func AddIncludeFilter(noun string)
AddIncludeFilter adds global include filter.
func ClearAdapters()
ClearAdapters deregisters all adapters.
func Errorf(message string, args ...interface{}) *errors.Error
Errorf returns a stack-wrapped error with a string-substituted message.
func GetDefaultAdapterName() string
GetDefaultAdapterName returns the default adapter name. May be empty.
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() bool
IsConfigurationLoaded indicates whether a config has been loaded.
func LoadConfiguration(cp ConfigurationProvider)
LoadConfiguration loads the effective configuration.
func Panic(err interface{})
Panic panics with the error. Wrap if not already stack-wrapped.
func PanicIf(err interface{})
PanicIf panics if err is non-nil.
func Panicf(message string, args ...interface{})
Panicf panics a stack-wrapped error with a string-substituted message.
func PrintError(err error)
PrintError is a utility function to prevent the caller from having to import the third-party library.
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(noun string)
RemoveExcludeFilter removes global exclude filter.
func RemoveIncludeFilter(noun string)
RemoveIncludeFilter removes global include filter.
func SetDefaultAdapterName(name string)
SetDefaultAdapterName sets the default adapter. If not set, the first one registered will be used.
func Wrap(err interface{}) *errors.Error
Wrap returns a stack-wrapped error. If already stack-wrapped this is a no-op.
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 }
ConsoleLogAdapter prints logging to STDOUT.
type ConsoleLogAdapter struct { }
func (cla *ConsoleLogAdapter) Debugf(lc *LogContext, message *string) error
Debugf logs a debugging message.
func (cla *ConsoleLogAdapter) Errorf(lc *LogContext, message *string) error
Errorf logs an error message.
func (cla *ConsoleLogAdapter) Infof(lc *LogContext, message *string) error
Infof logs an info message.
func (cla *ConsoleLogAdapter) Warningf(lc *LogContext, message *string) error
Warningf logs a warning message.
EnvironmentConfigurationProvider configuration-provider.
type EnvironmentConfigurationProvider struct { }
func NewEnvironmentConfigurationProvider() *EnvironmentConfigurationProvider
NewEnvironmentConfigurationProvider returns a new EnvironmentConfigurationProvider.
func (ecp *EnvironmentConfigurationProvider) DefaultAdapterName() string
DefaultAdapterName returns the name of the default-adapter.
func (ecp *EnvironmentConfigurationProvider) ExcludeBypassLevelName() LogLevelName
ExcludeBypassLevelName returns the level, if any, of the current bypass level for the excluded nouns.
func (ecp *EnvironmentConfigurationProvider) ExcludeNouns() string
ExcludeNouns returns inlined set of effective exclude nouns.
func (ecp *EnvironmentConfigurationProvider) Format() string
Format returns the format string.
func (ecp *EnvironmentConfigurationProvider) IncludeNouns() string
IncludeNouns returns inlined set of effective include nouns.
func (ecp *EnvironmentConfigurationProvider) LevelName() LogLevelName
LevelName returns the current level-name.
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() LogAdapter
NewConsoleLogAdapter returns a new ConsoleLogAdapter.
LogContext encapsulates the current context for passing to the adapter.
type LogContext struct {
// contains filtered or unexported fields
}
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 )
LogLevelName describes the name of a log-level.
type LogLevelName string
Logger is the main logger type.
type Logger struct {
// contains filtered or unexported fields
}
func NewLogger(noun string) (l *Logger)
NewLogger returns a new logger struct.
func NewLoggerWithAdapterName(noun string, adapterName string) (l *Logger)
NewLoggerWithAdapterName initializes a logger struct to log to a specific adapter.
func (l *Logger) Adapter() LogAdapter
Adapter returns the adapter used by this logger struct.
func (l *Logger) Debugf(ctx context.Context, format string, args ...interface{})
Debugf forwards debug-logging to the underlying adapter.
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 (l *Logger) Errorf(ctx context.Context, errRaw interface{}, format string, args ...interface{})
Errorf forwards debug-logging to the underlying adapter.
func (l *Logger) Infof(ctx context.Context, format string, args ...interface{})
Infof forwards debug-logging to the underlying adapter.
func (l *Logger) Noun() string
Noun returns the noun that this logger represents.
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 (l *Logger) Panicf(ctx context.Context, errRaw interface{}, format string, args ...interface{})
Panicf logs a string-substituted message.
func (l *Logger) Warningf(ctx context.Context, format string, args ...interface{})
Warningf forwards debug-logging to the underlying adapter.
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 }
StaticConfigurationProvider configuration-provider.
type StaticConfigurationProvider struct {
// contains filtered or unexported fields
}
func NewStaticConfigurationProvider() *StaticConfigurationProvider
NewStaticConfigurationProvider returns a new StaticConfigurationProvider struct.
func (scp *StaticConfigurationProvider) DefaultAdapterName() string
DefaultAdapterName returns the name of the default-adapter.
func (scp *StaticConfigurationProvider) ExcludeBypassLevelName() LogLevelName
ExcludeBypassLevelName returns the level, if any, of the current bypass level for the excluded nouns.
func (scp *StaticConfigurationProvider) ExcludeNouns() string
ExcludeNouns returns inlined set of effective exclude nouns.
func (scp *StaticConfigurationProvider) Format() string
Format returns the format string.
func (scp *StaticConfigurationProvider) IncludeNouns() string
IncludeNouns returns inlined set of effective include nouns.
func (scp *StaticConfigurationProvider) LevelName() LogLevelName
LevelName returns the current level-name.
func (scp *StaticConfigurationProvider) SetDefaultAdapterName(adapterName string)
SetDefaultAdapterName sets the default adapter name.
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 (scp *StaticConfigurationProvider) SetExcludeNouns(excludeNouns string)
SetExcludeNouns sets an inlined set of nouns to exclude.
func (scp *StaticConfigurationProvider) SetFormat(format string)
SetFormat sets the message format/layout.
func (scp *StaticConfigurationProvider) SetIncludeNouns(includeNouns string)
SetIncludeNouns sets an inlined set of nouns to include.
func (scp *StaticConfigurationProvider) SetLevel(level LogLevel)
SetLevel sets the effective level (using the constant).
func (scp *StaticConfigurationProvider) SetLevelName(levelName LogLevelName)
SetLevelName sets the effective level (using the name).