lumber

package
v0.6.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 8, 2022 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Debug has verbose message
	Debug = "debug"
	// Info is default log level
	Info = "info"
	// Warn is for logging messages about possible issues
	Warn = "warn"
	// Error is for logging errors
	Error = "error"
	// Fatal is for logging fatal messages. The system shutsdown after logging the message.
	Fatal = "fatal"
)
View Source
const (
	InstanceZapLogger int = iota
	InstanceLogrusLogger
)

List of supported loggers.

Variables

This section is empty.

Functions

This section is empty.

Types

type Fields

type Fields map[string]interface{}

Fields Type to pass when we want to call WithFields for structured logging

type Logger

type Logger interface {
	// Debugf logs a message at level Debug on the standard logger.
	Debugf(format string, args ...interface{})
	// Infof logs a message at level Info on the standard logger.
	Infof(format string, args ...interface{})
	// Warnf logs a message at level Warn on the standard logger.
	Warnf(format string, args ...interface{})
	// Errorf logs a message at level Error on the standard logger.
	Errorf(format string, args ...interface{})
	// Fatalf logs a message at level Fatal on the standard logger then the process will exit with status set to 1.
	Fatalf(format string, args ...interface{})
	// Panicf logs a message at level Panic on the standard logger.
	Panicf(format string, args ...interface{})
	// WithField creates an entry from the standard logger and adds a field to
	// it. If you want multiple fields, use `WithFields`
	// Note that it doesn't log until you call Debug, Print, Info, Warn, Fatal
	// or Panic on the Entry it returns.
	WithFields(keyValues Fields) Logger
}

Logger is our contract for the logger

func NewLogger

func NewLogger(config LoggingConfig, verbose bool, loggerInstance int) (Logger, error)

NewLogger returns an instance of logger

type LoggingConfig

type LoggingConfig struct {
	EnableConsole     bool
	ConsoleJSONFormat bool
	ConsoleLevel      string
	EnableFile        bool
	FileJSONFormat    bool
	FileLevel         string
	FileLocation      string
}

LoggingConfig stores the config for the logger For some loggers there can only be one level across writers, for such the level of Console is picked by default

type Writer

type Writer struct {
	// Log specifies the logger to which the Writer will write messages.
	// The Writer will panic if Log is unspecified.
	Log Logger
	// contains filtered or unexported fields
}

Writer must be closed when finished to flush buffered data to the logger.

func NewWriter

func NewWriter(log Logger) *Writer

NewWriter returns a new Writer that writes to the provided Logger.

func (*Writer) Close

func (w *Writer) Close() error

Close closes the writer, flushing any buffered data in the process.

func (*Writer) Sync

func (w *Writer) Sync() error

Sync flushes buffered data to the logger as a new log entry even if it doesn't contain a newline.

func (*Writer) Write

func (w *Writer) Write(bs []byte) (n int, err error)

Write writes the provided bytes to the underlying logger at the configured log level and returns the length of the bytes.

Write will split the input on newlines and post each line as a new log entry to the logger.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL