Documentation ¶
Overview ¶
Package log provides the both file and console (general) logging capabilities to spacemesh modules such as app and identity.
Package log is a generated GoMock package.
Index ¶
- Variables
- func Debug(msg string, args ...any)
- func ExtractRequestID(ctx context.Context) (string, bool)
- func ExtractSessionID(ctx context.Context) (string, bool)
- func Fatal(msg string, args ...any)
- func Info(msg string, args ...any)
- func JSONLog(b bool)
- func Panic(msg string, args ...any)
- func SetLogger(logger Log)
- func SetupGlobal(logger Log)
- func Warning(msg string, args ...any)
- func WithNewRequestID(ctx context.Context, fields ...LoggableField) context.Context
- func WithNewSessionID(ctx context.Context, fields ...LoggableField) context.Context
- func WithRequestID(ctx context.Context, requestID string, fields ...LoggableField) context.Context
- func WithSessionID(ctx context.Context, sessionID string, fields ...LoggableField) context.Context
- func ZContext(ctx context.Context) zap.Field
- func ZShortStringer(name string, val ShortString) zap.Field
- type ArrayEncoder
- type ArrayMarshaler
- type ArrayMarshalerFunc
- type Field
- func Any(key string, value any) Field
- func Array(name string, array ArrayMarshaler) Field
- func Binary(name string, val []byte) Field
- func Bool(name string, val bool) Field
- func Context(ctx context.Context) Field
- func Duration(name string, val time.Duration) Field
- func Err(err error) Field
- func FieldNamed(name string, field LoggableField) Field
- func Float64(name string, val float64) Field
- func Inline(object ObjectMarshaller) Field
- func Int(name string, val int) Field
- func Int32(name string, val int32) Field
- func Namespace(name string) Field
- func Object(namespace string, object ObjectMarshaller) Field
- func ShortStringer(name string, val ShortString) Field
- func String(name, val string) Field
- func Stringer(name string, val fmt.Stringer) Field
- func Time(name string, val time.Time) Field
- func Uint16(name string, val uint16) Field
- func Uint32(name string, val uint32) Field
- func Uint64(name string, val uint64) Field
- type FieldLogger
- func (fl FieldLogger) Debug(msg string, fields ...LoggableField)
- func (fl FieldLogger) Error(msg string, fields ...LoggableField)
- func (fl FieldLogger) Fatal(msg string, fields ...LoggableField)
- func (fl FieldLogger) Info(msg string, fields ...LoggableField)
- func (fl FieldLogger) Panic(msg string, fields ...LoggableField)
- func (fl FieldLogger) Warning(msg string, fields ...LoggableField)
- type Level
- type Log
- func (l Log) Check(level zapcore.Level) bool
- func (l Log) Core() zapcore.Core
- func (l Log) Debug(format string, args ...any)
- func (l Log) Error(format string, args ...any)
- func (l Log) Event() FieldLogger
- func (l Log) Fatal(format string, args ...any)
- func (l Log) Info(format string, args ...any)
- func (l Log) Named(name string) Log
- func (l Log) Panic(format string, args ...any)
- func (l Log) SetLevel(level *zap.AtomicLevel) Log
- func (l Log) Warning(format string, args ...any)
- func (l Log) With() FieldLogger
- func (l Log) WithContext(ctx context.Context) Log
- func (l Log) WithFields(fields ...LoggableField) Log
- func (l Log) WithName(prefix string) Log
- func (l Log) WithOptions(opts ...zap.Option) Log
- func (l Log) Zap() *zap.Logger
- type LoggableField
- type Logger
- type MockLogger
- func (m *MockLogger) Debug(format string, args ...any)
- func (m *MockLogger) EXPECT() *MockLoggerMockRecorder
- func (m *MockLogger) Error(format string, args ...any)
- func (m *MockLogger) Info(format string, args ...any)
- func (m *MockLogger) Panic(format string, args ...any)
- func (m *MockLogger) Warning(format string, args ...any)
- func (m *MockLogger) With() FieldLogger
- func (m *MockLogger) WithContext(arg0 context.Context) Log
- func (m *MockLogger) WithName(arg0 string) Log
- type MockLoggerDebugCall
- type MockLoggerErrorCall
- type MockLoggerInfoCall
- type MockLoggerMockRecorder
- func (mr *MockLoggerMockRecorder) Debug(format any, args ...any) *MockLoggerDebugCall
- func (mr *MockLoggerMockRecorder) Error(format any, args ...any) *MockLoggerErrorCall
- func (mr *MockLoggerMockRecorder) Info(format any, args ...any) *MockLoggerInfoCall
- func (mr *MockLoggerMockRecorder) Panic(format any, args ...any) *MockLoggerPanicCall
- func (mr *MockLoggerMockRecorder) Warning(format any, args ...any) *MockLoggerWarningCall
- func (mr *MockLoggerMockRecorder) With() *MockLoggerWithCall
- func (mr *MockLoggerMockRecorder) WithContext(arg0 any) *MockLoggerWithContextCall
- func (mr *MockLoggerMockRecorder) WithName(arg0 any) *MockLoggerWithNameCall
- type MockLoggerPanicCall
- type MockLoggerWarningCall
- type MockLoggerWithCall
- type MockLoggerWithContextCall
- type MockLoggerWithNameCall
- type ObjectEncoder
- type ObjectMarshaller
- type ObjectMarshallerFunc
- type ShortString
Constants ¶
This section is empty.
Variables ¶
var Named = FieldNamed
Named is an alias to FieldNamed. FieldNamed returns a field with the provided name instead of the default.
Functions ¶
func ExtractRequestID ¶ added in v0.1.27
ExtractRequestID extracts the request id from a context object.
func ExtractSessionID ¶ added in v0.1.27
ExtractSessionID extracts the session id from a context object.
func SetupGlobal ¶ added in v1.0.0
func SetupGlobal(logger Log)
SetupGlobal overwrites global logger.
func WithNewRequestID ¶ added in v0.1.27
func WithNewRequestID(ctx context.Context, fields ...LoggableField) context.Context
WithNewRequestID does the same thing as WithRequestID but generates a new, random requestId. It can be used when there isn't a single, clear, unique id associated with a request (e.g., a block or tx hash).
func WithNewSessionID ¶ added in v0.1.27
func WithNewSessionID(ctx context.Context, fields ...LoggableField) context.Context
WithNewSessionID does the same thing as WithSessionID but generates a new, random sessionId. It can be used when there isn't a single, clear, unique id associated with a session.
func WithRequestID ¶ added in v0.1.27
WithRequestID returns a context which knows its request ID. A request ID tracks the lifecycle of a single request across all execution contexts, including multiple goroutines, task queues, workers, etc. The canonical example is an incoming message received over the network. Rule of thumb: requests "traverse the heap" and may be passed from one session to another via channels. This requires a requestId string, and optionally, other LoggableFields that are added to context and printed in contextual logs.
func WithSessionID ¶ added in v0.1.27
WithSessionID returns a context which knows its session ID A session ID tracks a single thread of execution. This may include multiple goroutines running concurrently, but it does not include asynchronous task execution such as task queues handled in separate threads. The canonical example is a single protocol routine, down to the point where an incoming request is either handled, or else handed off to another routine via a channel. Rule of thumb: sessions live entirely on the stack, and never on the heap (and should not be passed over channels). This requires a sessionId string, and optionally, other LoggableFields that are added to context and printed in contextual logs.
func ZShortStringer ¶ added in v1.0.0
func ZShortStringer(name string, val ShortString) zap.Field
Types ¶
type ArrayEncoder ¶ added in v1.0.0
type ArrayEncoder = zapcore.ArrayEncoder
ArrayEncoder is an alias to zapcore.ArrayEncoder.
type ArrayMarshaler ¶ added in v1.0.0
type ArrayMarshaler = zapcore.ArrayMarshaler
ArrayMarshaler is an alias to zapcore.ArrayMarshaller.
type ArrayMarshalerFunc ¶ added in v1.0.0
type ArrayMarshalerFunc = zapcore.ArrayMarshalerFunc
ArrayMarshalerFunc is an alias to zapcore.ArrayMarshallerFunc.
type Field ¶
Field is a log field holding a name and value.
func Array ¶ added in v1.0.0
func Array(name string, array ArrayMarshaler) Field
Array for logging array efficiently.
func FieldNamed ¶ added in v0.1.15
func FieldNamed(name string, field LoggableField) Field
FieldNamed returns a field with the provided name instead of the default.
func Object ¶ added in v1.0.0
func Object(namespace string, object ObjectMarshaller) Field
Object for logging struct fields in namespace.
func ShortStringer ¶ added in v1.0.0
func ShortStringer(name string, val ShortString) Field
func (Field) AddTo ¶ added in v1.0.0
func (f Field) AddTo(enc ObjectEncoder)
type FieldLogger ¶ added in v0.1.11
type FieldLogger struct {
// contains filtered or unexported fields
}
FieldLogger is a logger that only logs messages with fields. It does not support formatting.
func (FieldLogger) Debug ¶ added in v0.1.11
func (fl FieldLogger) Debug(msg string, fields ...LoggableField)
Debug prints message with fields.
func (FieldLogger) Error ¶ added in v0.1.11
func (fl FieldLogger) Error(msg string, fields ...LoggableField)
Error prints message with fields.
func (FieldLogger) Fatal ¶ added in v1.0.0
func (fl FieldLogger) Fatal(msg string, fields ...LoggableField)
Fatal prints message with fields.
func (FieldLogger) Info ¶ added in v0.1.11
func (fl FieldLogger) Info(msg string, fields ...LoggableField)
Info prints message with fields.
func (FieldLogger) Panic ¶ added in v0.1.27
func (fl FieldLogger) Panic(msg string, fields ...LoggableField)
Panic prints message with fields.
func (FieldLogger) Warning ¶ added in v0.1.11
func (fl FieldLogger) Warning(msg string, fields ...LoggableField)
Warning prints message with fields.
type Level ¶ added in v0.1.11
Level is an alias to zapcore.Level.
func DefaultLevel ¶ added in v1.0.0
func DefaultLevel() Level
DefaultLevel returns the zapcore level of logging.
type Log ¶
type Log struct {
// contains filtered or unexported fields
}
Log is an exported type that embeds our logger.
var (
AppLog Log
)
AppLog is the local app singleton logger.
func NewDefault ¶
NewDefault creates a Log with the default log level.
func NewFromLog ¶ added in v0.1.15
NewFromLog creates a Log from an existing zap-compatible log.
func NewWithLevel ¶ added in v0.1.15
NewWithLevel creates a logger with a fixed level and with a set of (optional) hooks.
func RegisterHooks ¶ added in v1.0.0
RegisterHooks wraps provided loggers with hooks.
func (Log) Event ¶
func (l Log) Event() FieldLogger
Event returns a logger with the Event field appended to it.
func (Log) SetLevel ¶ added in v0.1.2
func (l Log) SetLevel(level *zap.AtomicLevel) Log
SetLevel returns a logger with level as the log level derived from l.
func (Log) WithContext ¶ added in v0.1.27
WithContext creates a Log from an existing log and a context object.
func (Log) WithFields ¶
func (l Log) WithFields(fields ...LoggableField) Log
WithFields returns a logger with fields permanently appended to it.
func (Log) WithOptions ¶
WithOptions clones the current Logger, applies the supplied Options, and returns the resulting Logger. It's safe to use concurrently.
type LoggableField ¶ added in v0.1.2
type LoggableField interface {
Field() Field
}
LoggableField as an interface to enable every type to be used as a log field.
func ExtractRequestFields ¶ added in v0.1.27
func ExtractRequestFields(ctx context.Context) (fields []LoggableField)
ExtractRequestFields extracts additional loggable fields associated with the request from a context object.
func ExtractSessionFields ¶ added in v0.1.27
func ExtractSessionFields(ctx context.Context) (fields []LoggableField)
ExtractSessionFields extracts additional loggable fields associated with the session from a context object.
type Logger ¶
type Logger interface { Info(format string, args ...any) Debug(format string, args ...any) Panic(format string, args ...any) Error(format string, args ...any) Warning(format string, args ...any) With() FieldLogger WithContext(context.Context) Log WithName(string) Log }
Logger is an interface for our logging API.
type MockLogger ¶ added in v1.0.0
type MockLogger struct {
// contains filtered or unexported fields
}
MockLogger is a mock of Logger interface.
func NewMockLogger ¶ added in v1.0.0
func NewMockLogger(ctrl *gomock.Controller) *MockLogger
NewMockLogger creates a new mock instance.
func (*MockLogger) Debug ¶ added in v1.0.0
func (m *MockLogger) Debug(format string, args ...any)
Debug mocks base method.
func (*MockLogger) EXPECT ¶ added in v1.0.0
func (m *MockLogger) EXPECT() *MockLoggerMockRecorder
EXPECT returns an object that allows the caller to indicate expected use.
func (*MockLogger) Error ¶ added in v1.0.0
func (m *MockLogger) Error(format string, args ...any)
Error mocks base method.
func (*MockLogger) Info ¶ added in v1.0.0
func (m *MockLogger) Info(format string, args ...any)
Info mocks base method.
func (*MockLogger) Panic ¶ added in v1.0.0
func (m *MockLogger) Panic(format string, args ...any)
Panic mocks base method.
func (*MockLogger) Warning ¶ added in v1.0.0
func (m *MockLogger) Warning(format string, args ...any)
Warning mocks base method.
func (*MockLogger) With ¶ added in v1.0.0
func (m *MockLogger) With() FieldLogger
With mocks base method.
func (*MockLogger) WithContext ¶ added in v1.0.0
func (m *MockLogger) WithContext(arg0 context.Context) Log
WithContext mocks base method.
func (*MockLogger) WithName ¶ added in v1.0.0
func (m *MockLogger) WithName(arg0 string) Log
WithName mocks base method.
type MockLoggerDebugCall ¶ added in v1.4.0
MockLoggerDebugCall wrap *gomock.Call
func (*MockLoggerDebugCall) Do ¶ added in v1.4.0
func (c *MockLoggerDebugCall) Do(f func(string, ...any)) *MockLoggerDebugCall
Do rewrite *gomock.Call.Do
func (*MockLoggerDebugCall) DoAndReturn ¶ added in v1.4.0
func (c *MockLoggerDebugCall) DoAndReturn(f func(string, ...any)) *MockLoggerDebugCall
DoAndReturn rewrite *gomock.Call.DoAndReturn
func (*MockLoggerDebugCall) Return ¶ added in v1.4.0
func (c *MockLoggerDebugCall) Return() *MockLoggerDebugCall
Return rewrite *gomock.Call.Return
type MockLoggerErrorCall ¶ added in v1.4.0
MockLoggerErrorCall wrap *gomock.Call
func (*MockLoggerErrorCall) Do ¶ added in v1.4.0
func (c *MockLoggerErrorCall) Do(f func(string, ...any)) *MockLoggerErrorCall
Do rewrite *gomock.Call.Do
func (*MockLoggerErrorCall) DoAndReturn ¶ added in v1.4.0
func (c *MockLoggerErrorCall) DoAndReturn(f func(string, ...any)) *MockLoggerErrorCall
DoAndReturn rewrite *gomock.Call.DoAndReturn
func (*MockLoggerErrorCall) Return ¶ added in v1.4.0
func (c *MockLoggerErrorCall) Return() *MockLoggerErrorCall
Return rewrite *gomock.Call.Return
type MockLoggerInfoCall ¶ added in v1.4.0
MockLoggerInfoCall wrap *gomock.Call
func (*MockLoggerInfoCall) Do ¶ added in v1.4.0
func (c *MockLoggerInfoCall) Do(f func(string, ...any)) *MockLoggerInfoCall
Do rewrite *gomock.Call.Do
func (*MockLoggerInfoCall) DoAndReturn ¶ added in v1.4.0
func (c *MockLoggerInfoCall) DoAndReturn(f func(string, ...any)) *MockLoggerInfoCall
DoAndReturn rewrite *gomock.Call.DoAndReturn
func (*MockLoggerInfoCall) Return ¶ added in v1.4.0
func (c *MockLoggerInfoCall) Return() *MockLoggerInfoCall
Return rewrite *gomock.Call.Return
type MockLoggerMockRecorder ¶ added in v1.0.0
type MockLoggerMockRecorder struct {
// contains filtered or unexported fields
}
MockLoggerMockRecorder is the mock recorder for MockLogger.
func (*MockLoggerMockRecorder) Debug ¶ added in v1.0.0
func (mr *MockLoggerMockRecorder) Debug(format any, args ...any) *MockLoggerDebugCall
Debug indicates an expected call of Debug.
func (*MockLoggerMockRecorder) Error ¶ added in v1.0.0
func (mr *MockLoggerMockRecorder) Error(format any, args ...any) *MockLoggerErrorCall
Error indicates an expected call of Error.
func (*MockLoggerMockRecorder) Info ¶ added in v1.0.0
func (mr *MockLoggerMockRecorder) Info(format any, args ...any) *MockLoggerInfoCall
Info indicates an expected call of Info.
func (*MockLoggerMockRecorder) Panic ¶ added in v1.0.0
func (mr *MockLoggerMockRecorder) Panic(format any, args ...any) *MockLoggerPanicCall
Panic indicates an expected call of Panic.
func (*MockLoggerMockRecorder) Warning ¶ added in v1.0.0
func (mr *MockLoggerMockRecorder) Warning(format any, args ...any) *MockLoggerWarningCall
Warning indicates an expected call of Warning.
func (*MockLoggerMockRecorder) With ¶ added in v1.0.0
func (mr *MockLoggerMockRecorder) With() *MockLoggerWithCall
With indicates an expected call of With.
func (*MockLoggerMockRecorder) WithContext ¶ added in v1.0.0
func (mr *MockLoggerMockRecorder) WithContext(arg0 any) *MockLoggerWithContextCall
WithContext indicates an expected call of WithContext.
func (*MockLoggerMockRecorder) WithName ¶ added in v1.0.0
func (mr *MockLoggerMockRecorder) WithName(arg0 any) *MockLoggerWithNameCall
WithName indicates an expected call of WithName.
type MockLoggerPanicCall ¶ added in v1.4.0
MockLoggerPanicCall wrap *gomock.Call
func (*MockLoggerPanicCall) Do ¶ added in v1.4.0
func (c *MockLoggerPanicCall) Do(f func(string, ...any)) *MockLoggerPanicCall
Do rewrite *gomock.Call.Do
func (*MockLoggerPanicCall) DoAndReturn ¶ added in v1.4.0
func (c *MockLoggerPanicCall) DoAndReturn(f func(string, ...any)) *MockLoggerPanicCall
DoAndReturn rewrite *gomock.Call.DoAndReturn
func (*MockLoggerPanicCall) Return ¶ added in v1.4.0
func (c *MockLoggerPanicCall) Return() *MockLoggerPanicCall
Return rewrite *gomock.Call.Return
type MockLoggerWarningCall ¶ added in v1.4.0
MockLoggerWarningCall wrap *gomock.Call
func (*MockLoggerWarningCall) Do ¶ added in v1.4.0
func (c *MockLoggerWarningCall) Do(f func(string, ...any)) *MockLoggerWarningCall
Do rewrite *gomock.Call.Do
func (*MockLoggerWarningCall) DoAndReturn ¶ added in v1.4.0
func (c *MockLoggerWarningCall) DoAndReturn(f func(string, ...any)) *MockLoggerWarningCall
DoAndReturn rewrite *gomock.Call.DoAndReturn
func (*MockLoggerWarningCall) Return ¶ added in v1.4.0
func (c *MockLoggerWarningCall) Return() *MockLoggerWarningCall
Return rewrite *gomock.Call.Return
type MockLoggerWithCall ¶ added in v1.4.0
MockLoggerWithCall wrap *gomock.Call
func (*MockLoggerWithCall) Do ¶ added in v1.4.0
func (c *MockLoggerWithCall) Do(f func() FieldLogger) *MockLoggerWithCall
Do rewrite *gomock.Call.Do
func (*MockLoggerWithCall) DoAndReturn ¶ added in v1.4.0
func (c *MockLoggerWithCall) DoAndReturn(f func() FieldLogger) *MockLoggerWithCall
DoAndReturn rewrite *gomock.Call.DoAndReturn
func (*MockLoggerWithCall) Return ¶ added in v1.4.0
func (c *MockLoggerWithCall) Return(arg0 FieldLogger) *MockLoggerWithCall
Return rewrite *gomock.Call.Return
type MockLoggerWithContextCall ¶ added in v1.4.0
MockLoggerWithContextCall wrap *gomock.Call
func (*MockLoggerWithContextCall) Do ¶ added in v1.4.0
func (c *MockLoggerWithContextCall) Do(f func(context.Context) Log) *MockLoggerWithContextCall
Do rewrite *gomock.Call.Do
func (*MockLoggerWithContextCall) DoAndReturn ¶ added in v1.4.0
func (c *MockLoggerWithContextCall) DoAndReturn(f func(context.Context) Log) *MockLoggerWithContextCall
DoAndReturn rewrite *gomock.Call.DoAndReturn
func (*MockLoggerWithContextCall) Return ¶ added in v1.4.0
func (c *MockLoggerWithContextCall) Return(arg0 Log) *MockLoggerWithContextCall
Return rewrite *gomock.Call.Return
type MockLoggerWithNameCall ¶ added in v1.4.0
MockLoggerWithNameCall wrap *gomock.Call
func (*MockLoggerWithNameCall) Do ¶ added in v1.4.0
func (c *MockLoggerWithNameCall) Do(f func(string) Log) *MockLoggerWithNameCall
Do rewrite *gomock.Call.Do
func (*MockLoggerWithNameCall) DoAndReturn ¶ added in v1.4.0
func (c *MockLoggerWithNameCall) DoAndReturn(f func(string) Log) *MockLoggerWithNameCall
DoAndReturn rewrite *gomock.Call.DoAndReturn
func (*MockLoggerWithNameCall) Return ¶ added in v1.4.0
func (c *MockLoggerWithNameCall) Return(arg0 Log) *MockLoggerWithNameCall
Return rewrite *gomock.Call.Return
type ObjectEncoder ¶ added in v1.0.0
type ObjectEncoder = zapcore.ObjectEncoder
ObjectEncoder is an alias to zapcore.ObjectEncoder.
type ObjectMarshaller ¶ added in v1.0.0
type ObjectMarshaller = zapcore.ObjectMarshaler
ObjectMarshaller is an alias to zapcore.ObjectMarshaller.
type ObjectMarshallerFunc ¶ added in v1.0.0
type ObjectMarshallerFunc = zapcore.ObjectMarshalerFunc
ObjectMarshallerFunc is an alias to zapcore.ObjectMarshallerFunc.
type ShortString ¶ added in v1.0.0
type ShortString interface {
ShortString() string
}