log

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2022 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BlacklistFunctions

func BlacklistFunctions(names ...string)

BlacklistFunctions adds the provided function names to the global loggers debug output blacklist

func BlacklistPackages

func BlacklistPackages(names ...string)

BlacklistPackages adds the provided package names to the global loggers debug output blacklist

func ClearBlacklist

func ClearBlacklist()

ClearBlacklist removes all entries from the global loggers blacklist

func ClearOutputs

func ClearOutputs()

ClearOutputs removes all outputs from the global logger

func ClearWhitelist

func ClearWhitelist()

ClearWhitelist removes all entries from the global loggers whitelist

func Debug

func Debug(msg ...string)

Debug writes a debug message to the global log

func Debugf

func Debugf(format string, arguments ...interface{})

Debugf writes a formatted error message to the global log

func Error

func Error(msg ...string)

Error writes an error message to the global log

func Errorf

func Errorf(format string, arguments ...interface{})

Errorf writes a formatted error message to the global log

func Info

func Info(msg ...string)

Info writes an info message to the global log

func Infof

func Infof(format string, arguments ...interface{})

Infof writes a formatted error message to the global log

func SetDebugMode

func SetDebugMode(state bool)

SetDebugMode toggles if debug messages are written to the global loggers outputs

func SetFormattedOutputs

func SetFormattedOutputs(outputs map[io.Writer]Formatter)

SetFormattedOutputs adds the provided io.Writer to the output of the global logger using the provided formatter

func SetOutputs

func SetOutputs(output ...io.Writer)

SetOutputs adds the provided io.Writers to the output of the global logger using the global formatter

func WhitelistFunctions

func WhitelistFunctions(names ...string)

WhitelistFunctions adds the provided function names to the global loggers debug output whitelist

func WhitelistPackages

func WhitelistPackages(names ...string)

WhitelistPackages adds the provided package name to the global loggers debug output whitelist

func XDebug added in v1.0.1

func XDebug(msg ...string)

XDebug disables the Debug function

Types

type CSVFormatter added in v1.0.1

type CSVFormatter struct {
	ColorsDisabled    bool
	TimestampDisabled bool
	TimestampLayout   string
	Clock             clock.Clock
	CallerDisabled    bool
}

CSVFormatter formats the log to csv lines with timestamp, package, function, log level and message

func NewCSVFormatter added in v1.0.1

func NewCSVFormatter() *CSVFormatter

func (*CSVFormatter) Format added in v1.0.1

func (f *CSVFormatter) Format(level Level, msg string) string

type DefaultFormatter

type DefaultFormatter struct {
	ColorsDisabled    bool
	Colors            map[Level]color.Style
	TimestampDisabled bool
	TimestampLayout   string
	Clock             clock.Clock
	CallerDisabled    bool
}

DefaultFormatter formats log to human readable text with timestamp, caller and log level

func NewDefaultFormatter

func NewDefaultFormatter() (f *DefaultFormatter)

NewDefaultFormatter initializes a new DefaultFormatter

func (*DefaultFormatter) Format

func (f *DefaultFormatter) Format(level Level, msg string) (formattedMsg string)

Format formats a single log message

type Formatter

type Formatter interface {
	Format(level Level, msg string) (formattedMsg string)
}

The Formatter interface is used to implement custom formatters

type JSONFormatter

type JSONFormatter struct {
	ColorsDisabled    bool
	TimestampDisabled bool
	TimestampLayout   string
	Clock             clock.Clock
	CallerDisabled    bool
	PrettyPrint       bool
}

JSONFormatter formats log to json objects with timestamp, function, package and log level

func NewJSONFormatter

func NewJSONFormatter() *JSONFormatter

NewJSONFormatter initializes a new JSONFormatter

func (*JSONFormatter) Format

func (f *JSONFormatter) Format(level Level, msg string) string

Format formats a single log message

type Level

type Level int

The Level describes the severity of the log message

