Config severity integers.
const ( LevelDebug = iota LevelInfo = iota LevelWarning = iota LevelError = iota )
Config severity names.
const ( LevelNameDebug = "debug" LevelNameInfo = "info" LevelNameWarning = "warning" LevelNameError = "error" )
Seveirty name->integer map.
var ( LevelNameMap = map[string]int{ LevelNameDebug: LevelDebug, LevelNameInfo: LevelInfo, LevelNameWarning: LevelWarning, LevelNameError: LevelError, } LevelNameMapR = map[int]string{ LevelDebug: LevelNameDebug, LevelInfo: LevelNameInfo, LevelWarning: LevelNameWarning, LevelError: LevelNameError, } )
Errors
var ( ErrAdapterAlreadyRegistered = e.New("adapter already registered") ErrFormatEmpty = e.New("format is empty") ErrExcludeLevelNameInvalid = e.New("exclude bypass-level is invalid") ErrNoAdapterConfigured = e.New("no default adapter configured") ErrAdapterIsNil = e.New("adapter is nil") ErrConfigurationNotLoaded = e.New("can not configure because configuration is not loaded") )
func AddAdapter(name string, la LogAdapter)
func AddExcludeFilter(noun string)
Add global exclude filter.
func AddIncludeFilter(noun string)
Add global include filter.
func ClearAdapters()
func Errorf(message string, args ...interface{}) *errors.Error
func GetDefaultAdapterName() string
Return the current default adapter name.
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
func LoadConfiguration(cp ConfigurationProvider)
func Panic(err interface{})
func PanicIf(err interface{})
func Panicf(message string, args ...interface{})
func PrintError(err error)
Print 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)
Remove global exclude filter.
func RemoveIncludeFilter(noun string)
Remove global include filter.
func SetDefaultAdapterName(name string)
The adapter will automatically be the first one registered. This overrides that.
func Wrap(err interface{}) *errors.Error
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() string // 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() string }
type ConsoleLogAdapter struct { }
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
Environment configuration-provider.
type EnvironmentConfigurationProvider struct { }
func NewEnvironmentConfigurationProvider() *EnvironmentConfigurationProvider
func (ecp *EnvironmentConfigurationProvider) DefaultAdapterName() string
func (ecp *EnvironmentConfigurationProvider) ExcludeBypassLevelName() string
func (ecp *EnvironmentConfigurationProvider) ExcludeNouns() string
func (ecp *EnvironmentConfigurationProvider) Format() string
func (ecp *EnvironmentConfigurationProvider) IncludeNouns() string
func (ecp *EnvironmentConfigurationProvider) LevelName() string
type LogAdapter interface { Debugf(lc *LogContext, message *string) error Infof(lc *LogContext, message *string) error Warningf(lc *LogContext, message *string) error Errorf(lc *LogContext, message *string) error }
func NewConsoleLogAdapter() LogAdapter
type LogContext struct { Logger *Logger Ctx context.Context }
type LogMethod func(lc *LogContext, message *string) error
type Logger struct {
// contains filtered or unexported fields
}
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{})
TODO(dustin): !! Also populate whether we've bypassed an exception so that
we can add a template macro to prefix an exclamation of some sort.
type MessageContext struct { Level *string Noun *string Message *string ExcludeBypass bool }
Static configuration-provider.
type StaticConfigurationProvider struct {
// contains filtered or unexported fields
}
func NewStaticConfigurationProvider() *StaticConfigurationProvider
func (scp *StaticConfigurationProvider) DefaultAdapterName() string
func (scp *StaticConfigurationProvider) ExcludeBypassLevelName() string
func (scp *StaticConfigurationProvider) ExcludeNouns() string
func (scp *StaticConfigurationProvider) Format() string
func (scp *StaticConfigurationProvider) IncludeNouns() string
func (scp *StaticConfigurationProvider) LevelName() string
func (scp *StaticConfigurationProvider) SetDefaultAdapterName(adapterName string)
func (scp *StaticConfigurationProvider) SetExcludeBypassLevelName(excludeBypassLevelName string)
func (scp *StaticConfigurationProvider) SetExcludeNouns(excludeNouns string)
func (scp *StaticConfigurationProvider) SetFormat(format string)
func (scp *StaticConfigurationProvider) SetIncludeNouns(includeNouns string)
func (scp *StaticConfigurationProvider) SetLevelName(levelName string)