logging

package
v1.10.17-rc.3 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2023 License: BSD-3-Clause Imports: 15 Imported by: 462

Documentation

Overview

Package logging is a generated GoMock package.

Index

Constants

This section is empty.

Variables

View Source
var (
	// Discard is a mock WriterCloser that drops all writes and close requests
	Discard io.WriteCloser = discard{}
)
View Source
var ErrUnknownLevel = errors.New("unknown log level")

Functions

func UserString added in v1.7.17

func UserString(key, val string) zap.Field

UserString constructs a field with the given key and the value stripped of newlines. The value is sanitized lazily.

func UserStrings added in v1.7.17

func UserStrings(key string, val []string) zap.Field

UserStrings constructs a field with the given key and the values stripped of newlines. The values are sanitized lazily.

Types

type Color

type Color string
const (
	Black       Color = "\033[0;30m"
	DarkGray    Color = "\033[1;30m"
	Red         Color = "\033[0;31m"
	LightRed    Color = "\033[1;31m"
	Green       Color = "\033[0;32m"
	LightGreen  Color = "\033[1;32m"
	Orange      Color = "\033[0;33m"
	Yellow      Color = "\033[1;33m"
	Blue        Color = "\033[0;34m"
	LightBlue   Color = "\033[1;34m"
	Purple      Color = "\033[0;35m"
	LightPurple Color = "\033[1;35m"
	Cyan        Color = "\033[0;36m"
	LightCyan   Color = "\033[1;36m"
	LightGray   Color = "\033[0;37m"
	White       Color = "\033[1;37m"

	Reset   Color = "\033[0;0m"
	Bold    Color = "\033[;1m"
	Reverse Color = "\033[;7m"
)

Colors

func (Color) Wrap

func (lc Color) Wrap(text string) string

type Config

type Config struct {
	RotatingWriterConfig
	DisableWriterDisplaying bool   `json:"disableWriterDisplaying"`
	LogLevel                Level  `json:"logLevel"`
	DisplayLevel            Level  `json:"displayLevel"`
	LogFormat               Format `json:"logFormat"`
	MsgPrefix               string `json:"-"`
	LoggerName              string `json:"-"`
}

Config defines the configuration of a logger

type Factory

type Factory interface {
	// Make creates a new logger with name [name]
	Make(name string) (Logger, error)

	// MakeChain creates a new logger to log the events of chain [chainID]
	MakeChain(chainID string) (Logger, error)

	// SetLogLevels sets log levels for all loggers in factory with given logger name, level pairs.
	SetLogLevel(name string, level Level) error

	// SetDisplayLevels sets log display levels for all loggers in factory with given logger name, level pairs.
	SetDisplayLevel(name string, level Level) error

	// GetLogLevels returns all log levels in factory as name, level pairs
	GetLogLevel(name string) (Level, error)

	// GetDisplayLevels returns all log display levels in factory as name, level pairs
	GetDisplayLevel(name string) (Level, error)

	// GetLoggerNames returns the names of all logs created by this factory
	GetLoggerNames() []string

	// Close stops and clears all of a Factory's instantiated loggers
	Close()
}

Factory creates new instances of different types of Logger

func NewFactory

func NewFactory(config Config) Factory

NewFactory returns a new instance of a Factory producing loggers configured with the values set in the [config] parameter

type Format added in v1.7.11

type Format int

Highlight mode to apply to displayed logs

const (
	Plain Format = iota
	Colors
	JSON
)

Format modes available

func ToFormat added in v1.7.11

func ToFormat(h string, fd uintptr) (Format, error)

ToFormat chooses a highlighting mode

func (Format) ConsoleEncoder added in v1.7.11

func (f Format) ConsoleEncoder() zapcore.Encoder

func (Format) FileEncoder added in v1.7.11

func (f Format) FileEncoder() zapcore.Encoder

func (Format) MarshalJSON added in v1.7.11

func (f Format) MarshalJSON() ([]byte, error)

func (Format) WrapPrefix added in v1.7.11

func (f Format) WrapPrefix(prefix string) string

type Level

type Level zapcore.Level
const (
	Verbo Level = iota - 9
	Debug
	Trace
	Info
	Warn
	Error
	Fatal
	Off
)

func ToLevel

func ToLevel(l string) (Level, error)

Inverse of Level.String()

func (Level) LowerString added in v1.7.11

func (l Level) LowerString() string

func (Level) MarshalJSON added in v1.5.0

func (l Level) MarshalJSON() ([]byte, error)

func (Level) String

func (l Level) String() string

func (*Level) UnmarshalJSON added in v1.5.0

func (l *Level) UnmarshalJSON(b []byte) error

type Logger

