logutil

package
v2.434.7 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2022 License: Apache-2.0, MIT Imports: 22 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 CurrentLogfilePath added in v2.420.0

func CurrentLogfilePath(target string) (string, error)

func DisablePrivateFields added in v2.367.0

func DisablePrivateFields()

func LogfileGC added in v2.286.0

func LogfileGC(logDir string, max int) error

func NewLogger

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

func PrivateAny added in v2.326.0

func PrivateAny(key string, value interface{}) zap.Field

func PrivateBinary added in v2.326.0

func PrivateBinary(key string, value []byte) zap.Field

func PrivateString added in v2.326.0

func PrivateString(key string, value string) zap.Field

func PrivateStringer added in v2.414.0

func PrivateStringer(key string, value fmt.Stringer) zap.Field

func PrivateStrings added in v2.326.0

func PrivateStrings(key string, value []string) zap.Field

func ReplaceGRPCLogger added in v2.350.0

func ReplaceGRPCLogger(l *zap.Logger)

func SetGlobal added in v2.326.0

func SetGlobal(namespace []byte, enabled bool)

Types

type Logfile added in v2.286.0

type Logfile struct {
	Dir    string
	Name   string
	Size   int64
	Kind   string
	Time   time.Time
	Latest bool
	Errs   error `json:"Errs,omitempty"`
}

func LogfileList added in v2.286.0

func LogfileList(logDir string) ([]*Logfile, error)

func (Logfile) Path added in v2.286.0

func (l Logfile) Path() string

type PrivateField added in v2.326.0

type PrivateField struct {
	Namespace []byte
	Enabled   bool
}

func (*PrivateField) PrivateAny added in v2.326.0

func (p *PrivateField) PrivateAny(key string, value interface{}) zap.Field

func (*PrivateField) PrivateBinary added in v2.326.0

func (p *PrivateField) PrivateBinary(key string, value []byte) zap.Field

func (*PrivateField) PrivateString added in v2.326.0

func (p *PrivateField) PrivateString(key string, value string) zap.Field

func (*PrivateField) PrivateStringer added in v2.414.0

func (p *PrivateField) PrivateStringer(key string, value fmt.Stringer) zap.Field

func (*PrivateField) PrivateStrings added in v2.326.0

func (p *PrivateField) PrivateStrings(key string, values []string) zap.Field

type Stream added in v2.264.0

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

func NewCustomStream added in v2.287.0

func NewCustomStream(filters string, logger *zap.Logger) Stream

func NewFileStream added in v2.286.0

func NewFileStream(filters, format, path, sessionKind string) Stream

NewFileStream creates a new file stream backed by Lumberjack with sane default values.

Usually, Lumberjack is used as a rolling log file and is intended to be reused from a session to another, In Berty, we want one file per session named with the start time instead of the rotation time.

If the provided path is a directory, it will create files in that directory with the following pattern: `<path>/<session-kind>-<start-time>.log`.

If the provided path is a path finishing with ".log", then, the path will be taken as it, instead of creating a new file, it will append new lines to the existing one; this can be particularly useful to keep a `tail -f` running.

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