logbuch: github.com/emvi/logbuch Index | Files

package logbuch

import "github.com/emvi/logbuch"

Index

Package Files

discard_formatter.go field_formatter.go formatter.go funcs.go logger.go rolling_file_appender.go standard_formatter.go

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
)

func Debug Uses

func Debug(msg string, params ...interface{})

Debug logs a formatted debug message.

func Error Uses

func Error(msg string, params ...interface{})

Error logs a formatted error message.

func Fatal Uses

func Fatal(msg string, params ...interface{})

Fatal logs a formatted error message and panics.

func Info Uses

func Info(msg string, params ...interface{})

Info logs a formatted info message.

func SetFormatter Uses

func SetFormatter(formatter Formatter)

SetFormatter sets the formatter of the default logger.

func SetLevel Uses

func SetLevel(level int)

SetLevel sets the logging level.

func SetOutput Uses

func SetOutput(stdout, stderr io.Writer)

SetOutput sets the output channels for the default logger. The first parameter is used for debug, info and warning levels. The second one for error level.

func Warn Uses

func Warn(msg string, params ...interface{})

Warn logs a formatted warning message.

type DiscardFormatter Uses

type DiscardFormatter struct{}

DiscardFormatter drops all messages.

func NewDiscardFormatter Uses

func NewDiscardFormatter() *DiscardFormatter

NewDiscardFormatter creates a new DiscardFormatter.

func (*DiscardFormatter) Fmt Uses

func (formatter *DiscardFormatter) Fmt(buffer *[]byte, level int, t time.Time, msg string, params []interface{})

Fmt drops the message.

func (*DiscardFormatter) Pnc Uses

func (formatter *DiscardFormatter) Pnc(msg string, params []interface{})

Pnc formats the given message and panics.

type FieldFormatter Uses

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 Uses

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 Uses

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 Uses

func (formatter *FieldFormatter) Pnc(msg string, params []interface{})

Pnc formats the given message and panics.

type Fields Uses

type Fields map[string]interface{}

Fields is used together with the FieldFormatter.

type Formatter Uses

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 Uses

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 NewLogger Uses

func NewLogger(stdout, stderr io.Writer) *Logger

NewLogger creates a new logger using the StandardFormatter for given io.Writers.

func (*Logger) Debug Uses

func (log *Logger) Debug(msg string, params ...interface{})

Debug logs a formatted debug message.

func (*Logger) Error Uses

func (log *Logger) Error(msg string, params ...interface{})

Error logs a formatted error message.

func (*Logger) Fatal Uses

func (log *Logger) Fatal(msg string, params ...interface{})

Fatal logs a formatted error message and panics.

func (*Logger) GetFormatter Uses

func (log *Logger) GetFormatter() Formatter

GetFormatter returns the formatter.

func (*Logger) GetLevel Uses

func (log *Logger) GetLevel() int

GetLevel returns the log level.

func (*Logger) GetOut Uses

func (log *Logger) GetOut(level int) io.Writer

GetOut returns the io.Writer for given level.

func (*Logger) Info Uses

func (log *Logger) Info(msg string, params ...interface{})

Info logs a formatted info message.

func (*Logger) SetFormatter Uses

func (log *Logger) SetFormatter(formatter Formatter)

SetFormatter sets the formatter.

func (*Logger) SetLevel Uses

func (log *Logger) SetLevel(level int)

SetLevel sets the log level.

func (*Logger) SetOut Uses

func (log *Logger) SetOut(level int, out io.Writer)

SetOut sets the io.Writer for given level.

func (*Logger) Warn Uses

func (log *Logger) Warn(msg string, params ...interface{})

Warn logs a formatted warning message.

type NameSchema Uses

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 Uses

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 Uses

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 Uses

func (appender *RollingFileAppender) Close() error

Close flushes the log data and closes all open file handlers.

func (*RollingFileAppender) Flush Uses

func (appender *RollingFileAppender) Flush() error

Flush writes all log data currently in buffer into the currently active log file.

func (*RollingFileAppender) Write Uses

func (appender *RollingFileAppender) Write(p []byte) (n int, err error)

Write writes given data to the rolling log files. This might not happen immediately as the RollingFileAppender uses a buffer. If you want the data to be persisted, call Flush().

type StandardFormatter Uses

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 Uses

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 Uses

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 Uses

func (formatter *StandardFormatter) Pnc(msg string, params []interface{})

Pnc formats the given message and panics.

Package logbuch imports 8 packages (graph). Updated 2020-11-13. Refresh now. Tools for package owners.