logger

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2022 License: MIT Imports: 27 Imported by: 46

Documentation

Index

Constants

View Source
const (
	HeadTracker     = "HeadTracker"
	HeadListener    = "HeadListener"
	HeadSaver       = "HeadSaver"
	HeadBroadcaster = "HeadBroadcaster"
	FluxMonitor     = "FluxMonitor"
	Keeper          = "Keeper"
)

Constants for service names for package specific logging configuration

View Source
const LogsFile = "chainlink_debug.log"

LogsFile describes the logs file name

View Source
const (
	// SentryFlushDeadline indicates the maximum amount of time we allow sentry to
	// flush events on manual flush
	SentryFlushDeadline = 5 * time.Second
)

Variables

This section is empty.

Functions

func InitColor added in v1.1.0

func InitColor(c bool)

InitColor explicitly sets the global color.NoColor option. Not safe for concurrent use. Only to be called from init().

func NewOCRWrapper added in v1.1.0

func NewOCRWrapper(l Logger, trace bool, saveError func(string)) ocrtypes.Logger

Types

type Config added in v1.1.0

type Config struct {
	LogLevel       zapcore.Level
	Dir            string
	JsonConsole    bool
	UnixTS         bool
	FileMaxSizeMB  int
	FileMaxAgeDays int
	FileMaxBackups int // files
}

func (Config) DebugLogsToDisk added in v1.3.0

func (c Config) DebugLogsToDisk() bool

DebugLogsToDisk returns whether debug logs should be stored in disk

func (*Config) New added in v1.2.0

func (c *Config) New() (Logger, func() error)

New returns a new Logger with pretty printing to stdout, prometheus counters, and sentry forwarding. Tests should use TestLogger.

func (Config) RequiredDiskSpace added in v1.3.0

func (c Config) RequiredDiskSpace() utils.FileSize

RequiredDiskSpace returns the required disk space in order to allow debug logs to be stored in disk

type Fields added in v1.1.0

type Fields map[string]interface{}

func (Fields) Merge added in v1.1.0

func (f Fields) Merge(f2 Fields) Fields

func (Fields) Slice added in v1.1.0

func (f Fields) Slice() []interface{}

func (Fields) With added in v1.1.0

func (f Fields) With(xs ...interface{}) Fields

type Logger

type Logger interface {
	// With creates a new Logger with the given arguments
	With(args ...interface{}) Logger
	// Named creates a new Logger sub-scoped with name.
	// Names are inherited and dot-separated.
	//   a := l.Named("a") // logger=a
	//   b := a.Named("b") // logger=a.b
	Named(name string) Logger

	// SetLogLevel changes the log level for this and all connected Loggers.
	SetLogLevel(zapcore.Level)

	Trace(args ...interface{})
	Debug(args ...interface{})
	Info(args ...interface{})
	Warn(args ...interface{})
	Error(args ...interface{})
	Critical(args ...interface{})
	Panic(args ...interface{})
	// Fatal logs and then calls os.Exit(1)
	// Be careful about using this since it does NOT unwind the stack and may
	// exit uncleanly
	Fatal(args ...interface{})

	Tracef(format string, values ...interface{})
	Debugf(format string, values ...interface{})
	Infof(format string, values ...interface{})
	Warnf(format string, values ...interface{})
	Errorf(format string, values ...interface{})
	Criticalf(format string, values ...interface{})
	Panicf(format string, values ...interface{})
	Fatalf(format string, values ...interface{})

	Tracew(msg string, keysAndValues ...interface{})
	Debugw(msg string, keysAndValues ...interface{})
	Infow(msg string, keysAndValues ...interface{})
	Warnw(msg string, keysAndValues ...interface{})
	Errorw(msg string, keysAndValues ...interface{})
	Criticalw(msg string, keysAndValues ...interface{})
	Panicw(msg string, keysAndValues ...interface{})
	Fatalw(msg string, keysAndValues ...interface{})

	// ErrorIf logs the error if present.
	ErrorIf(err error, msg string)

	// ErrorIfClosing calls c.Close() and logs any returned error along with name.
	ErrorIfClosing(c io.Closer, name string)

	// Sync flushes any buffered log entries.
	// Some insignificant errors are suppressed.
	Sync() error

	// Helper creates a new logger with the number of callers skipped by caller annotation increased by skip.
	// This allows wrappers and helpers to point higher up the stack (like testing.T.Helper()).
	Helper(skip int) Logger

	// Recover reports recovered panics; this is useful because it avoids
	// double-reporting to sentry
	Recover(panicErr interface{})
}

