Documentation
¶
Overview ¶
Package gomolconsole implements a console logger for gomol.
Example ¶
Code for the README example to make sure it still builds!
// Add an io.Writer logger
consoleCfg := NewConsoleLoggerConfig()
consoleLogger, _ := NewConsoleLogger(consoleCfg)
gomol.AddLogger(consoleLogger)
// Set some global attrs that will be added to all
// messages automatically
gomol.SetAttr("facility", "gomol.example")
gomol.SetAttr("another_attr", 1234)
// Initialize the loggers
gomol.InitLoggers()
defer gomol.ShutdownLoggers()
// Log some debug messages with message-level attrs
// that will be sent only with that message
for idx := 1; idx <= 10; idx++ {
gomol.Dbgm(
gomol.NewAttrs().
SetAttr("msg_attr1", 4321),
"Test message %v", idx)
}
Index ¶
- func NewTemplateDefault() *gomol.Template
- func NewTemplateFull() *gomol.Template
- func NewTemplateTimestamped() *gomol.Template
- type ConsoleLogger
- func (l *ConsoleLogger) InitLogger() error
- func (l *ConsoleLogger) IsInitialized() bool
- func (l *ConsoleLogger) Logm(timestamp time.Time, level gomol.LogLevel, attrs map[string]interface{}, ...) error
- func (l *ConsoleLogger) SetBase(base *gomol.Base)
- func (l *ConsoleLogger) SetTemplate(tpl *gomol.Template) error
- func (l *ConsoleLogger) ShutdownLogger() error
- type ConsoleLoggerConfig
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewTemplateDefault ¶
NewTemplateDefault will create a new default logging template.
Example output:
[INFO] This is my message
func NewTemplateFull ¶
NewTemplateFull will create a new logging template including the current timestamp as well as any attributes included with the message.
Example output:
2006-01-02 15:04:05.000 [INFO] This is my message attr1: 1234 attr2: value2
func NewTemplateTimestamped ¶
NewTemplateTimestamped will create a new logging template including the current timestamp.
Example output:
2006-01-02 15:04:05.000 [INFO] This is my message
Types ¶
type ConsoleLogger ¶
type ConsoleLogger struct {
// contains filtered or unexported fields
}
func NewConsoleLogger ¶
func NewConsoleLogger(config *ConsoleLoggerConfig) (*ConsoleLogger, error)
func (*ConsoleLogger) InitLogger ¶
func (l *ConsoleLogger) InitLogger() error
func (*ConsoleLogger) IsInitialized ¶
func (l *ConsoleLogger) IsInitialized() bool
func (*ConsoleLogger) SetBase ¶
func (l *ConsoleLogger) SetBase(base *gomol.Base)
func (*ConsoleLogger) SetTemplate ¶
func (l *ConsoleLogger) SetTemplate(tpl *gomol.Template) error
func (*ConsoleLogger) ShutdownLogger ¶
func (l *ConsoleLogger) ShutdownLogger() error
type ConsoleLoggerConfig ¶
type ConsoleLoggerConfig struct {
// Colorize specifies whether the output will include ANSI colors or not. Defaults to true
Colorize bool
// Writer is the io.Writer to be used if not overridden in other options. Defaults to os.Stdout
Writer io.Writer
// DebugWriter is the io.Writer debug messages will be written to. Defaults to Writer
DebugWriter io.Writer
// InfoWriter is the io.Writer info messages will be written to. Defaults to Writer
InfoWriter io.Writer
// WarningWriter is the io.Writer warning messages will be written to. Defaults to Writer
WarningWriter io.Writer
// ErrorWriter is the io.Writer error messages will be written to. Defaults to Writer
ErrorWriter io.Writer
// FatalWriter is the io.Writer fatal messages will be written to. Defaults to Writer
FatalWriter io.Writer
}
func NewConsoleLoggerConfig ¶
func NewConsoleLoggerConfig() *ConsoleLoggerConfig