logger

package
v1.13.3 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2023 License: MIT Imports: 30 Imported by: 46

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

func StartPyroscope added in v1.9.0

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

StartPyroscope starts continuous profiling of the Chainlink Node

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) LogsFile added in v1.12.0

func (c Config) LogsFile() string

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.
	// Deprecated: use SugaredLogger.ErrorIf
	ErrorIf(err error, msg string)

	// ErrorIfClosing calls c.Close() and logs any returned error along with name.
	// Deprecated: use SugaredLogger.ErrorIfFn with c.Close
	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

	// 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 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. Deprecated: This depends on legacy environment variables.

func TestLoggerObserved added in v1.3.0

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 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 PyroscopeConfig added in v1.9.0

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 added in v1.3.0

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 added in v1.3.0

func Sugared(l Logger) SugaredLogger

Sugared returns a new SugaredLogger wrapping the given Logger.

func TestLogger added in v1.1.0

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