logger

package
v0.0.0-...-34cb6d9 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2024 License: BSD-3-Clause Imports: 19 Imported by: 525

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertRPCTagsToLogTags

func ConvertRPCTagsToLogTags(ctx context.Context) context.Context

ConvertRPCTagsToLogTags takes any RPC tags in the context and makes them log tags. It uses the string representation of the tag key, rather than the original uniquely typed key, since the latter isn't available in the RPC tags.

func EnableBufferedLogging

func EnableBufferedLogging()

EnableBufferedLogging turns on buffered logging - this is a performance boost at the expense of not getting all the logs in a crash.

func ErrorWriter

func ErrorWriter() io.Writer

func FileExists

func FileExists(path string) (bool, error)

func LogTagsFromContextRPC

func LogTagsFromContextRPC(ctx context.Context) (map[interface{}]string, bool)

LogTagsFromContextRPC is a wrapper around LogTagsFromContext that simply casts the result to the type expected by rpc.Connection.

func MakeParentDirs

func MakeParentDirs(filename string) error

func NewAutoFlushingBufferedWriter

func NewAutoFlushingBufferedWriter(baseWriter io.Writer,
	config *BufferedLoggerConfig) (w io.Writer, shutdown chan struct{}, done chan struct{})

NewAutoFlushingBufferedWriter returns an io.Writer that buffers its output and flushes automatically after `flushFrequency`.

func NewContextWithLogTags

func NewContextWithLogTags(
	ctx context.Context, logTagsToAdd CtxLogTags) context.Context

NewContext returns a new Context that carries adds the given log tag mappings (context key -> display string).

func OpenLogFile

func OpenLogFile(filename string) (name string, file *os.File, err error)

func OutputWriter

func OutputWriter() io.Writer

func RestoreConsoleMode

func RestoreConsoleMode()

RestoreConsoleMode restores the current text attributes from a global, in case nonstandard colors are expected. (Windows only)

func SaveConsoleMode

func SaveConsoleMode() error

SaveConsoleMode records the current text attributes in a global, so it can be restored later, in case nonstandard colors are expected. (Windows only)

func SetLogFileConfig

func SetLogFileConfig(lfc *LogFileConfig, blc *BufferedLoggerConfig) error

SetLogFileConfig sets the log file config to be used globally.

func Shutdown

func Shutdown()

Shutdown shuts down logger, flushing remaining logs if a backend with buffering is used.

Types

type BaseLogger

type BaseLogger interface {
	Debug(format string, args ...interface{})
	Info(format string, args ...interface{})
	Warning(format string, args ...interface{})
	Error(format string, args ...interface{})
}

type BufferedLoggerConfig

type BufferedLoggerConfig struct {
	Frequency time.Duration
	Size      int
}

type Context

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

func NewContext

func NewContext(c context.Context, l Logger) Context

func (Context) Critical

func (c Context) Critical(format string, arg ...interface{})

func (Context) Ctx

func (c Context) Ctx() context.Context

func (Context) Debug

func (c Context) Debug(format string, arg ...interface{})

func (Context) Error

func (c Context) Error(format string, arg ...interface{})

func (Context) Fatal

func (c Context) Fatal(format string, arg ...interface{})

func (Context) Info

func (c Context) Info(format string, arg ...interface{})

func (Context) Notice

func (c Context) Notice(format string, arg ...interface{})

func (Context) UpdateContextToLoggerContext

func (c Context) UpdateContextToLoggerContext(ctx context.Context) ContextInterface

func (Context) Warning

func (c Context) Warning(format string, arg ...interface{})

type ContextInterface

type ContextInterface interface {
	BaseLogger
	Ctx() context.Context
	UpdateContextToLoggerContext(context.Context) ContextInterface
}

type CtxLogTags

type CtxLogTags map[interface{}]string

func LogTagsFromContext

func LogTagsFromContext(ctx context.Context) (CtxLogTags, bool)

LogTagsFromContext returns the log tags being passed along with the given context.

type CtxStandardLoggerKey

type CtxStandardLoggerKey int

CtxStandardLoggerKey is a type defining context keys used by the Standard logger.

const (
	// CtxLogTagsKey defines a context key that can associate with a map of
	// context keys (key -> descriptive-name), the mapped values of which should
	// be logged by a Standard logger if one of those keys is seen in a context
	// during a log call.
	CtxLogTagsKey CtxStandardLoggerKey = iota
)

type ExternalHandler

type ExternalHandler interface {
	Log(level keybase1.LogLevel, format string, args []interface{})
}

type ExternalLogger

type ExternalLogger interface {
	Log(level keybase1.LogLevel, format string, args []interface{})
}

type InternalLogger

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

func NewInternalLogger

func NewInternalLogger(log *log.Logger) *InternalLogger

func (*InternalLogger) CCriticalf

func (l *InternalLogger) CCriticalf(ctx context.Context, fmt string,
	arg ...interface{})

func (*InternalLogger) CDebugf

func (l *InternalLogger) CDebugf(ctx context.Context, fmt string,
	arg ...interface{})

func (*InternalLogger) CErrorf

func (l *InternalLogger) CErrorf(ctx context.Context, fmt string,
	arg ...interface{})

func (*InternalLogger) CFatalf

func (l *InternalLogger) CFatalf(ctx context.Context, fmt string,
	arg ...interface{})

func (*InternalLogger) CInfof

func (l *InternalLogger) CInfof(ctx context.Context, fmt string,
	arg ...interface{})

func (*InternalLogger) CNoticef

func (l *InternalLogger) CNoticef(ctx context.Context, fmt string,
	arg ...interface{})

func (*InternalLogger) CWarningf

func (l *InternalLogger) CWarningf(ctx context.Context, fmt string,
	arg ...interface{})

func (*InternalLogger) CloneWithAddedDepth

func (l *InternalLogger) CloneWithAddedDepth(depth int) Logger

func (*InternalLogger) Configure

func (l *InternalLogger) Configure(style string, debug bool, filename string)

func (*InternalLogger) Critical

func (l *InternalLogger) Critical(fmt string, arg ...interface{})

func (*InternalLogger) Debug

func (l *InternalLogger) Debug(fmt string, arg ...interface{})

func (*InternalLogger) Error

func (l *InternalLogger) Error(fmt string, arg ...interface{})

func (*InternalLogger) Errorf

func (l *InternalLogger) Errorf(fmt string, arg ...interface{})

func (*InternalLogger) Fatalf

func (l *InternalLogger) Fatalf(fmt string, arg ...interface{})

func (*InternalLogger) Info

func (l *InternalLogger) Info(fmt string, arg ...interface{})

func (*InternalLogger) Notice

func (l *InternalLogger) Notice(fmt string, arg ...interface{})

func (*InternalLogger) Profile

func (l *InternalLogger) Profile(fmts string, arg ...interface{})

func (*InternalLogger) SetExternalHandler

func (l *InternalLogger) SetExternalHandler(handler ExternalHandler)

func (*InternalLogger) Warning

func (l *InternalLogger) Warning(fmt string, arg ...interface{})

type LogFileConfig

type LogFileConfig struct {
	// Path is the path of the log file to use
	Path string
	// MaxSize is the size of log file (in bytes) before rotation, 0 for infinite.
	MaxSize int64
	// MaxAge is the duration before log rotation, zero value for infinite.
	MaxAge time.Duration
	// MaxKeepFiles is maximum number of log files for this service, older
	// files are deleted.
	MaxKeepFiles int
	// RedirectStdErr indicates if the current stderr redirected to the given
	// Path.
	SkipRedirectStdErr bool
}

LogFileConfig is the config structure for new style log files with rotation.

type LogFileWriter

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

func NewLogFileWriter

func NewLogFileWriter(config LogFileConfig) *LogFileWriter

func (*LogFileWriter) Close

func (lfw *LogFileWriter) Close() error

func (*LogFileWriter) Open

func (lfw *LogFileWriter) Open(at time.Time) error

func (*LogFileWriter) Write

func (lfw *LogFileWriter) Write(bs []byte) (int, error)

type LogOutputWithDepthAdder

type LogOutputWithDepthAdder struct {
	Logger
}

