Documentation
¶
Overview ¶
Package log is the logging library used by IPFS & libp2p (https://github.com/ipfs/go-ipfs).
Index ¶
- Constants
- Variables
- func FormatRFC3339(t time.Time) string
- func GetSubsystems() []string
- func SetAllLoggers(lvl LogLevel)
- func SetDebugLogging()
- func SetLogLevel(name, level string) error
- func SetLogLevelRegex(e, l string) error
- func SetPrimaryCore(core zapcore.Core)
- func SetupLogging(cfg Config)
- func SubsystemLevelName(subsys string) (string, error)
- func SubsystemLevelNames() map[string]string
- type Config
- type EventLogger
- type LogFormat
- type LogLevel
- type PipeReader
- type PipeReaderOption
- type StandardLogger
- type ZapEventLogger
Constants ¶
const DefaultName = ""
DefaultName is the subsystem name that identifies the default log level.
Variables ¶
var ( LevelDebug = LogLevel(zapcore.DebugLevel) LevelInfo = LogLevel(zapcore.InfoLevel) LevelWarn = LogLevel(zapcore.WarnLevel) LevelError = LogLevel(zapcore.ErrorLevel) LevelDPanic = LogLevel(zapcore.DPanicLevel) LevelPanic = LogLevel(zapcore.PanicLevel) LevelFatal = LogLevel(zapcore.FatalLevel) )
var ErrNoSuchLogger = errors.New("error: No such logger")
ErrNoSuchLogger is returned when the util pkg is asked for a non existant logger
Functions ¶
func FormatRFC3339 ¶
FormatRFC3339 returns the given time in UTC with RFC3999Nano format.
func GetSubsystems ¶
func GetSubsystems() []string
GetSubsystems returns a slice containing the names of the current loggers
func SetAllLoggers ¶
func SetAllLoggers(lvl LogLevel)
SetAllLoggers changes the logging level of all loggers to lvl
func SetDebugLogging ¶
func SetDebugLogging()
SetDebugLogging calls SetAllLoggers with logging.DEBUG
func SetLogLevel ¶
SetLogLevel changes the log level of a specific subsystem name=="*" changes all subsystems
func SetLogLevelRegex ¶
SetLogLevelRegex sets all loggers to level `l` that match expression `e`. An error is returned if `e` fails to compile.
func SetPrimaryCore ¶ added in v2.2.0
SetPrimaryCore changes the primary logging core. If the SetupLogging was called then the previously configured core will be replaced.
func SetupLogging ¶
func SetupLogging(cfg Config)
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
func SubsystemLevelName ¶ added in v2.8.0
SubsystemLevelName returns the current log level name for a given subsystem. An empty name, "", returns the default LogLevel name.
func SubsystemLevelNames ¶ added in v2.8.0
SubsystemLevelNames returns a map of all facility names to their current log levels as strings. The map includes the default log level identified by the defaultName string as the map key.
Types ¶
type Config ¶ added in v2.1.0
type Config struct { // Format overrides the format of the log output. Defaults to ColorizedOutput Format LogFormat // Level is the default minimum enabled logging level. Level LogLevel // SubsystemLevels are the default levels per-subsystem. When unspecified, defaults to Level. SubsystemLevels map[string]LogLevel // Stderr indicates whether logs should be written to stderr. Stderr bool // Stdout indicates whether logs should be written to stdout. Stdout bool // File is a path to a file that logs will be written to. File string // URL with schema supported by zap. Use zap.RegisterSink URL string // Labels is a set of key-values to apply to all loggers Labels map[string]string }
type EventLogger ¶
type EventLogger interface { StandardLogger }
EventLogger extends the StandardLogger interface to allow for log items containing structured metadata
type LogLevel ¶
LogLevel represents a log severity level. Use the package variables as an enum.
func DefaultLevel ¶ added in v2.8.0
func DefaultLevel() LogLevel
DefaultLevel returns the current default LogLevel.
type PipeReader ¶ added in v2.1.0
type PipeReader struct {
// contains filtered or unexported fields
}
A PipeReader is a reader that reads from the logger. It is synchronous so blocking on read will affect logging performance.
func NewPipeReader ¶ added in v2.1.0
func NewPipeReader(opts ...PipeReaderOption) *PipeReader
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:
- Logs JSON. This can be changed by passing the PipeFormat option.
- 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.
func (*PipeReader) Close ¶ added in v2.1.0
func (p *PipeReader) Close() error
Close unregisters the reader from the logger.
type PipeReaderOption ¶ added in v2.1.0
type PipeReaderOption interface {
// contains filtered or unexported methods
}
func PipeFormat ¶ added in v2.1.0
func PipeFormat(format LogFormat) PipeReaderOption
PipeFormat sets the output format of the pipe reader
func PipeLevel ¶ added in v2.1.0
func PipeLevel(level LogLevel) PipeReaderOption
PipeLevel sets the log level of logs sent to the pipe reader.
type StandardLogger ¶
type StandardLogger interface { Debug(args ...interface{}) Debugf(format string, args ...interface{}) Error(args ...interface{}) Errorf(format string, args ...interface{}) Fatal(args ...interface{}) Fatalf(format string, args ...interface{}) Info(args ...interface{}) Infof(format string, args ...interface{}) Panic(args ...interface{}) Panicf(format string, args ...interface{}) Warn(args ...interface{}) Warnf(format string, args ...interface{}) }
StandardLogger provides API compatibility with standard printf loggers eg. go-logging
type ZapEventLogger ¶
type ZapEventLogger struct { zap.SugaredLogger // contains filtered or unexported fields }
ZapEventLogger implements the EventLogger and wraps a go-logging Logger
func WithSkip ¶ added in v2.5.1
func WithSkip(l *ZapEventLogger, skip int) *ZapEventLogger
WithSkip returns a new logger that skips the specified number of stack frames when reporting the line/file.
func WithStacktrace ¶ added in v2.4.0
func WithStacktrace(l *ZapEventLogger, level LogLevel) *ZapEventLogger
func (*ZapEventLogger) LevelEnabled ¶ added in v2.8.1
func (logger *ZapEventLogger) LevelEnabled(level LogLevel) bool
LevelEnabled returns true if the LogLevel is enabled for the logger.
func (*ZapEventLogger) Warning ¶ added in v2.0.6
func (logger *ZapEventLogger) Warning(args ...interface{})
Warning is for compatibility Deprecated: use Warn(args ...interface{}) instead
func (*ZapEventLogger) Warningf ¶ added in v2.0.6
func (logger *ZapEventLogger) Warningf(format string, args ...interface{})
Warningf is for compatibility Deprecated: use Warnf(format string, args ...interface{}) instead