type Logger interface {
	io.Writer // For logging pre-formatted messages

	// Log that a fatal error has occurred. The program should likely exit soon
	// after this is called
	Fatal(msg string, fields ...zap.Field)
	// Log that an error has occurred. The program should be able to recover
	// from this error
	Error(msg string, fields ...zap.Field)
	// Log that an event has occurred that may indicate a future error or
	// vulnerability
	Warn(msg string, fields ...zap.Field)
	// Log an event that may be useful for a user to see to measure the progress
	// of the protocol
	Info(msg string, fields ...zap.Field)
	// Log an event that may be useful for understanding the order of the
	// execution of the protocol
	Trace(msg string, fields ...zap.Field)
	// Log an event that may be useful for a programmer to see when debuging the
	// execution of the protocol
	Debug(msg string, fields ...zap.Field)
	// Log extremely detailed events that can be useful for inspecting every
	// aspect of the program
	Verbo(msg string, fields ...zap.Field)

	// SetLevel that this logger should log to
	SetLevel(level Level)
	// Enabled returns true if the given level is at or above this level.
	Enabled(lvl Level) bool

	// Recovers a panic, logs the error, and rethrows the panic.
	StopOnPanic()
	// If a function panics, this will log that panic and then re-panic ensuring
	// that the program logs the error before exiting.
	RecoverAndPanic(f func())

	// If a function panics, this will log that panic and then call the exit
	// function, ensuring that the program logs the error, recovers, and
	// executes the desired exit function
	RecoverAndExit(f, exit func())

	// Stop this logger and write back all meta-data.
	Stop()
}

Logger defines the interface that is used to keep a record of all events that happen to the program

func NewLogger added in v1.7.11

func NewLogger(prefix string, wrappedCores ...WrappedCore) Logger

New returns a new logger set up according to [config]

type MockLogger added in v1.7.6

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

MockLogger is a mock of Logger interface.

func NewMockLogger added in v1.7.6

func NewMockLogger(ctrl *gomock.Controller) *MockLogger

NewMockLogger creates a new mock instance.

func (*MockLogger) Debug added in v1.7.6

func (m *MockLogger) Debug(arg0 string, arg1 ...zapcore.Field)

Debug mocks base method.

func (*MockLogger) EXPECT added in v1.7.6

func (m *MockLogger) EXPECT() *MockLoggerMockRecorder

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockLogger) Enabled added in v1.10.2

func (m *MockLogger) Enabled(arg0 Level) bool

Enabled mocks base method.

func (*MockLogger) Error added in v1.7.6

func (m *MockLogger) Error(arg0 string, arg1 ...zapcore.Field)

Error mocks base method.

func (*MockLogger) Fatal added in v1.7.6

func (m *MockLogger) Fatal(arg0 string, arg1 ...zapcore.Field)

Fatal mocks base method.

func (*MockLogger) Info added in v1.7.6

func (m *MockLogger) Info(arg0 string, arg1 ...zapcore.Field)

Info mocks base method.

func (*MockLogger) RecoverAndExit added in v1.7.6

func (m *MockLogger) RecoverAndExit(arg0, arg1 func())

RecoverAndExit mocks base method.

func (*MockLogger) RecoverAndPanic added in v1.7.6

func (m *MockLogger) RecoverAndPanic(arg0 func())

RecoverAndPanic mocks base method.

func (*MockLogger) SetLevel added in v1.9.6

func (m *MockLogger) SetLevel(arg0 Level)

SetLevel mocks base method.

func (*MockLogger) Stop added in v1.7.6

func (m *MockLogger) Stop()

Stop mocks base method.

func (*MockLogger) StopOnPanic added in v1.7.6

func (m *MockLogger) StopOnPanic()

StopOnPanic mocks base method.

func (*MockLogger) Trace added in v1.7.6

func (m *MockLogger) Trace(arg0 string, arg1 ...zapcore.Field)

Trace mocks base method.

func (*MockLogger) Verbo added in v1.7.6

func (m *MockLogger) Verbo(arg0 string, arg1 ...zapcore.Field)

Verbo mocks base method.

func (*MockLogger) Warn added in v1.7.6

func (m *MockLogger) Warn(arg0 string, arg1 ...zapcore.Field)

Warn mocks base method.

func (*MockLogger) Write added in v1.7.6

func (m *MockLogger) Write(arg0 []byte) (int, error)

Write mocks base method.

type MockLoggerMockRecorder added in v1.7.6

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

MockLoggerMockRecorder is the mock recorder for MockLogger.

func (*MockLoggerMockRecorder) Debug added in v1.7.6

func (mr *MockLoggerMockRecorder) Debug(arg0 interface{}, arg1 ...interface{}) *gomock.Call

Debug indicates an expected call of Debug.

func (*MockLoggerMockRecorder) Enabled added in v1.10.2

func (mr *MockLoggerMockRecorder) Enabled(arg0 interface{}) *gomock.Call

Enabled indicates an expected call of Enabled.

func (*MockLoggerMockRecorder) Error added in v1.7.6

func (mr *MockLoggerMockRecorder) Error(arg0 interface{}, arg1 ...interface{}) *gomock.Call

Error indicates an expected call of Error.

func (*MockLoggerMockRecorder) Fatal added in v1.7.6

