logger

package
v2.1.0-rc0 Latest Latest
Warning

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

Go to latest
Published: May 5, 2023 License: MIT Imports: 29 Imported by: 12

Documentation

Index

Constants

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

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

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

func StartPyroscope

func StartPyroscope(cfg PyroscopeConfig) (*pyroscope.Profiler, error)

StartPyroscope starts continuous profiling of the Chainlink Node

Types

type Config

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

func (Config) DebugLogsToDisk

func (c Config) DebugLogsToDisk() bool

DebugLogsToDisk returns whether debug logs should be stored in disk

func (Config) LogsFile

func (c Config) LogsFile() string

func (*Config) New

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

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

type Fields map[string]interface{}

func (Fields) Merge

func (f Fields) Merge(f2 Fields) Fields

func (Fields) Slice

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

func (Fields) With

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{})

	// 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

	// Name returns the fully qualified name of the logger.
	Name() string

	// 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

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

NewLogger returns a new Logger with default configuration. Tests should use TestLogger.

func TestLoggerObserved

func TestLoggerObserved(tb testing.TB, 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

Note: It is not necessary to Sync().

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

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 PyroscopeConfig

type PyroscopeConfig interface {
	PyroscopeServerAddress() string
	PyroscopeAuthToken() string
	PyroscopeEnvironment() string

	AutoPprofBlockProfileRate() int
	AutoPprofMutexProfileFraction() int
}

PyroscopeConfig represents the expected configuration for Pyroscope to properly work

type SugaredLogger

type SugaredLogger interface {
	Logger
	// AssumptionViolation variants log at error level with the message prefix "AssumptionViolation: ".
	AssumptionViolation(args ...interface{})
	AssumptionViolationf(format string, vals ...interface{})
	AssumptionViolationw(msg string, keyvals ...interface{})
	// ErrorIf logs the error if present.
	ErrorIf(err error, msg string)
	// ErrorIfFn calls fn() and logs any returned error along with msg.
	// Unlike ErrorIf, this can be deffered inline, since the function call is delayed.
	ErrorIfFn(fn func() error, msg string)
}

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

func Sugared

func Sugared(l Logger) SugaredLogger

Sugared returns a new SugaredLogger wrapping the given Logger.

func TestLogger

func TestLogger(tb testing.TB) 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 DEBUG by default.

Note: It is not necessary to Sync().

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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