Logger is the main interface of this package. It implements uber/zap's SugaredLogger interface and adds conditional logging helpers.

Loggers should be injected (and usually Named as well): e.g. lggr.Named("<service name>")

Tests

  • Tests should use a TestLogger, with NewLogger being reserved for actual runtime and limited direct testing.

Levels

  • Fatal: Logs and then calls os.Exit(1). Be careful about using this since it does NOT unwind the stack and may exit uncleanly.
  • Panic: Unrecoverable error. Example: invariant violation, programmer error
  • Critical: Requires quick action from the node op, obviously these should happen extremely rarely. Example: failed to listen on TCP port
  • Error: Something bad happened, and it was clearly on the node op side. No need for immediate action though. Example: database write timed out
  • Warn: Something bad happened, not clear who/what is at fault. Node ops should have a rough look at these once in a while to see whether anything stands out. Example: connection to peer was closed unexpectedly. observation timed out.
  • Info: High level information. First level we’d expect node ops to look at. Example: entered new epoch with leader, made an observation with value, etc.
  • Debug: Useful for forensic debugging, but we don't expect nops to look at this. Example: Got a message, dropped a message, ...
  • Trace: Only included if compiled with the trace tag. For example: go test -tags trace ...

Node Operator Docs: https://docs.chain.link/docs/configuration-variables/#log_level

var NullLogger Logger = &nullLogger{}

nolint

func NewLogger added in v1.1.0

func NewLogger() (Logger, func() error)

NewLogger returns a new Logger configured from environment variables, and logs any parsing errors. Tests should use TestLogger.

func TestLoggerObserved added in v1.3.0

func TestLoggerObserved(t T, lvl zapcore.Level) (Logger, *observer.ObservedLogs)

TestLoggerObserved creates a logger with an observer that can be used to test emitted logs at the given level or above

type MemorySink added in v0.8.15

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

MemorySink implements zap.Sink by writing all messages to a buffer.

func MemoryLogTestingOnly added in v0.8.15

func MemoryLogTestingOnly() *MemorySink

func (*MemorySink) Close added in v0.8.15

func (s *MemorySink) Close() error

Close is a dummy method to satisfy the zap.Sink interface

func (*MemorySink) Reset added in v1.1.0

func (s *MemorySink) Reset()

func (*MemorySink) String added in v0.8.15

func (s *MemorySink) String() string

String returns the full log contents, as a string

func (*MemorySink) Sync added in v0.8.15

func (s *MemorySink) Sync() error

Sync is a dummy method to satisfy the zap.Sink interface

func (*MemorySink) Write added in v0.8.15

func (s *MemorySink) Write(p []byte) (n int, err error)

type PrettyConsole

type PrettyConsole struct {
	zap.Sink
}

PrettyConsole wraps a Sink (Writer, Syncer, Closer), usually stdout, and formats the incoming json bytes with colors and white space for readability before passing on to the underlying Writer in Sink.

func (PrettyConsole) Close added in v1.2.0

func (pc PrettyConsole) Close() error

Close is overridden to prevent accidental closure of stderr/stdout

func (PrettyConsole) Write

func (pc PrettyConsole) Write(b []byte) (int, error)

Write reformats the incoming json bytes with colors, newlines and whitespace for better readability in console.

type SugaredLogger added in v1.3.0

type SugaredLogger interface {
	Logger
	AssumptionViolation(args ...interface{})
	AssumptionViolationf(format string, vals ...interface{})
	AssumptionViolationw(msg string, keyvals ...interface{})
}

SugaredLogger extends the base Logger interface with syntactic sugar, similar to zap.SugaredLogger.

func Sugared added in v1.3.0

func Sugared(l Logger) SugaredLogger

func TestLogger added in v1.1.0

func TestLogger(t T) SugaredLogger

TestLogger creates a logger that directs output to PrettyConsole configured for test output, and to the buffer testMemoryLog. t is optional. Log level is derived from the LOG_LEVEL env var.

type T added in v1.1.0

type T interface {
	Name() string
	Cleanup(f func())
	Fatal(...interface{})
	Errorf(format string, args ...interface{})
}

Jump to

Keyboard shortcuts

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