func (LogOutputWithDepthAdder) CloneWithAddedDepth

func (l LogOutputWithDepthAdder) CloneWithAddedDepth(depth int) rpc.LogOutputWithDepthAdder

CloneWithAddedDepth implements the rpc.LogOutput interface.

type Logger

type Logger interface {
	BaseLogger
	// CDebugf logs a message at debug level, with a context and
	// formatting args.
	CDebugf(ctx context.Context, format string, args ...interface{})
	// CInfo logs a message at info level, with a context and formatting args.
	CInfof(ctx context.Context, format string, args ...interface{})
	// Notice logs a message at notice level, with formatting args.
	Notice(format string, args ...interface{})
	// CNoticef logs a message at notice level, with a context and
	// formatting args.
	CNoticef(ctx context.Context, format string, args ...interface{})
	// Warning logs a message at warning level, with formatting args.
	CWarningf(ctx context.Context, format string, args ...interface{})
	// Error logs a message at error level, with formatting args
	Errorf(format string, args ...interface{})
	// CErrorf logs a message at error level, with a context and
	// formatting args.
	CErrorf(ctx context.Context, format string, args ...interface{})
	// Critical logs a message at critical level, with formatting args.
	Critical(format string, args ...interface{})
	// CCriticalf logs a message at critical level, with a context and
	// formatting args.
	CCriticalf(ctx context.Context, format string, args ...interface{})
	// Fatalf logs a message at fatal level, with formatting args.
	Fatalf(format string, args ...interface{})
	// Fatalf logs a message at fatal level, with a context and formatting args.
	CFatalf(ctx context.Context, format string, args ...interface{})
	// Profile logs a profile message, with formatting args.
	Profile(fmts string, arg ...interface{})

	// Returns a logger that is like the current one, except with
	// more logging depth added on.
	CloneWithAddedDepth(depth int) Logger
	// Configure sets the style, debug level, and filename of the
	// logger.  Output isn't redirected to the file until
	// the log file rotation is configured.
	Configure(style string, debug bool, filename string)

	// SetExternalHandler sets a handler that will be called with every log message.
	SetExternalHandler(handler ExternalHandler)
}

func NewRPCLoggerAdapter

func NewRPCLoggerAdapter(log rpc.LogOutput) Logger

type Loggerf

type Loggerf interface {
	Debugf(s string, args ...interface{})
	Infof(s string, args ...interface{})
	Warningf(s string, args ...interface{})
	Errorf(s string, args ...interface{})
}

Loggerf is a minimal log interface (using proper formatter style methods)

func NewLoggerf

func NewLoggerf(log loggerInternal) Loggerf

NewLoggerf adapts a logger

type Null

type Null struct{}

func NewNull

func NewNull() *Null

func (*Null) CCriticalf

func (l *Null) CCriticalf(ctx context.Context, fmt string, arg ...interface{})

func (*Null) CDebugf

func (l *Null) CDebugf(ctx context.Context, fmt string, arg ...interface{})

func (*Null) CErrorf

func (l *Null) CErrorf(ctx context.Context, fmt string, arg ...interface{})

func (*Null) CFatalf

func (l *Null) CFatalf(ctx context.Context, fmt string, arg ...interface{})

func (*Null) CInfof

func (l *Null) CInfof(ctx context.Context, fmt string, arg ...interface{})

func (*Null) CNoticef

func (l *Null) CNoticef(ctx context.Context, fmt string, arg ...interface{})

func (*Null) CWarningf

func (l *Null) CWarningf(ctx context.Context, fmt string, arg ...interface{})

func (*Null) CloneWithAddedDepth

func (l *Null) CloneWithAddedDepth(depth int) Logger

func (*Null) Configure

func (l *Null) Configure(style string, debug bool, filename string)

func (*Null) Critical

func (l *Null) Critical(format string, args ...interface{})

func (*Null) Debug

func (l *Null) Debug(format string, args ...interface{})

func (*Null) Error

func (l *Null) Error(fmt string, arg ...interface{})

func (*Null) Errorf

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

func (*Null) Fatalf

func (l *Null) Fatalf(fmt string, arg ...interface{})

