log

package module
v2.5.1 Latest Latest
Warning

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

Go to latest
Published: May 15, 2020 License: MIT Imports: 10 Imported by: 0

README

go-log

The logging library used by go-btfs

go-log wraps zap to provide a logging facade. go-log manages logging instances and allows for their levels to be controlled individually.

Install

go get github.com/TRON-US/go-log

Usage

Once the package is imported under the name logging, an instance of EventLogger can be created like so:

var log = logging.Logger("subsystem name")

It can then be used to emit log messages in plain printf-style messages at seven standard levels:

Levels may be set for all loggers:

lvl, err := logging.LevelFromString("error")
  if err != nil {
    panic(err)
  }
logging.SetAllLoggers(lvl)

or individually:

lvl, err := logging.LevelFromString("error")
  if err != nil {
    panic(err)
  }
logging.SetLogLevel("foo", "info")

Contribute

PRs are welcome!

License

MIT @ TRON-US

Documentation

Overview

Package log is the logging library used by IPFS (https://github.com/ipfs/go-ipfs). It uses a modified version of https://godoc.org/github.com/whyrusleeping/go-logging .

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 FormatRFC3339

func FormatRFC3339(t time.Time) string

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

func SetLogLevel(name, level string) error

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

func SetLogLevelRegex

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 SetupLogging

func SetupLogging()

Types

type EventLogger

type EventLogger interface {
	StandardLogger
}

EventLogger extends the StandardLogger interface to allow for log items containing structured metadata

type LogLevel

type LogLevel zapcore.Level

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

func LevelFromString

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

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 Logger

func Logger(system string) *ZapEventLogger

Logger retrieves an event logger by name

func LoggerWithChannel

func LoggerWithChannel(system string, outChan chan []logclient.Entry) *ZapEventLogger

Jump to

Keyboard shortcuts

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