Documentation ¶
Index ¶
Constants ¶
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 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 // contains filtered or unexported fields }
func (Config) DebugLogsToDisk ¶
DebugLogsToDisk returns whether debug logs should be stored in disk
func (*Config) DiskSpaceAvailable ¶ added in v2.2.0
func (*Config) New ¶
New returns a new Logger with pretty printing to stdout, prometheus counters, and sentry forwarding. Tests should use TestLogger.
func (Config) RequiredDiskSpace ¶
RequiredDiskSpace returns the required disk space in order to allow debug logs to be stored in disk
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 ¶
NewLogger returns a new Logger with default configuration. Tests should use TestLogger.
func TestLoggerObserved ¶
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 ¶
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
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().