Documentation ¶
Index ¶
- Variables
- func DefaultLogHandler(msg LogMessage)
- type Formatter
- type LeveledLogHandler
- type LogConfig
- type LogHandler
- type LogLevel
- type LogMessage
- type Logger
- func (logger *Logger) ChildLogger(name string) *Logger
- func (logger *Logger) Debug(format string, args ...interface{})
- func (logger *Logger) Error(format string, args ...interface{})
- func (logger *Logger) Info(format string, args ...interface{})
- func (logger *Logger) Label() string
- func (logger *Logger) Level() LogLevel
- func (logger *Logger) PackageLogger(opts ...PackageLoggerOpts) *Logger
- func (logger *Logger) Trace(format string, args ...interface{})
- func (logger *Logger) Warn(format string, args ...interface{})
- type PackageLoggerOpts
- type RootLogConfig
Constants ¶
This section is empty.
Variables ¶
var LogLevels orderedLogLevels
Functions ¶
func DefaultLogHandler ¶
func DefaultLogHandler(msg LogMessage)
DefaultLogHandler is a LogHandler that writes color coded log messages to stdout with UTC timestamps.
Types ¶
type LeveledLogHandler ¶
func (*LeveledLogHandler) LogHandler ¶
func (h *LeveledLogHandler) LogHandler(msg LogMessage)
type LogHandler ¶
type LogHandler func(LogMessage)
LogHandler receives a LogMessage and ensures it is properly written to the logs. Most consumers of this package will want to use the DefaultLogHandler to write color coded log messages to stdout with timestamps.
type LogLevel ¶
type LogLevel int
Log Constants NotSet is literally our "zero value" NOTE: go does _not_ recommend using ALL_CAPS for constants, as these would always be exported (see https://stackoverflow.com/questions/22688906/go-naming-conventions-for-const)
func (*LogLevel) UnmarshalJSON ¶
type LogMessage ¶
LogMessage structs will be passed by the logger to the configured LogHandler each time a logging function (`.Trace()`, `.Debug()`,`.Info()`,`.Warn()`, `.Error()`) is called.
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger is the primary structure in this package. It supplies the log level functions. A Logger only has a `parent` if it was created by Logger.ChildLogger(). If so, it's `logConfig` will be a reference to it's config from the parent - the only place it can get a config.
func (*Logger) ChildLogger ¶
ChildLogger returns a Logger that takes it's configuration from the Logger it was created from. ChildLogger's are named so that configuration can be applied specifically to them. The name of a ChildLogger is also used in it's label along with it's parent's label.
func (*Logger) Level ¶
Level returns the effective log level of the Logger below which log messages will be ignored
func (*Logger) PackageLogger ¶
func (logger *Logger) PackageLogger(opts ...PackageLoggerOpts) *Logger
PackageLogger returns a ChildLogger using the basename of the package path of the caller as the name. This allows targetting a package logger in configuration by package name. It is recommended that PackageLogger() only be used when initializing a package. NOTE: the basename of the package path is more readily available at runtime than the actual package name (see https://golang.org/pkg/runtime/#example_Frames), but for well-named packages (see https://blog.golang.org/package-names) should be the same.
type PackageLoggerOpts ¶
type PackageLoggerOpts struct {
Skip int
}
PackageLoggerOpts allows callers of PackageLogger() to specify options. Currently the only supportted option is Skip, which tells PackageLogger() to skip additional stack frames that shouldn't be included when determining the calling package path.
type RootLogConfig ¶
type RootLogConfig struct { Loggers map[string]*LogConfig `json:"loggers"` Level LogLevel `json:"level"` Label string `json:"label"` // Don't try to Marshall/Unmarshall a function LogHandler LogHandler `json:"-"` }
func EnvPrefixConfig ¶
func EnvPrefixConfig(prefix string) (*RootLogConfig, error)
EnvPrefixConfig finds all the environment variables that start with a specified prefix and uses them to build a RootLogConfig. After the prefix, a single underscore ("_") is treated as a word seperator. Two successive underscores ("__") are treated as a struct seperator - the left side is the parent struct, the right is a field name.
func FileConfig ¶
func FileConfig(configFile string) (*RootLogConfig, error)
FileConfig reads a file path and creates a RootLogConfig from it's JSON data
func JsonConfig ¶
func JsonConfig(data []byte) (*RootLogConfig, error)
JsonConfig creates a RootLogConfig from JSON data
func PathEnvConfig ¶
func PathEnvConfig(env string) (*RootLogConfig, error)
PathEnvConfig gets a file path from the specified environment variable, reads it's contents and creates a RootLogConfig from it's JSON data