Documentation ¶
Index ¶
- Constants
- func Debug(msg string, params ...interface{})
- func Error(msg string, params ...interface{})
- func Fatal(msg string, params ...interface{})
- func Info(msg string, params ...interface{})
- func SetFormatter(formatter Formatter)
- func SetLevel(level int)
- func SetOutput(stdout, stderr io.Writer)
- func Warn(msg string, params ...interface{})
- type DiscardFormatter
- type FieldFormatter
- type Fields
- type Formatter
- type Logger
- func (log *Logger) Debug(msg string, params ...interface{})
- func (log *Logger) Error(msg string, params ...interface{})
- func (log *Logger) Fatal(msg string, params ...interface{})
- func (log *Logger) GetFormatter() Formatter
- func (log *Logger) GetLevel() int
- func (log *Logger) GetOut(level int) io.Writer
- func (log *Logger) Info(msg string, params ...interface{})
- func (log *Logger) SetFormatter(formatter Formatter)
- func (log *Logger) SetLevel(level int)
- func (log *Logger) SetOut(level int, out io.Writer)
- func (log *Logger) Warn(msg string, params ...interface{})
- type NameSchema
- type RollingFileAppender
- type StandardFormatter
Constants ¶
const ( // LevelDebug log all messages. LevelDebug = iota // LevelInfo log info, warning and error messages. LevelInfo // LevelWarning log warning and error messages. LevelWarning // LevelError log error messages only. LevelError )
const ( // StandardTimeFormat is a synonym for time.RFC3339Nano. StandardTimeFormat = time.RFC3339Nano )
Variables ¶
This section is empty.
Functions ¶
func Fatal ¶
func Fatal(msg string, params ...interface{})
Fatal logs a formatted error message and panics.
func SetFormatter ¶
func SetFormatter(formatter Formatter)
SetFormatter sets the formatter of the default logger.
Types ¶
type DiscardFormatter ¶
type DiscardFormatter struct{}
DiscardFormatter drops all messages.
func NewDiscardFormatter ¶
func NewDiscardFormatter() *DiscardFormatter
NewDiscardFormatter creates a new DiscardFormatter.
func (*DiscardFormatter) Fmt ¶
func (formatter *DiscardFormatter) Fmt(buffer *[]byte, level int, t time.Time, msg string, params []interface{})
Fmt drops the message.
func (*DiscardFormatter) Pnc ¶
func (formatter *DiscardFormatter) Pnc(msg string, params []interface{})
Pnc formats the given message and panics.
type FieldFormatter ¶
type FieldFormatter struct {
// contains filtered or unexported fields
}
FieldFormatter adds fields to the output as key value pairs. The message won't be formatted. It prints log messages starting with the timestamp, followed by the log level, the message and key value pairs. To make this work the first and only parameter must be of type Fields.
Example:
logbuch.Debug("Hello World!", logbuch.Fields{"integer": 123, "string": "test"})
If there is more than one parameter or the type of the parameter is different, all parameters will be appended after the message.
func NewFieldFormatter ¶
func NewFieldFormatter(timeFormat, separator string) *FieldFormatter
NewFieldFormatter creates a new FieldFormatter with given timestamp format and separator between message and key value pairs. The timestamp can be disabled by passing an empty string.
func (*FieldFormatter) Fmt ¶
func (formatter *FieldFormatter) Fmt(buffer *[]byte, level int, t time.Time, msg string, params []interface{})
Fmt formats the message as described for the FieldFormatter.
func (*FieldFormatter) Pnc ¶
func (formatter *FieldFormatter) Pnc(msg string, params []interface{})
Pnc formats the given message and panics.
type Formatter ¶
type Formatter interface { // Fmt formats a logger message and writes the result into the buffer. Fmt(*[]byte, int, time.Time, string, []interface{}) // Pnc formats the given message and panics. Pnc(string, []interface{}) }
Formatter is an interface to format log messages.
type Logger ¶
type Logger struct { // PanicOnErr enables panics if the logger cannot write to log output. PanicOnErr bool // contains filtered or unexported fields }
Logger writes messages to different io.Writers depending on the log level by using a Formatter.
func (*Logger) GetFormatter ¶
GetFormatter returns the formatter.
func (*Logger) SetFormatter ¶
SetFormatter sets the formatter.
type NameSchema ¶
type NameSchema interface { // Name returns the next file name used to store log data. Name() string }
NameSchema is an interface to generate log file names. If you implement this interface, make sure the Name() method returns unique file names.
type RollingFileAppender ¶
type RollingFileAppender struct {
// contains filtered or unexported fields
}
RollingFileAppender is a manager for rolling log files. It needs to be closed using the Close() method.
func NewRollingFileAppender ¶
func NewRollingFileAppender(files, size, bufferSize int, dir string, filename NameSchema) (*RollingFileAppender, error)
NewRollingFileAppender creates a new RollingFileAppender. If you pass values below or equal to 0 for files, size or bufferSize, default values will be used. The file output directory is created if required and can be left empty to use the current directory. The filename schema is required. Note that the rolling file appender uses the filename schema you provide, so if it returns the same name on each call, it will overwrite the existing log file. The RollingFileAppender won't clean the log directory on startup. Old log files will stay in place.
func (*RollingFileAppender) Close ¶
func (appender *RollingFileAppender) Close() error
Close flushes the log data and closes all open file handlers.
func (*RollingFileAppender) Flush ¶
func (appender *RollingFileAppender) Flush() error
Flush writes all log data currently in buffer into the currently active log file.
type StandardFormatter ¶
type StandardFormatter struct {
// contains filtered or unexported fields
}
StandardFormatter is the default formatter. It prints log messages starting with the timestamp, followed by the log level and the formatted message.
func NewStandardFormatter ¶
func NewStandardFormatter(timeFormat string) *StandardFormatter
NewStandardFormatter creates a new StandardFormatter with given timestamp format. The timestamp can be disabled by passing an empty string.
func (*StandardFormatter) Fmt ¶
func (formatter *StandardFormatter) Fmt(buffer *[]byte, level int, t time.Time, msg string, params []interface{})
Fmt formats the message as described for the StandardFormatter.
func (*StandardFormatter) Pnc ¶
func (formatter *StandardFormatter) Pnc(msg string, params []interface{})
Pnc formats the given message and panics.