func (*Null) Info

func (l *Null) Info(format string, args ...interface{})

func (*Null) Notice

func (l *Null) Notice(format string, args ...interface{})

func (*Null) Profile

func (l *Null) Profile(fmts string, arg ...interface{})

func (*Null) SetExternalHandler

func (l *Null) SetExternalHandler(handler ExternalHandler)

func (*Null) Shutdown

func (l *Null) Shutdown()

func (*Null) Warning

func (l *Null) Warning(format string, args ...interface{})

type RPCLoggerAdapter

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

RPCLoggerAdapter is used to turn a logger complying to the rpc.LogOutput interface into one that can be used as a logger.Logger

func (RPCLoggerAdapter) CCriticalf

func (l RPCLoggerAdapter) CCriticalf(_ context.Context, format string, args ...interface{})

func (RPCLoggerAdapter) CDebugf

func (l RPCLoggerAdapter) CDebugf(_ context.Context, format string, args ...interface{})

func (RPCLoggerAdapter) CErrorf

func (l RPCLoggerAdapter) CErrorf(_ context.Context, format string, args ...interface{})

func (RPCLoggerAdapter) CFatalf

func (l RPCLoggerAdapter) CFatalf(_ context.Context, format string, args ...interface{})

func (RPCLoggerAdapter) CInfof

func (l RPCLoggerAdapter) CInfof(_ context.Context, format string, args ...interface{})

func (RPCLoggerAdapter) CNoticef

func (l RPCLoggerAdapter) CNoticef(_ context.Context, format string, args ...interface{})

func (RPCLoggerAdapter) CWarningf

func (l RPCLoggerAdapter) CWarningf(_ context.Context, format string, args ...interface{})

func (RPCLoggerAdapter) CloneWithAddedDepth

func (l RPCLoggerAdapter) CloneWithAddedDepth(depth int) Logger

func (RPCLoggerAdapter) Configure

func (l RPCLoggerAdapter) Configure(style string, debug bool, filename string)

func (RPCLoggerAdapter) Critical

func (l RPCLoggerAdapter) Critical(format string, args ...interface{})

func (RPCLoggerAdapter) Debug

func (l RPCLoggerAdapter) Debug(format string, args ...interface{})

func (RPCLoggerAdapter) Error

func (l RPCLoggerAdapter) Error(format string, args ...interface{})

func (RPCLoggerAdapter) Errorf

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

func (RPCLoggerAdapter) Fatalf

func (l RPCLoggerAdapter) Fatalf(format string, args ...interface{})

func (RPCLoggerAdapter) Info

func (l RPCLoggerAdapter) Info(format string, args ...interface{})

func (RPCLoggerAdapter) Notice

func (l RPCLoggerAdapter) Notice(format string, args ...interface{})

func (RPCLoggerAdapter) Profile

func (l RPCLoggerAdapter) Profile(format string, args ...interface{})

func (RPCLoggerAdapter) SetExternalHandler

func (l RPCLoggerAdapter) SetExternalHandler(handler ExternalHandler)

func (RPCLoggerAdapter) Warning

func (l RPCLoggerAdapter) Warning(format string, args ...interface{})

type SingleContextLogger

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

SingleContextLogger logs everything in the same context. Useful for adding context-logging into code that doesn't yet support it.

func NewSingleContextLogger

func NewSingleContextLogger(ctx context.Context, l Logger) *SingleContextLogger

func (*SingleContextLogger) CCriticalf

func (s *SingleContextLogger) CCriticalf(ctx context.Context, format string, args ...interface{})

func (*SingleContextLogger) CDebugf

func (s *SingleContextLogger) CDebugf(ctx context.Context, format string, args ...interface{})

func (*SingleContextLogger) CErrorf

func (s *SingleContextLogger) CErrorf(ctx context.Context, format string, args ...interface{})

func (*SingleContextLogger) CFatalf

func (s *SingleContextLogger) CFatalf(ctx context.Context, format string, args ...interface{})

func (*SingleContextLogger) CInfof

func (s *SingleContextLogger) CInfof(ctx context.Context, format string, args ...interface{})

