mirror of
https://github.com/hanzo-fi/go-libs.git
synced 2026-10-30 20:53:44 +00:00
* feat(logging): add Trace level to Logger Add a TraceLevel constant (value -1, more verbose than Debug) and Trace/Tracef methods to the Logger interface. Trace is intended for per-event/per-request logging that is too noisy for Debug. - TraceLevel is exposed alongside Debug/Info/Error in the Level enum. - LogrusLogger forwards Trace/Tracef to logrus's native Trace level. - NewDefaultLoggerWithLevel lets callers pick a precise level (the existing NewDefaultLogger(w, debug, ...) wrapper is preserved for backward compatibility). - ParseLevel(string) and Level.String() are added for CLI parsing and structured logging. - Package-level Trace/Tracef helpers mirror the existing Debug/Info helpers and delegate to FromContext. - The generated mock is updated; the local mockLogger in pkg/authn/licence/licence_test.go now implements Trace/Tracef. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * feat(logging): add ZapLogger adapter with Trace support Add a zap-backed implementation of the Logger interface, mirroring the existing LogrusLogger but built on go.uber.org/zap. Trace records are emitted at a custom zapcore.Level (-2, below DebugLevel) so cores that opt out of Trace — typically OTel exporter bridges wrapped with MinLevelCore — silently drop them. Public surface: - ZapLogger struct, NewZap(sugar), NopZap() — drop-in Logger backed by *zap.SugaredLogger. - (*ZapLogger).Zap() exposes the underlying *zap.Logger for libraries that require it directly (etcd WAL, gRPC instrumentation, ...). - ToZapLevel(Level) and EncodeLevelWithTrace(base) help build pipelines that handle the custom Trace level correctly. - MinLevelCore wraps a zapcore.Core to enforce a minimum level — meant to keep Trace records off the OTel bridge while letting them flow to the console core. This backport unblocks services (ledger-v3) that already maintain a local copy of this adapter; centralising it here avoids divergence and keeps the Trace semantics consistent across the platform. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * chore(logging): regenerate mock to match mockgen output The hand-edited mock placed Trace/Tracef before Writer instead of in the order mockgen produces. Running `go generate ./...` in CI flagged the diff via the "Dirty" check. Regenerated via mockgen to match. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * test(logging): cover Trace level, ParseLevel, and MinLevelCore Add unit tests for the new public surface so codecov picks up the patch coverage: - ParseLevel: accepts trace|debug|info|error case-insensitively, rejects unknown strings. - Level.String: round-trips the supported levels and falls back to a readable form for unknown values. - ZapLogger: Trace records are emitted when the configured level is TraceLevel and silently dropped at DebugLevel; Enabled returns the expected truth table across all four levels; WithFields propagates. - NopZap: never emits and reports Enabled=false. - MinLevelCore: the canonical pipeline (console accepts Trace, OTel core wrapped with MinLevelCore at DebugLevel) routes Trace to the console only and lets Debug through both cores. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> --------- Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
245 lines
7.1 KiB
Go
245 lines
7.1 KiB
Go
// Code generated by MockGen. DO NOT EDIT.
|
|
// Source: logging.go
|
|
//
|
|
// Generated by this command:
|
|
//
|
|
// mockgen -source logging.go -destination logging_generated.go -package logging . Logger
|
|
//
|
|
|
|
// Package logging is a generated GoMock package.
|
|
package logging
|
|
|
|
import (
|
|
context "context"
|
|
io "io"
|
|
reflect "reflect"
|
|
|
|
gomock "go.uber.org/mock/gomock"
|
|
)
|
|
|
|
// MockLogger is a mock of Logger interface.
|
|
type MockLogger struct {
|
|
ctrl *gomock.Controller
|
|
recorder *MockLoggerMockRecorder
|
|
isgomock struct{}
|
|
}
|
|
|
|
// MockLoggerMockRecorder is the mock recorder for MockLogger.
|
|
type MockLoggerMockRecorder struct {
|
|
mock *MockLogger
|
|
}
|
|
|
|
// NewMockLogger creates a new mock instance.
|
|
func NewMockLogger(ctrl *gomock.Controller) *MockLogger {
|
|
mock := &MockLogger{ctrl: ctrl}
|
|
mock.recorder = &MockLoggerMockRecorder{mock}
|
|
return mock
|
|
}
|
|
|
|
// EXPECT returns an object that allows the caller to indicate expected use.
|
|
func (m *MockLogger) EXPECT() *MockLoggerMockRecorder {
|
|
return m.recorder
|
|
}
|
|
|
|
// Debug mocks base method.
|
|
func (m *MockLogger) Debug(args ...any) {
|
|
m.ctrl.T.Helper()
|
|
varargs := []any{}
|
|
for _, a := range args {
|
|
varargs = append(varargs, a)
|
|
}
|
|
m.ctrl.Call(m, "Debug", varargs...)
|
|
}
|
|
|
|
// Debug indicates an expected call of Debug.
|
|
func (mr *MockLoggerMockRecorder) Debug(args ...any) *gomock.Call {
|
|
mr.mock.ctrl.T.Helper()
|
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Debug", reflect.TypeOf((*MockLogger)(nil).Debug), args...)
|
|
}
|
|
|
|
// Debugf mocks base method.
|
|
func (m *MockLogger) Debugf(fmt string, args ...any) {
|
|
m.ctrl.T.Helper()
|
|
varargs := []any{fmt}
|
|
for _, a := range args {
|
|
varargs = append(varargs, a)
|
|
}
|
|
m.ctrl.Call(m, "Debugf", varargs...)
|
|
}
|
|
|
|
// Debugf indicates an expected call of Debugf.
|
|
func (mr *MockLoggerMockRecorder) Debugf(fmt any, args ...any) *gomock.Call {
|
|
mr.mock.ctrl.T.Helper()
|
|
varargs := append([]any{fmt}, args...)
|
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Debugf", reflect.TypeOf((*MockLogger)(nil).Debugf), varargs...)
|
|
}
|
|
|
|
// Enabled mocks base method.
|
|
func (m *MockLogger) Enabled(level Level) bool {
|
|
m.ctrl.T.Helper()
|
|
ret := m.ctrl.Call(m, "Enabled", level)
|
|
ret0, _ := ret[0].(bool)
|
|
return ret0
|
|
}
|
|
|
|
// Enabled indicates an expected call of Enabled.
|
|
func (mr *MockLoggerMockRecorder) Enabled(level any) *gomock.Call {
|
|
mr.mock.ctrl.T.Helper()
|
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Enabled", reflect.TypeOf((*MockLogger)(nil).Enabled), level)
|
|
}
|
|
|
|
// Error mocks base method.
|
|
func (m *MockLogger) Error(args ...any) {
|
|
m.ctrl.T.Helper()
|
|
varargs := []any{}
|
|
for _, a := range args {
|
|
varargs = append(varargs, a)
|
|
}
|
|
m.ctrl.Call(m, "Error", varargs...)
|
|
}
|
|
|
|
// Error indicates an expected call of Error.
|
|
func (mr *MockLoggerMockRecorder) Error(args ...any) *gomock.Call {
|
|
mr.mock.ctrl.T.Helper()
|
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Error", reflect.TypeOf((*MockLogger)(nil).Error), args...)
|
|
}
|
|
|
|
// Errorf mocks base method.
|
|
func (m *MockLogger) Errorf(fmt string, args ...any) {
|
|
m.ctrl.T.Helper()
|
|
varargs := []any{fmt}
|
|
for _, a := range args {
|
|
varargs = append(varargs, a)
|
|
}
|
|
m.ctrl.Call(m, "Errorf", varargs...)
|
|
}
|
|
|
|
// Errorf indicates an expected call of Errorf.
|
|
func (mr *MockLoggerMockRecorder) Errorf(fmt any, args ...any) *gomock.Call {
|
|
mr.mock.ctrl.T.Helper()
|
|
varargs := append([]any{fmt}, args...)
|
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Errorf", reflect.TypeOf((*MockLogger)(nil).Errorf), varargs...)
|
|
}
|
|
|
|
// Info mocks base method.
|
|
func (m *MockLogger) Info(args ...any) {
|
|
m.ctrl.T.Helper()
|
|
varargs := []any{}
|
|
for _, a := range args {
|
|
varargs = append(varargs, a)
|
|
}
|
|
m.ctrl.Call(m, "Info", varargs...)
|
|
}
|
|
|
|
// Info indicates an expected call of Info.
|
|
func (mr *MockLoggerMockRecorder) Info(args ...any) *gomock.Call {
|
|
mr.mock.ctrl.T.Helper()
|
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Info", reflect.TypeOf((*MockLogger)(nil).Info), args...)
|
|
}
|
|
|
|
// Infof mocks base method.
|
|
func (m *MockLogger) Infof(fmt string, args ...any) {
|
|
m.ctrl.T.Helper()
|
|
varargs := []any{fmt}
|
|
for _, a := range args {
|
|
varargs = append(varargs, a)
|
|
}
|
|
m.ctrl.Call(m, "Infof", varargs...)
|
|
}
|
|
|
|
// Infof indicates an expected call of Infof.
|
|
func (mr *MockLoggerMockRecorder) Infof(fmt any, args ...any) *gomock.Call {
|
|
mr.mock.ctrl.T.Helper()
|
|
varargs := append([]any{fmt}, args...)
|
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Infof", reflect.TypeOf((*MockLogger)(nil).Infof), varargs...)
|
|
}
|
|
|
|
// Trace mocks base method.
|
|
func (m *MockLogger) Trace(args ...any) {
|
|
m.ctrl.T.Helper()
|
|
varargs := []any{}
|
|
for _, a := range args {
|
|
varargs = append(varargs, a)
|
|
}
|
|
m.ctrl.Call(m, "Trace", varargs...)
|
|
}
|
|
|
|
// Trace indicates an expected call of Trace.
|
|
func (mr *MockLoggerMockRecorder) Trace(args ...any) *gomock.Call {
|
|
mr.mock.ctrl.T.Helper()
|
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Trace", reflect.TypeOf((*MockLogger)(nil).Trace), args...)
|
|
}
|
|
|
|
// Tracef mocks base method.
|
|
func (m *MockLogger) Tracef(fmt string, args ...any) {
|
|
m.ctrl.T.Helper()
|
|
varargs := []any{fmt}
|
|
for _, a := range args {
|
|
varargs = append(varargs, a)
|
|
}
|
|
m.ctrl.Call(m, "Tracef", varargs...)
|
|
}
|
|
|
|
// Tracef indicates an expected call of Tracef.
|
|
func (mr *MockLoggerMockRecorder) Tracef(fmt any, args ...any) *gomock.Call {
|
|
mr.mock.ctrl.T.Helper()
|
|
varargs := append([]any{fmt}, args...)
|
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Tracef", reflect.TypeOf((*MockLogger)(nil).Tracef), varargs...)
|
|
}
|
|
|
|
// WithContext mocks base method.
|
|
func (m *MockLogger) WithContext(ctx context.Context) Logger {
|
|
m.ctrl.T.Helper()
|
|
ret := m.ctrl.Call(m, "WithContext", ctx)
|
|
ret0, _ := ret[0].(Logger)
|
|
return ret0
|
|
}
|
|
|
|
// WithContext indicates an expected call of WithContext.
|
|
func (mr *MockLoggerMockRecorder) WithContext(ctx any) *gomock.Call {
|
|
mr.mock.ctrl.T.Helper()
|
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "WithContext", reflect.TypeOf((*MockLogger)(nil).WithContext), ctx)
|
|
}
|
|
|
|
// WithField mocks base method.
|
|
func (m *MockLogger) WithField(key string, value any) Logger {
|
|
m.ctrl.T.Helper()
|
|
ret := m.ctrl.Call(m, "WithField", key, value)
|
|
ret0, _ := ret[0].(Logger)
|
|
return ret0
|
|
}
|
|
|
|
// WithField indicates an expected call of WithField.
|
|
func (mr *MockLoggerMockRecorder) WithField(key, value any) *gomock.Call {
|
|
mr.mock.ctrl.T.Helper()
|
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "WithField", reflect.TypeOf((*MockLogger)(nil).WithField), key, value)
|
|
}
|
|
|
|
// WithFields mocks base method.
|
|
func (m *MockLogger) WithFields(arg0 map[string]any) Logger {
|
|
m.ctrl.T.Helper()
|
|
ret := m.ctrl.Call(m, "WithFields", arg0)
|
|
ret0, _ := ret[0].(Logger)
|
|
return ret0
|
|
}
|
|
|
|
// WithFields indicates an expected call of WithFields.
|
|
func (mr *MockLoggerMockRecorder) WithFields(arg0 any) *gomock.Call {
|
|
mr.mock.ctrl.T.Helper()
|
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "WithFields", reflect.TypeOf((*MockLogger)(nil).WithFields), arg0)
|
|
}
|
|
|
|
// Writer mocks base method.
|
|
func (m *MockLogger) Writer() io.Writer {
|
|
m.ctrl.T.Helper()
|
|
ret := m.ctrl.Call(m, "Writer")
|
|
ret0, _ := ret[0].(io.Writer)
|
|
return ret0
|
|
}
|
|
|
|
// Writer indicates an expected call of Writer.
|
|
func (mr *MockLoggerMockRecorder) Writer() *gomock.Call {
|
|
mr.mock.ctrl.T.Helper()
|
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Writer", reflect.TypeOf((*MockLogger)(nil).Writer))
|
|
}
|