log

package
v7.0.4+incompatible Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2020 License: MIT, Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Console = "console"
	Syslog  = "syslog"
	UDPLog  = "udplog"
)

Supported log types.

View Source
const (
	DefaultHost = "127.0.0.1"
	DefaultPort = 55647

	DefaultCategory = "go_logging"
)

Variables

This section is empty.

Functions

func Debugf

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

Debugf logs to the DEBUG log.

func Errorf

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

Errorf logs to the ERROR, WARN, and INFO logs.

func Infof

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

Infof logs to the INFO log.

func Init

func Init(l ...Logger)

Init initializes the logging package with the provided loggers.

func InitWithConfig

func InitWithConfig(configs ...Config) error

InitWithConfig instantiates loggers based on the provided configs and initializes the package with them.

func Logfmt

func Logfmt(callDepth int, sev Severity, format string, args ...interface{})

Logfmt logs a formatted message of the specified severity, marking it attributed to a function at the specified depth on the current goroutine stack.

func SetSeverity

func SetSeverity(sev Severity)

func Warningf

func Warningf(format string, args ...interface{})

Warningf logs to the WARN and INFO logs.

Types

type CallerInfo

type CallerInfo struct {
	FileName string
	FilePath string
	FuncName string
	LineNo   int
}

CallerInfo encapsulates information about a piece of code that called a certain log function, such as file name, line number, etc.

type Config

type Config struct {
	// Name is a logger's identificator used to instantiate a proper logger type
	// from a config.
	Name string

	// Severity indicates the minimum severity a logger will be logging messages at.
	Severity string
}

Config represents a configuration of an individual logger.

type LogWriter

type LogWriter interface {
	Infof(format string, args ...interface{})
	Warningf(format string, args ...interface{})
	Errorf(format string, args ...interface{})
}

func GetGlobalLogger

func GetGlobalLogger() LogWriter

type Logger

type Logger interface {
	// Writer returns logger's underlying io.Writer used to write log messages to.
	//
	// It may be, for example, the standard output for a console logger or a socket
	// connection for a UDP logger.
	//
	// Should return `nil` if the logger is not supposed to log at the specified severity.
	Writer(Severity) io.Writer

	// FormatMessage constructs and returns a final message that will go to the logger's
	// output channel.
	FormatMessage(Severity, *CallerInfo, string, ...interface{}) string

	// Sets a loggers current Severity level.
	SetSeverity(Severity)

	// Gets the current Severity level.
	GetSeverity() Severity
}

Logger is an interface that should be implemented by all loggers wishing to participate in the logger chain initialized by this package.

func NewConsoleLogger

func NewConsoleLogger(conf Config) (Logger, error)

func NewLogger

func NewLogger(config Config) (Logger, error)

NewLogger makes a proper logger from the given configuration.

func NewSysLogger

func NewSysLogger(conf Config) (Logger, error)

func NewUDPLogger

func NewUDPLogger(conf Config) (Logger, error)

type Severity

type Severity int32
const (
	SeverityDebug Severity = iota
	SeverityInfo
	SeverityWarning
	SeverityError
)

Supported severities.

func SeverityFromString

func SeverityFromString(s string) (Severity, error)

func (Severity) String

func (s Severity) String() string

Jump to

Keyboard shortcuts

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