func (*SingleContextLogger) CNoticef

func (s *SingleContextLogger) CNoticef(ctx context.Context, format string, args ...interface{})

func (*SingleContextLogger) CWarningf

func (s *SingleContextLogger) CWarningf(ctx context.Context, format string, args ...interface{})

func (*SingleContextLogger) CloneWithAddedDepth

func (s *SingleContextLogger) CloneWithAddedDepth(depth int) Logger

func (*SingleContextLogger) Configure

func (s *SingleContextLogger) Configure(style string, debug bool, filename string)

func (*SingleContextLogger) Critical

func (s *SingleContextLogger) Critical(format string, args ...interface{})

func (*SingleContextLogger) Debug

func (s *SingleContextLogger) Debug(format string, args ...interface{})

func (*SingleContextLogger) Error

func (s *SingleContextLogger) Error(format string, args ...interface{})

func (*SingleContextLogger) Errorf

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

func (*SingleContextLogger) Fatalf

func (s *SingleContextLogger) Fatalf(format string, args ...interface{})

func (*SingleContextLogger) Info

func (s *SingleContextLogger) Info(format string, args ...interface{})

func (*SingleContextLogger) Notice

func (s *SingleContextLogger) Notice(format string, args ...interface{})

func (*SingleContextLogger) Profile

func (s *SingleContextLogger) Profile(fmts string, arg ...interface{})

func (*SingleContextLogger) SetExternalHandler

func (s *SingleContextLogger) SetExternalHandler(handler ExternalHandler)

func (*SingleContextLogger) Warning

func (s *SingleContextLogger) Warning(format string, args ...interface{})

type Standard

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

func New

func New(module string) *Standard

New creates a new Standard logger for module.

func NewWithCallDepth

func NewWithCallDepth(module string, extraCallDepth int) *Standard

NewWithCallDepth creates a new Standard logger for module, and when printing file names and line numbers, it goes extraCallDepth up the stack from where logger was invoked.

func (*Standard) CCriticalf

func (log *Standard) CCriticalf(ctx context.Context, fmt string,
	arg ...interface{})

func (*Standard) CDebugf

func (log *Standard) CDebugf(ctx context.Context, fmt string,
	arg ...interface{})

func (*Standard) CErrorf

func (log *Standard) CErrorf(ctx context.Context, fmt string,
	arg ...interface{})

func (*Standard) CFatalf

func (log *Standard) CFatalf(ctx context.Context, fmt string,
	arg ...interface{})

func (*Standard) CInfof

func (log *Standard) CInfof(ctx context.Context, fmt string,
	arg ...interface{})

func (*Standard) CNoticef

func (log *Standard) CNoticef(ctx context.Context, fmt string,
	arg ...interface{})

func (*Standard) CWarningf

func (log *Standard) CWarningf(ctx context.Context, fmt string,
	arg ...interface{})

func (*Standard) CloneWithAddedDepth

func (log *Standard) CloneWithAddedDepth(depth int) Logger

func (*Standard) Configure

func (log *Standard) Configure(style string, debug bool, filename string)

Configure sets the style of the log file, whether debugging (verbose) is enabled and a filename. If a filename is provided here it will be used for logging straight away (this is a new feature). SetLogFileConfig provides a way to set the log file with more control on rotation.

func (*Standard) Critical

func (log *Standard) Critical(fmt string, arg ...interface{})

func (*Standard) Debug

func (log *Standard) Debug(fmt string, arg ...interface{})

func (*Standard) Error

func (log *Standard) Error(fmt string, arg ...interface{})

func (*Standard) Errorf

func (log *Standard) Errorf(fmt string, arg ...interface{})

func (*Standard) Fatalf

func (log *Standard) Fatalf(fmt string, arg ...interface{})

func (*Standard) GetUnforwardedLogger

func (log *Standard) GetUnforwardedLogger() *UnforwardedLogger

func (*Standard) Info

func (log *Standard) Info(fmt string, arg ...interface{})

func (*Standard) Notice

func (log *Standard) Notice(fmt string, arg ...interface{})

func (*Standard) Profile

func (log *Standard) Profile(fmts string, arg ...interface{})

