logutil

package
v2.284.6 Latest Latest
Warning

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

Go to latest
Published: May 20, 2021 License: Apache-2.0, MIT Imports: 13 Imported by: 0

Documentation

Overview

Example (Logall)
package main

import (
	"berty.tech/berty/v2/go/internal/logutil"
)

func main() {
	logger, cleanup, err := logutil.NewLogger(logutil.NewStdStream("*", "light-console", "stdout"))
	if err != nil {
		panic(err)
	}
	defer cleanup()

	logger.Debug("top debug")
	logger.Info("top info")
	logger.Warn("top warn")
	logger.Error("top error")

	logger.Named("foo").Debug("foo debug")
	logger.Named("foo").Info("foo info")
	logger.Named("foo").Warn("foo warn")
	logger.Named("foo").Error("foo error")

}
Output:

DEBUG	bty               	logutil/example_test.go:14	top debug
INFO 	bty               	logutil/example_test.go:15	top info
WARN 	bty               	logutil/example_test.go:16	top warn
ERROR	bty               	logutil/example_test.go:17	top error
DEBUG	bty.foo           	logutil/example_test.go:19	foo debug
INFO 	bty.foo           	logutil/example_test.go:20	foo info
WARN 	bty.foo           	logutil/example_test.go:21	foo warn
ERROR	bty.foo           	logutil/example_test.go:22	foo error
Example (Logerrors)
package main

import (
	"berty.tech/berty/v2/go/internal/logutil"
)

func main() {
	logger, cleanup, err := logutil.NewLogger(logutil.NewStdStream("error:*,-*.bar warn:*.bar", "light-console", "stdout"))
	if err != nil {
		panic(err)
	}
	defer cleanup()

	logger.Debug("top debug")
	logger.Info("top info")
	logger.Warn("top warn")
	logger.Error("top error")

	logger.Named("foo").Debug("foo debug")
	logger.Named("foo").Info("foo info")
	logger.Named("foo").Warn("foo warn")
	logger.Named("foo").Error("foo error")

	logger.Named("foo").Named("bar").Debug("foo.bar debug")
	logger.Named("foo").Named("bar").Info("foo.bar info")
	logger.Named("foo").Named("bar").Warn("foo.bar warn")
	logger.Named("foo").Named("bar").Error("foo.bar error")

}
Output:

ERROR	bty               	logutil/example_test.go:45	top error
ERROR	bty.foo           	logutil/example_test.go:50	foo error
WARN 	bty.foo.bar       	logutil/example_test.go:54	foo.bar warn

Index

Examples

Constants

View Source
const (
	Black uint8 = iota + 30
	Red
	Green
	Yellow
	Blue
	Magenta
	Cyan
	White
)

Variables

This section is empty.

Functions

func DecorateLogger

func DecorateLogger(base *zap.Logger, filters string) (*zap.Logger, func(), error)

DecorateLogger can be used by external packages to configure zapfilter and libp2p logging on an existing zap.Logger.

func NewLogger

func NewLogger(streams ...Stream) (*zap.Logger, func(), error)

Types

type Stream added in v2.264.0

type Stream struct {
	// contains filtered or unexported fields
}

func NewLumberjackStream added in v2.264.0

func NewLumberjackStream(filters, format string, opts *lumberjack.Logger) Stream

func NewRingStream added in v2.264.0

func NewRingStream(filters, format string, ring *zapring.Core) Stream

func NewStdStream added in v2.264.0

func NewStdStream(filters, format, path string) Stream

Jump to

Keyboard shortcuts

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