log

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2018 License: MIT Imports: 4 Imported by: 1

Documentation

Overview

Package log provides logging mechanism including replaceable Logger interface and its default implementation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

func Debug(args ...interface{})

Debug outputs given arguments via pre-set Logger implementation. Logging level must be set to DebugLevel via logger.SetOutputLevel

func Debugf

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

Debugf outputs given arguments with format via pre-set Logger implementation. Logging level must be set to DebugLevel via logger.SetOutputLevel

func Error

func Error(args ...interface{})

Error outputs given arguments via pre-set Logger implementation.

func Errorf

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

Errorf outputs given arguments with format via pre-set Logger implementation.

func Info

func Info(args ...interface{})

Info outputs given arguments via pre-set Logger implementation. Logging level must be set to DebugLevel or InfoLevel via logger.SetOutputLevel

func Infof

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

Infof outputs given arguments with format via pre-set Logger implementation. Logging level must be set to DebugLevel or InfoLevel via logger.SetOutputLevel

func SetLogger

func SetLogger(l Logger)

SetLogger receives struct that satisfies Logger interface, and set this as logger. From this call forward, any call to logging method proxies arguments to corresponding logging method of given Logger. e.g. call to log.Info points to Logger.Info.

This method is "thread-safe."

func SetOutputLevel

func SetOutputLevel(level Level)

SetOutputLevel sets what logging level to output. Application may call logging method any time, but Logger only outputs if the corresponding log level is equal to or higher than the level set here.

func Warn

func Warn(args ...interface{})

Warn outputs given arguments via pre-set Logger implementation. Logging level must be set to DebugLevel, InfoLevel or WarnLevel via logger.SetOutputLevel

func Warnf

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

Warnf outputs given arguments with format via pre-set Logger implementation. Logging level must be set to DebugLevel, InfoLevel or WarnLevel via logger.SetOutputLevel

Types

type Level

type Level uint

Level indicates what logging level the output is representing. This typically indicates the severity of particular logging event.

const (
	// ErrorLevel indicates the error state of events. This must be noted and be fixed.
	// In practical situation, fix may include lowering of the log level.
	ErrorLevel Level = iota

	// WarnLevel represents those events that are not critical, but deserves to note.
	WarnLevel

	// InfoLevel is used to inform what is happening inside the application.
	InfoLevel

	// DebugLevel indicates the output is logged for debugging purpose.
	DebugLevel
)

func (Level) String

func (level Level) String() string

String returns the stringified representation of log level.

type Logger

type Logger interface {
	Debug(args ...interface{})
	Debugf(format string, args ...interface{})

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

	Warn(args ...interface{})
	Warnf(format string, args ...interface{})

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

Logger defines the interface that can be used as logging tool in this application. Developer may provide a customized logger via SetLogger to modify behavior. By default, instance of defaultLogger is set as default Logger just like http's DefaultClient.

func NewWithStandardLogger

func NewWithStandardLogger(l *log.Logger) Logger

NewWithStandardLogger creates an instance of defaultLogger with Go's standard log.Logger. This can be used when implementing Logger interface is too much of a task, but still a bit of modification to defaultLogger is required.

Returning Logger can be fed to SetLogger to replace old defaultLogger.

Jump to

Keyboard shortcuts

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