func (*Standard) SetExternalHandler

func (log *Standard) SetExternalHandler(handler ExternalHandler)

func (*Standard) Warning

func (log *Standard) Warning(fmt string, arg ...interface{})

type TestLogBackend

type TestLogBackend interface {
	Error(args ...interface{})
	Errorf(format string, args ...interface{})
	Fatal(args ...interface{})
	Fatalf(format string, args ...interface{})
	Log(args ...interface{})
	Logf(format string, args ...interface{})
	Failed() bool
	Name() string
}

TestLogBackend is an interface for logging to a test object (i.e., a *testing.T). We define this in order to avoid pulling in the "testing" package in exported code.

type TestLogger

type TestLogger struct {
	sync.Mutex
	// contains filtered or unexported fields
}

TestLogger is a Logger that writes to a TestLogBackend. All messages except Fatal are printed using Logf, to avoid failing a test that is trying to test an error condition. No context tags are logged.

func NewTestLogger

func NewTestLogger(log TestLogBackend) *TestLogger

func (*TestLogger) CCriticalf

func (log *TestLogger) CCriticalf(ctx context.Context, fmts string,
	arg ...interface{})

func (*TestLogger) CDebugf

func (log *TestLogger) CDebugf(ctx context.Context, fmts string,
	arg ...interface{})

func (*TestLogger) CErrorf

func (log *TestLogger) CErrorf(ctx context.Context, fmts string,
	arg ...interface{})

func (*TestLogger) CFatalf

func (log *TestLogger) CFatalf(ctx context.Context, fmts string,
	arg ...interface{})

func (*TestLogger) CInfof

func (log *TestLogger) CInfof(ctx context.Context, fmts string,
	arg ...interface{})

func (*TestLogger) CNoticef

func (log *TestLogger) CNoticef(ctx context.Context, fmts string,
	arg ...interface{})

func (*TestLogger) CWarningf

func (log *TestLogger) CWarningf(ctx context.Context, fmts string,
	arg ...interface{})

func (*TestLogger) CloneWithAddedDepth

func (log *TestLogger) CloneWithAddedDepth(depth int) Logger

func (*TestLogger) Configure

func (log *TestLogger) Configure(style string, debug bool, filename string)

func (*TestLogger) Critical

func (log *TestLogger) Critical(fmts string, arg ...interface{})

func (*TestLogger) Debug

func (log *TestLogger) Debug(fmts string, arg ...interface{})

func (*TestLogger) Error

func (log *TestLogger) Error(fmts string, arg ...interface{})

func (*TestLogger) Errorf

func (log *TestLogger) Errorf(fmts string, arg ...interface{})

func (*TestLogger) Fatalf

func (log *TestLogger) Fatalf(fmts string, arg ...interface{})

func (*TestLogger) Info

func (log *TestLogger) Info(fmts string, arg ...interface{})

func (*TestLogger) Notice

func (log *TestLogger) Notice(fmts string, arg ...interface{})

func (*TestLogger) Profile

func (log *TestLogger) Profile(fmts string, arg ...interface{})

func (*TestLogger) SetExternalHandler

func (log *TestLogger) SetExternalHandler(_ ExternalHandler)

no-op stubs to fulfill the Logger interface

func (*TestLogger) Warning

func (log *TestLogger) Warning(fmts string, arg ...interface{})

type UnforwardedLogger

type UnforwardedLogger Standard

func (*UnforwardedLogger) Debug

func (log *UnforwardedLogger) Debug(s string, args ...interface{})

func (*UnforwardedLogger) Error

func (log *UnforwardedLogger) Error(s string, args ...interface{})

func (*UnforwardedLogger) Errorf

func (log *UnforwardedLogger) Errorf(s string, args ...interface{})

func (*UnforwardedLogger) Info

func (log *UnforwardedLogger) Info(s string, args ...interface{})

func (*UnforwardedLogger) Profile

func (log *UnforwardedLogger) Profile(s string, args ...interface{})

func (*UnforwardedLogger) Warning

func (log *UnforwardedLogger) Warning(s string, args ...interface{})

Jump to

Keyboard shortcuts

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