logger

package
v1.1.20 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package log is the logging library used by IPFS & libp2p (https://github.com/ipfs/go-ipfs).

Index

Constants

This section is empty.

Variables

View Source
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)
)
View Source
var ErrNoSuchLogger = errors.New("error: No such logger")

ErrNoSuchLogger is returned when the util pkg is asked for a non existant logger

Functions

func Debug

func Debug(args ...interface{})

func Debugf

func Debugf(template string, args ...interface{})

func Error

func Error(args ...interface{})

func Errorf

func Errorf(template string, args ...interface{})

func Fatal

func Fatal(args ...interface{})

func Fatalf

func Fatalf(template string, args ...interface{})

func FormatRFC3339 added in v1.0.10

func FormatRFC3339(t time.Time) string

FormatRFC3339 returns the given time in UTC with RFC3999Nano format.

func GetSubsystems added in v1.0.10

func GetSubsystems() map[string]string

GetSubsystems returns a map containing the name/level of the current loggers

func Info

func Info(args ...interface{})

func Infof

func Infof(template string, args ...interface{})

func SetAllLoggers added in v1.0.10

func SetAllLoggers(lvl LogLevel)

SetAllLoggers changes the logging level of all loggers to lvl

func SetDebugLogging added in v1.0.10

func SetDebugLogging()

SetDebugLogging calls SetAllLoggers with logging.DEBUG

func SetLogLevel added in v1.0.10

func SetLogLevel(name, level string) error

SetLogLevel changes the log level of a specific subsystem name=="*" changes all subsystems

func SetLogLevelRegex added in v1.0.10

func SetLogLevelRegex(e, l string) error

SetLogLevelRegex sets all loggers to level `l` that match expression `e`. An error is returned if `e` fails to compile.

func SetPrimaryCore added in v1.0.10

func SetPrimaryCore(core zapcore.Core)

SetPrimaryCore changes the primary logging core. If the SetupLogging was called then the previously configured core will be replaced.

func SetupLogging added in v1.0.10

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 Warn

func Warn(args ...interface{})

func Warnf

func Warnf(template string, args ...interface{})

Types

type Config added in v1.0.10

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 KLogger

type KLogger struct {
	zap.SugaredLogger
	// contains filtered or unexported fields
}

KLogger implements the StandardLogger interface

var (
	// DefaultLogger logger
	DefaultLogger *KLogger
)

func Logger

func Logger(system string) *KLogger

Logger retrieves an event logger by name

func (*KLogger) WithCallerSkip added in v1.0.10

func (h *KLogger) WithCallerSkip(skip int) *KLogger

func (*KLogger) WithError

func (h *KLogger) WithError(err error) *KLogger

func (*KLogger) WithFields

func (h *KLogger) WithFields(args ...interface{}) *KLogger

type LogFormat added in v1.0.10

type LogFormat int
const (
	ColorizedOutput LogFormat = iota
	PlaintextOutput
	JSONOutput
)

type LogLevel added in v1.0.10

type LogLevel zapcore.Level

LogLevel represents a log severity level. Use the package variables as an enum.

func LevelFromString added in v1.0.10

func LevelFromString(level string) (LogLevel, error)

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.

type StandardLogger added in v1.0.10

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

Jump to

Keyboard shortcuts

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