log

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2019 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultConsoleLevel     = "crit"
	DefaultFileLevel        = "debug"
	DefaultFileSizeMiB      = 50
	DefaultFileMaxAgeDays   = 7
	DefaultFileMaxBackups   = 10
	DefaultFileFlushSeconds = 5
)
View Source
const (
	LvlCrit  = Lvl(log15.LvlCrit)
	LvlError = Lvl(log15.LvlError)
	LvlWarn  = Lvl(log15.LvlWarn)
	LvlInfo  = Lvl(log15.LvlInfo)
	LvlDebug = Lvl(log15.LvlDebug)
)
View Source
const (
	LvlTraceStr = "trace"
	// TraceMsgPrefix is prepended to TRACE level logging messages.
	TraceMsgPrefix = "[TRACE] "
)

Variables

View Source
var (
	ConsoleLevel = DefaultConsoleLevel
)

Functions

func AddLogConsFlags

func AddLogConsFlags()

func AddLogFileFlags

func AddLogFileFlags()

func Crit

func Crit(msg string, ctx ...interface{})

func CtxWith added in v0.4.0

func CtxWith(ctx context.Context, logger Logger) context.Context

CtxWith returns a new context, based on ctx, that embeds argument logger. The logger can be recovered using GetLogger. Attaching a logger to a context which already contains one will overwrite the existing value.

func Debug

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

func Error

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

func FilterTraceHandler added in v0.4.0

func FilterTraceHandler(handler log15.Handler) log15.Handler

func Flush

func Flush()

func Info

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

func Log added in v0.1.1

func Log(lvl Lvl, msg string, ctx ...interface{})

func LogPanicAndExit

func LogPanicAndExit()

func RandId

func RandId(idlen int) string

func SetupFromFlags

func SetupFromFlags(name string) error

func SetupLogConsole

func SetupLogConsole(logLevel string) error

SetupLogConsole sets up logging on default stderr. logLevel can be one of trace, debug, info, warn, error, and crit, and states the minimum level of logging events that gets printed to the console.

func SetupLogFile

func SetupLogFile(name string, logDir string, logLevel string, logSize int, logAge int,
	logBackups int, logFlush int) error

SetupLogFile initializes a file for logging. The path is logDir/name.log if name doesn't already contain the .log extension, or logDir/name otherwise. logLevel can be one of trace, debug, info, warn, error, and crit and states the minimum level of logging events that get written to the file. logSize is the maximum size, in MiB, until the log rotates. logAge is the maximum number of days to retain old log files. logBackups is the maximum number of old log files to retain. If logFlush > 0, logging output is buffered, and flushed every logFlush seconds. If logFlush < 0: logging output is buffered, but must be manually flushed by calling Flush(). If logFlush = 0 logging output is unbuffered and Flush() is a no-op.

func Trace added in v0.4.0

func Trace(msg string, ctx ...interface{})

func Warn

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

Types

type Handler

type Handler interface {
	log15.Handler
}

func DiscardHandler

func DiscardHandler() Handler

type Logger

type Logger interface {
	New(ctx ...interface{}) Logger
	GetHandler() Handler
	SetHandler(h Handler)
	Trace(msg string, ctx ...interface{})
	Debug(msg string, ctx ...interface{})
	Info(msg string, ctx ...interface{})
	Warn(msg string, ctx ...interface{})
	Error(msg string, ctx ...interface{})
	Crit(msg string, ctx ...interface{})
}

func FromCtx added in v0.4.0

func FromCtx(ctx context.Context) Logger

FromCtx returns the logger embedded in ctx if one exists, or the root logger otherwise. FromCtx is guaranteed to never return nil.

func New

func New(ctx ...interface{}) Logger

func Root

func Root() Logger

type Lvl added in v0.1.1

type Lvl log15.Lvl

func LvlFromString added in v0.1.1

func LvlFromString(lvl string) (Lvl, error)

func (Lvl) String added in v0.1.1

func (l Lvl) String() string

Directories

Path Synopsis
Package mock_log is a generated GoMock package.
Package mock_log is a generated GoMock package.

Jump to

Keyboard shortcuts

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