const (
	// DebugLevel is used for messages for the developer debugging the application
	DebugLevel Level = iota
	// InfoLevel is used for messages for the user running the application
	InfoLevel
	// ErrorLevel is used in case the application encountered an unhandleable error and will terminate after messaging
	ErrorLevel
)

func (Level) String

func (level Level) String() string

String returns the string name for a log level

type Logger

type Logger struct {
	// contains filtered or unexported fields
}

A Logger writes formatted messages to the set of outputs.

func NewDefaultLogger

func NewDefaultLogger() (logger *Logger)

NewDefaultLogger initializes a new logger configured to write its output to the stdout console using the default formatter

func NewLogger

func NewLogger() (logger *Logger)

NewLogger initializes a new empty logger with no outputs configured

func (*Logger) BlacklistFunctions

func (logger *Logger) BlacklistFunctions(names ...string)

BlacklistFunctions adds the provided function names to the loggers debug output blacklist

func (*Logger) BlacklistPackages

func (logger *Logger) BlacklistPackages(names ...string)

BlacklistPackages adds the provided package names to the loggers debug output blacklist

func (*Logger) ClearBlacklist

func (logger *Logger) ClearBlacklist()

ClearBlacklist removes all entries from the loggers blacklist

func (*Logger) ClearOutputs

func (logger *Logger) ClearOutputs()

ClearOutputs removes all set outputs from the logger

func (*Logger) ClearWhitelist

func (logger *Logger) ClearWhitelist()

ClearWhitelist removes all entries from the loggers whitelist

func (*Logger) Debug

func (logger *Logger) Debug(msg ...string)

Debug writes a debug message to the log

func (*Logger) Debugf

func (logger *Logger) Debugf(format string, arguments ...interface{})

Debugf writes a formatted debug message to the log

func (*Logger) Error

func (logger *Logger) Error(msg ...string)

Error writes an error message to the log

func (*Logger) Errorf

func (logger *Logger) Errorf(format string, arguments ...interface{})

Errorf writes a formatted error message to the log

func (*Logger) Info

func (logger *Logger) Info(msg ...string)

Info writes an info message to the log

func (*Logger) Infof

func (logger *Logger) Infof(format string, arguments ...interface{})

Infof writes a formatted info message to the log

func (*Logger) SetDebugMode

func (logger *Logger) SetDebugMode(state bool)

SetDebugMode toggles if debug messages are written to the loggers outputs

func (*Logger) SetFormattedOutputs

func (logger *Logger) SetFormattedOutputs(outputs map[io.Writer]Formatter)

SetFormattedOutputs adds the provided io.Writers to the loggers outputs with the provided custom formatters

func (*Logger) SetOutputs

func (logger *Logger) SetOutputs(outputs ...io.Writer)

SetOutputs adds the provided io.Writers to the loggers outputs using the default formatter

func (*Logger) WhitelistFunctions

func (logger *Logger) WhitelistFunctions(names ...string)

WhitelistFunctions adds the provided function names to the loggers debug output whitelist

func (*Logger) WhitelistPackages

func (logger *Logger) WhitelistPackages(names ...string)

WhitelistPackages adds the provided package name to the loggers debug output whitelist

func (*Logger) XDebug added in v1.0.1

func (logger *Logger) XDebug(msg ...string)

XDebug disables the Debug method

func (*Logger) XDebugf added in v1.0.1

func (logger *Logger) XDebugf(format string, arguments ...interface{})

XDebugf disables the Debugf method

type RawFormatter

type RawFormatter struct {
	ColorsDisabled bool
}

RawFormatter formats log to just the message

func NewRawFormatter

func NewRawFormatter() (f *RawFormatter)

NewRawFormatter initializes a new RawFormatter

func (*RawFormatter) Format

func (f *RawFormatter) Format(level Level, msg string) string

Format formats a single log message

Jump to

Keyboard shortcuts

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