func (mr *MockLoggerMockRecorder) Fatal(arg0 interface{}, arg1 ...interface{}) *gomock.Call

Fatal indicates an expected call of Fatal.

func (*MockLoggerMockRecorder) Info added in v1.7.6

func (mr *MockLoggerMockRecorder) Info(arg0 interface{}, arg1 ...interface{}) *gomock.Call

Info indicates an expected call of Info.

func (*MockLoggerMockRecorder) RecoverAndExit added in v1.7.6

func (mr *MockLoggerMockRecorder) RecoverAndExit(arg0, arg1 interface{}) *gomock.Call

RecoverAndExit indicates an expected call of RecoverAndExit.

func (*MockLoggerMockRecorder) RecoverAndPanic added in v1.7.6

func (mr *MockLoggerMockRecorder) RecoverAndPanic(arg0 interface{}) *gomock.Call

RecoverAndPanic indicates an expected call of RecoverAndPanic.

func (*MockLoggerMockRecorder) SetLevel added in v1.9.6

func (mr *MockLoggerMockRecorder) SetLevel(arg0 interface{}) *gomock.Call

SetLevel indicates an expected call of SetLevel.

func (*MockLoggerMockRecorder) Stop added in v1.7.6

func (mr *MockLoggerMockRecorder) Stop() *gomock.Call

Stop indicates an expected call of Stop.

func (*MockLoggerMockRecorder) StopOnPanic added in v1.7.6

func (mr *MockLoggerMockRecorder) StopOnPanic() *gomock.Call

StopOnPanic indicates an expected call of StopOnPanic.

func (*MockLoggerMockRecorder) Trace added in v1.7.6

func (mr *MockLoggerMockRecorder) Trace(arg0 interface{}, arg1 ...interface{}) *gomock.Call

Trace indicates an expected call of Trace.

func (*MockLoggerMockRecorder) Verbo added in v1.7.6

func (mr *MockLoggerMockRecorder) Verbo(arg0 interface{}, arg1 ...interface{}) *gomock.Call

Verbo indicates an expected call of Verbo.

func (*MockLoggerMockRecorder) Warn added in v1.7.6

func (mr *MockLoggerMockRecorder) Warn(arg0 interface{}, arg1 ...interface{}) *gomock.Call

Warn indicates an expected call of Warn.

func (*MockLoggerMockRecorder) Write added in v1.7.6

func (mr *MockLoggerMockRecorder) Write(arg0 interface{}) *gomock.Call

Write indicates an expected call of Write.

type NoLog

type NoLog struct{}

func (NoLog) Debug

func (NoLog) Debug(string, ...zap.Field)

func (NoLog) Enabled added in v1.10.2

func (NoLog) Enabled(Level) bool

func (NoLog) Error

func (NoLog) Error(string, ...zap.Field)

func (NoLog) Fatal

func (NoLog) Fatal(string, ...zap.Field)

func (NoLog) Info

func (NoLog) Info(string, ...zap.Field)

func (NoLog) RecoverAndExit added in v0.8.0

func (NoLog) RecoverAndExit(f, exit func())

func (NoLog) RecoverAndPanic

func (NoLog) RecoverAndPanic(f func())

func (NoLog) SetLevel added in v1.9.6

func (NoLog) SetLevel(Level)

func (NoLog) Stop

func (NoLog) Stop()

func (NoLog) StopOnPanic

func (NoLog) StopOnPanic()

func (NoLog) Trace added in v1.4.9

func (NoLog) Trace(string, ...zap.Field)

func (NoLog) Verbo

func (NoLog) Verbo(string, ...zap.Field)

func (NoLog) Warn

func (NoLog) Warn(string, ...zap.Field)

func (NoLog) Write

func (NoLog) Write(b []byte) (int, error)

type NoWarn added in v1.7.18

type NoWarn struct{ NoLog }

func (NoWarn) Error added in v1.7.18

func (NoWarn) Error(string, ...zap.Field)

func (NoWarn) Fatal added in v1.7.18

func (NoWarn) Fatal(string, ...zap.Field)

func (NoWarn) Warn added in v1.7.18

func (NoWarn) Warn(string, ...zap.Field)

type RotatingWriterConfig added in v1.7.11

type RotatingWriterConfig struct {
	MaxSize   int    `json:"maxSize"` // in megabytes
	MaxFiles  int    `json:"maxFiles"`
	MaxAge    int    `json:"maxAge"` // in days
	Directory string `json:"directory"`
	Compress  bool   `json:"compress"`
}

type WrappedCore added in v1.7.11

type WrappedCore struct {
	Core           zapcore.Core
	Writer         io.WriteCloser
	WriterDisabled bool
	AtomicLevel    zap.AtomicLevel
}

func NewWrappedCore added in v1.7.11

func NewWrappedCore(level Level, rw io.WriteCloser, encoder zapcore.Encoder) WrappedCore

Jump to

Keyboard shortcuts

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