log

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: May 13, 2020 License: Apache-2.0, Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DATEFORMAT         = "20060102150405"
	DATETIMEFORMAT     = "[2006-01-02 15:04:05.000]"
	TIMEZONEFORMAT     = "-07"
	DEFAULT_FILE_COUNT = 10
	DEFAULT_FILE_SIZE  = 20 * 1024 * 1024 //20MB
)

Variables

This section is empty.

Functions

func GetGID

func GetGID() string

func NewSyncWriter

func NewSyncWriter(w io.Writer) io.Writer

NewSyncWriter returns a new writer that is safe for concurrent use by multiple goroutines. Writes to the returned writer are passed on to w. If another write is already in progress, the calling goroutine blocks until the writer is available.

If w implements the following interface, so does the returned writer.

interface {
    Fd() uintptr
}

func NewTMFmtLogger

func NewTMFmtLogger(w io.Writer) kitlog.Logger

NewTMFmtLogger returns a logger that encodes keyvals to the Writer in Tendermint custom format. Note complex types (structs, maps, slices) formatted as "%+v".

Each log event produces no more than one call to w.Write. The passed Writer must be safe for concurrent use by multiple goroutines if the returned Logger will be used concurrently.

Types

type Logger

type Logger interface {
	Trace(msg string, keyvals ...interface{})
	Debug(msg string, keyvals ...interface{})
	Info(msg string, keyvals ...interface{})
	Warn(msg string, keyvals ...interface{})
	Error(msg string, keyvals ...interface{})
	Fatal(msg string, keyvals ...interface{})

	With(keyvals ...interface{}) Logger

	Flush()
}

Logger is what any Tendermint library should take.

func NewFileFilter

func NewFileFilter(file string, lvl string, next Logger, options ...Option) Logger

NewFileFilter wraps next and implements filtering. See the commentary on the Option functions for a detailed description of how to configure levels. If no options are provided, all leveled log events created with Debug, Info or Error helper methods are squelched.

func NewFilter

func NewFilter(next Logger, options ...Option) Logger

NewFilter wraps next and implements filtering. See the commentary on the Option functions for a detailed description of how to configure levels. If no options are provided, all leveled log events created with Debug, Info or Error helper methods are squelched.

func NewNopLogger

func NewNopLogger() Logger

NewNopLogger returns a logger that doesn't do anything.

func NewOldTMLogger

func NewOldTMLogger(w io.Writer) Logger

NewTMTermLogger returns a logger that encodes msg and keyvals to the Writer using go-kit's log as an underlying logger and our custom formatter. Note that underlying logger could be swapped with something else.

func NewOldTMLoggerWithColorFn

func NewOldTMLoggerWithColorFn(w io.Writer, colorFn func(keyvals ...interface{}) term.FgBgColor) Logger

NewOldTMLoggerWithColorFn allows you to provide your own color function. See NewOldTMLogger for documentation.

func NewTMJSONLogger

func NewTMJSONLogger(w io.Writer) Logger

NewTMJSONLogger returns a Logger that encodes keyvals to the Writer as a single JSON object. Each log event produces no more than one call to w.Write. The passed Writer must be safe for concurrent use by multiple goroutines if the returned Logger will be used concurrently.

func NewTracingLogger

func NewTracingLogger(next Logger) Logger

NewTracingLogger enables tracing by wrapping all errors (if they implement stackTracer interface) in tracedError.

All errors returned by https://github.com/pkg/errors implement stackTracer interface.

For debugging purposes only as it doubles the amount of allocations.

func TestingLogger

func TestingLogger() Logger

TestingLogger returns a TMLogger which writes to STDOUT if testing being run with the verbose (-v) flag, NopLogger otherwise.

Note that the call to TestingLogger() must be made inside a test (not in the init func) because verbose flag only set at the time of testing.

func TestingLoggerWithColorFn

func TestingLoggerWithColorFn(colorFn func(keyvals ...interface{}) term.FgBgColor) Logger

TestingLoggerWithColorFn allow you to provide your own color function. See TestingLogger for documentation.

type Loggerf

type Loggerf interface {
	Logger

	Tracef(fmtStr string, vals ...interface{})
	Debugf(fmtStr string, vals ...interface{})
	Infof(fmtStr string, vals ...interface{})
	Warnf(fmtStr string, vals ...interface{})
	Errorf(fmtStr string, vals ...interface{})
	Fatalf(fmtStr string, vals ...interface{})

	AllowLevel(lvl string)
	SetOutputToFile(isToFile bool)
	SetOutputToScreen(isToScreen bool)
	SetOutputAsync(isAsync bool)
	SetOutputFileSize(maxFileSize int)
	SetWithThreadID(with bool)
}

func NewTMLogger

func NewTMLogger(path, module string) Loggerf

NewTMLogger returns a logger that encodes msg and keyvals to the Writer Note that underlying logger could be swapped with something else.

type Option

type Option func(*filter)

Option sets a parameter for the filter.

func AllowAll

func AllowAll() Option

AllowAll is an alias for AllowDebug.

func AllowDebug

func AllowDebug() Option

AllowDebug allows fatal, error, info and debug level log events to pass.

func AllowDebugWith

func AllowDebugWith(key interface{}, value interface{}) Option

AllowDebugWith allows error, info and debug level log events to pass for a specific key value pair.

func AllowError

func AllowError() Option

AllowError allows fatal and error level log events to pass.

func AllowErrorWith

func AllowErrorWith(key interface{}, value interface{}) Option

AllowErrorWith allows only error level log events to pass for a specific key value pair.

func AllowFatal

func AllowFatal() Option

AllowFatal allows only fatal level log events to pass.

func AllowInfo

func AllowInfo() Option

AllowInfo allows fatal, error and info level log events to pass.

func AllowInfoWith

func AllowInfoWith(key interface{}, value interface{}) Option

AllowInfoWith allows error, warn and info level log events to pass for a specific key value pair.

func AllowLevel

func AllowLevel(lvl string) (Option, error)

AllowLevel returns an option for the given level or error if no option exist for such level.

func AllowNone

func AllowNone() Option

AllowNone allows no leveled log events to pass.

func AllowNoneWith

func AllowNoneWith(key interface{}, value interface{}) Option

AllowNoneWith allows no leveled log events to pass for a specific key value pair.

func AllowTrace

func AllowTrace() Option

AllowTrace allows fatal, error, info, debug and trace level log events to pass.

func AllowWarn

func AllowWarn() Option

AllowWarn allows fatal, error and warn level log events to pass.

func AllowWarnWith

func AllowWarnWith(key interface{}, value interface{}) Option

AllowWarnWith allows error and warn level log events to pass for a specific key value pair.

Jump to

Keyboard shortcuts

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