package log

Import Path
	github.com/ipfs/go-log/v2 (on go.dev)

Dependency Relation
	imports 14 packages, and imported by 34 packages

Involved Source Files core.go levels.go Package log is the logging library used by IPFS & libp2p (https://github.com/ipfs/go-ipfs). path_other.go pipe.go setup.go
Package-Level Type Names (total 8)
/* sort by: | */
File is a path to a file that logs will be written to. Format overrides the format of the log output. Defaults to ColorizedOutput Labels is a set of key-values to apply to all loggers Level is the default minimum enabled logging level. Stderr indicates whether logs should be written to stderr. Stdout indicates whether logs should be written to stdout. SubsystemLevels are the default levels per-subsystem. When unspecified, defaults to Level. URL with schema supported by zap. Use zap.RegisterSink func GetConfig() Config func SetupLogging(cfg Config)
EventLogger extends the StandardLogger interface to allow for log items containing structured metadata ( EventLogger) Debug(args ...interface{}) ( EventLogger) Debugf(format string, args ...interface{}) ( EventLogger) Error(args ...interface{}) ( EventLogger) Errorf(format string, args ...interface{}) ( EventLogger) Fatal(args ...interface{}) ( EventLogger) Fatalf(format string, args ...interface{}) ( EventLogger) Info(args ...interface{}) ( EventLogger) Infof(format string, args ...interface{}) ( EventLogger) Panic(args ...interface{}) ( EventLogger) Panicf(format string, args ...interface{}) ( EventLogger) Warn(args ...interface{}) ( EventLogger) Warnf(format string, args ...interface{}) StandardLogger (interface) *ZapEventLogger *go.uber.org/zap.SugaredLogger EventLogger : StandardLogger EventLogger : github.com/hibiken/asynq.Logger EventLogger : github.com/hibiken/asynq/internal/log.Base EventLogger : github.com/stretchr/testify/assert.TestingT
func PipeFormat(format LogFormat) PipeReaderOption const ColorizedOutput const JSONOutput const PlaintextOutput
LogLevel represents a log severity level. Use the package variables as an enum. func LevelFromString(level string) (LogLevel, error) func PipeLevel(level LogLevel) PipeReaderOption func SetAllLoggers(lvl LogLevel) func WithStacktrace(l *ZapEventLogger, level LogLevel) *ZapEventLogger var LevelDebug var LevelDPanic var LevelError var LevelFatal var LevelInfo var LevelPanic var LevelWarn
A PipeReader is a reader that reads from the logger. It is synchronous so blocking on read will affect logging performance. Close unregisters the reader from the logger. Read implements the standard Read interface *PipeReader : github.com/prometheus/common/expfmt.Closer *PipeReader : io.Closer *PipeReader : io.ReadCloser *PipeReader : io.Reader func NewPipeReader(opts ...PipeReaderOption) *PipeReader
func PipeFormat(format LogFormat) PipeReaderOption func PipeLevel(level LogLevel) PipeReaderOption func NewPipeReader(opts ...PipeReaderOption) *PipeReader
StandardLogger provides API compatibility with standard printf loggers eg. go-logging ( StandardLogger) Debug(args ...interface{}) ( StandardLogger) Debugf(format string, args ...interface{}) ( StandardLogger) Error(args ...interface{}) ( StandardLogger) Errorf(format string, args ...interface{}) ( StandardLogger) Fatal(args ...interface{}) ( StandardLogger) Fatalf(format string, args ...interface{}) ( StandardLogger) Info(args ...interface{}) ( StandardLogger) Infof(format string, args ...interface{}) ( StandardLogger) Panic(args ...interface{}) ( StandardLogger) Panicf(format string, args ...interface{}) ( StandardLogger) Warn(args ...interface{}) ( StandardLogger) Warnf(format string, args ...interface{}) EventLogger (interface) *ZapEventLogger *go.uber.org/zap.SugaredLogger StandardLogger : EventLogger StandardLogger : github.com/hibiken/asynq.Logger StandardLogger : github.com/hibiken/asynq/internal/log.Base StandardLogger : github.com/stretchr/testify/assert.TestingT
ZapEventLogger implements the EventLogger and wraps a go-logging Logger SugaredLogger zap.SugaredLogger DPanic logs the provided arguments at [DPanicLevel]. In development, the logger then panics. (See [DPanicLevel] for details.) Spaces are added between arguments when neither is a string. DPanicf formats the message according to the format specifier and logs it at [DPanicLevel]. In development, the logger then panics. (See [DPanicLevel] for details.) DPanicln logs a message at [DPanicLevel]. In development, the logger then panics. (See [DPanicLevel] for details.) Spaces are always added between arguments. DPanicw logs a message with some additional context. In development, the logger then panics. (See DPanicLevel for details.) The variadic key-value pairs are treated as they are in With. Debug logs the provided arguments at [DebugLevel]. Spaces are added between arguments when neither is a string. Debugf formats the message according to the format specifier and logs it at [DebugLevel]. Debugln logs a message at [DebugLevel]. Spaces are always added between arguments. Debugw logs a message with some additional context. The variadic key-value pairs are treated as they are in With. When debug-level logging is disabled, this is much faster than s.With(keysAndValues).Debug(msg) Desugar unwraps a SugaredLogger, exposing the original Logger. Desugaring is quite inexpensive, so it's reasonable for a single application to use both Loggers and SugaredLoggers, converting between them on the boundaries of performance-sensitive code. Error logs the provided arguments at [ErrorLevel]. Spaces are added between arguments when neither is a string. Errorf formats the message according to the format specifier and logs it at [ErrorLevel]. Errorln logs a message at [ErrorLevel]. Spaces are always added between arguments. Errorw logs a message with some additional context. The variadic key-value pairs are treated as they are in With. Fatal constructs a message with the provided arguments and calls os.Exit. Spaces are added between arguments when neither is a string. Fatalf formats the message according to the format specifier and calls os.Exit. Fatalln logs a message at [FatalLevel] and calls os.Exit. Spaces are always added between arguments. Fatalw logs a message with some additional context, then calls os.Exit. The variadic key-value pairs are treated as they are in With. Info logs the provided arguments at [InfoLevel]. Spaces are added between arguments when neither is a string. Infof formats the message according to the format specifier and logs it at [InfoLevel]. Infoln logs a message at [InfoLevel]. Spaces are always added between arguments. Infow logs a message with some additional context. The variadic key-value pairs are treated as they are in With. Level reports the minimum enabled level for this logger. For NopLoggers, this is [zapcore.InvalidLevel]. Log logs the provided arguments at provided level. Spaces are added between arguments when neither is a string. Logf formats the message according to the format specifier and logs it at provided level. Logln logs a message at provided level. Spaces are always added between arguments. Logw logs a message with some additional context. The variadic key-value pairs are treated as they are in With. Named adds a sub-scope to the logger's name. See Logger.Named for details. Panic constructs a message with the provided arguments and panics. Spaces are added between arguments when neither is a string. Panicf formats the message according to the format specifier and panics. Panicln logs a message at [PanicLevel] and panics. Spaces are always added between arguments. Panicw logs a message with some additional context, then panics. The variadic key-value pairs are treated as they are in With. Sync flushes any buffered log entries. Warn logs the provided arguments at [WarnLevel]. Spaces are added between arguments when neither is a string. Warnf formats the message according to the format specifier and logs it at [WarnLevel]. Warning is for compatibility Deprecated: use Warn(args ...interface{}) instead Warningf is for compatibility Deprecated: use Warnf(format string, args ...interface{}) instead Warnln logs a message at [WarnLevel]. Spaces are always added between arguments. Warnw logs a message with some additional context. The variadic key-value pairs are treated as they are in With. With adds a variadic number of fields to the logging context. It accepts a mix of strongly-typed Field objects and loosely-typed key-value pairs. When processing pairs, the first element of the pair is used as the field key and the second as the field value. For example, sugaredLogger.With( "hello", "world", "failure", errors.New("oh no"), Stack(), "count", 42, "user", User{Name: "alice"}, ) is the equivalent of unsugared.With( String("hello", "world"), String("failure", "oh no"), Stack(), Int("count", 42), Object("user", User{Name: "alice"}), ) Note that the keys in key-value pairs should be strings. In development, passing a non-string key panics. In production, the logger is more forgiving: a separate error is logged, but the key-value pair is skipped and execution continues. Passing an orphaned key triggers similar behavior: panics in development and errors in production. WithLazy adds a variadic number of fields to the logging context lazily. The fields are evaluated only if the logger is further chained with [With] or is written to with any of the log level methods. Until that occurs, the logger may retain references to objects inside the fields, and logging will reflect the state of an object at the time of logging, not the time of WithLazy(). Similar to [With], fields added to the child don't affect the parent, and vice versa. Also, the keys in key-value pairs should be strings. In development, passing a non-string key panics, while in production it logs an error and skips the pair. Passing an orphaned key has the same behavior. WithOptions clones the current SugaredLogger, applies the supplied Options, and returns the result. It's safe to use concurrently. *ZapEventLogger : EventLogger *ZapEventLogger : StandardLogger *ZapEventLogger : github.com/hibiken/asynq.Logger *ZapEventLogger : github.com/hibiken/asynq/internal/log.Base *ZapEventLogger : github.com/polarsignals/frostdb.Sync *ZapEventLogger : github.com/stretchr/testify/assert.TestingT func Logger(system string) *ZapEventLogger func WithSkip(l *ZapEventLogger, skip int) *ZapEventLogger func WithStacktrace(l *ZapEventLogger, level LogLevel) *ZapEventLogger func WithSkip(l *ZapEventLogger, skip int) *ZapEventLogger func WithStacktrace(l *ZapEventLogger, level LogLevel) *ZapEventLogger
Package-Level Functions (total 16)
FormatRFC3339 returns the given time in UTC with RFC3999Nano format.
GetConfig returns a copy of the saved config. It can be inspected, modified, and re-applied using a subsequent call to SetupLogging().
GetSubsystems returns a slice containing the names of the current loggers
LevelFromString parses a string-based level and returns the corresponding LogLevel. Supported strings are: DEBUG, INFO, WARN, ERROR, DPANIC, PANIC, FATAL, and their lower-case forms. The returned LogLevel must be discarded if error is not nil.
Logger retrieves an event logger by name
NewPipeReader creates a new in-memory reader that reads from all loggers The caller must call Close on the returned reader when done. By default, it: 1. Logs JSON. This can be changed by passing the PipeFormat option. 2. Logs everything that would otherwise be logged to the "primary" log output. That is, everything enabled by SetLogLevel. The minimum log level can be increased by passing the PipeLevel option.
PipeFormat sets the output format of the pipe reader
PipeLevel sets the log level of logs sent to the pipe reader.
SetAllLoggers changes the logging level of all loggers to lvl
SetDebugLogging calls SetAllLoggers with logging.DEBUG
SetLogLevel changes the log level of a specific subsystem name=="*" changes all subsystems
SetLogLevelRegex sets all loggers to level `l` that match expression `e`. An error is returned if `e` fails to compile.
SetPrimaryCore changes the primary logging core. If the SetupLogging was called then the previously configured core will be replaced.
SetupLogging will initialize the logger backend and set the flags. TODO calling this in `init` pushes all configuration to env variables - move it out of `init`? then we need to change all the code (js-ipfs, go-ipfs) to call this explicitly - have it look for a config file? need to define what that is
WithSkip returns a new logger that skips the specified number of stack frames when reporting the line/file.
Package-Level Variables (total 8)
ErrNoSuchLogger is returned when the util pkg is asked for a non existant logger
Package-Level Constants (total 3)