logger

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2025 License: Apache-2.0 Imports: 7 Imported by: 5

Documentation

Overview

Package logger is a generated GoMock package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewDefaultLogger

func NewDefaultLogger(mode string) *defaultLogger

NewDefaultLogger creates a new DefaultLogger.

Types

type Field

type Field struct {
	Key   string
	Value any
}

Field represents a key-value pair for structured logging.

func Any

func Any(key string, value any) Field

NewField creates a new generic Field.

func Bool

func Bool(key string, value bool) Field

NewBoolField creates a new Field with a boolean value.

func Error

func Error(err error) Field

NewErrorField creates a new Field with an error value.

func Float

func Float(key string, value float64) Field

func Int

func Int(key string, value int) Field

NewIntField creates a new Field with an integer value.

func RequestIDField

func RequestIDField(requestID string) Field

func String

func String(key, value string) Field

NewStringField creates a new Field with a string value.

func TenantIDField

func TenantIDField(tenantID string) Field

func Time

func Time(key string, value time.Time) Field

func UserField

func UserField(userID string) Field

type Level

type Level int8
const (
	// TraceLevel level. Designates finer-grained informational events than the Debug.
	TraceLevel Level = iota - 2
	// DebugLevel level. Usually only enabled when debugging. Very verbose logging.
	DebugLevel
	// InfoLevel is the default logging priority.
	// General operational entries about what's going on inside the application.
	InfoLevel
	// WarnLevel level. Non-critical entries that deserve eyes.
	WarnLevel
	// ErrorLevel level. Logs. Used for errors that should definitely be noted.
	ErrorLevel
	// FatalLevel level. Logs and then calls `logger.Exit(1)`. highest level of severity.
	FatalLevel
)

func GetLevel

func GetLevel(levelStr string) (Level, error)

GetLevel converts a level string into a logger Level value. returns an error if the input string does not match known values.

func (Level) Enabled

func (l Level) Enabled(lvl Level) bool

Enabled returns true if the given level is at or above this level.

func (Level) String

func (l Level) String() string

type Logger

type Logger interface {
	// Debug logs messages at the debug level, typically used for low-level system information.
	Debug(msg string, fields ...Field)
	// Info logs informational messages that highlight the progress of the application.
	Info(msg string, fields ...Field)
	// Warn logs messages that indicate potentially harmful situations.
	Warn(msg string, fields ...Field)
	// Error logs error messages that indicate a failure in the application.
	Error(msg string, fields ...Field)
	// DPanic logs messages at the DPanic level, which is between Debug and Panic levels. It is used to log critical issues that are considered panics in development environments but are treated differently in production.
	DPanic(msg string, fields ...Field)
	// Panic logs messages at the panic level and then panics.
	Panic(msg string, fields ...Field)
	// Fatal logs messages at the fatal level and then calls os.Exit(1).
	Fatal(msg string, fields ...Field)
	// Sync flushes any buffered log entries.
	Sync() error
}
var DefaultLogger Logger

Logger defines the interface for logging at various levels. Logger is an interface that defines a set of methods for logging messages at various levels of severity. The levels include Debug, Info, Warn, Error, DPanic, Panic, and Fatal. Each method accepts a message string and optional fields for additional context. The Sync method is used to flush any buffered log entries.

func New

func New(provider Provider) Logger

NewLogger creates a new instance of Logger.

type MockLogger

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

MockLogger is a mock of Logger interface.

func NewMockLogger

func NewMockLogger(ctrl *gomock.Controller) *MockLogger

NewMockLogger creates a new mock instance.

func (*MockLogger) DPanic

func (m *MockLogger) DPanic(msg string, fields ...Field)

DPanic mocks base method.

func (*MockLogger) Debug

func (m *MockLogger) Debug(msg string, fields ...Field)

Debug mocks base method.

func (*MockLogger) EXPECT

func (m *MockLogger) EXPECT() *MockLoggerMockRecorder

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

func (*MockLogger) Error

func (m *MockLogger) Error(msg string, fields ...Field)

Error mocks base method.

func (*MockLogger) Fatal

func (m *MockLogger) Fatal(msg string, fields ...Field)

Fatal mocks base method.

func (*MockLogger) Info

func (m *MockLogger) Info(msg string, fields ...Field)

Info mocks base method.

func (*MockLogger) Panic

func (m *MockLogger) Panic(msg string, fields ...Field)

Panic mocks base method.

func (*MockLogger) Sync

func (m *MockLogger) Sync() error

Sync mocks base method.

func (*MockLogger) Warn

func (m *MockLogger) Warn(msg string, fields ...Field)

Warn mocks base method.

type MockLoggerMockRecorder

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

MockLoggerMockRecorder is the mock recorder for MockLogger.

func (*MockLoggerMockRecorder) DPanic

func (mr *MockLoggerMockRecorder) DPanic(msg any, fields ...any) *gomock.Call

DPanic indicates an expected call of DPanic.

func (*MockLoggerMockRecorder) Debug

func (mr *MockLoggerMockRecorder) Debug(msg any, fields ...any) *gomock.Call

Debug indicates an expected call of Debug.

func (*MockLoggerMockRecorder) Error

func (mr *MockLoggerMockRecorder) Error(msg any, fields ...any) *gomock.Call

Error indicates an expected call of Error.

func (*MockLoggerMockRecorder) Fatal

func (mr *MockLoggerMockRecorder) Fatal(msg any, fields ...any) *gomock.Call

Fatal indicates an expected call of Fatal.

func (*MockLoggerMockRecorder) Info

func (mr *MockLoggerMockRecorder) Info(msg any, fields ...any) *gomock.Call

Info indicates an expected call of Info.

func (*MockLoggerMockRecorder) Panic

func (mr *MockLoggerMockRecorder) Panic(msg any, fields ...any) *gomock.Call

Panic indicates an expected call of Panic.

func (*MockLoggerMockRecorder) Sync

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

Sync indicates an expected call of Sync.

func (*MockLoggerMockRecorder) Warn

func (mr *MockLoggerMockRecorder) Warn(msg any, fields ...any) *gomock.Call

Warn indicates an expected call of Warn.

type Provider

type Provider interface {
	// Debug logs messages at the debug level, typically used for low-level system information.
	Debug(msg string, fields map[string]any)
	// Info logs informational messages that highlight the progress of the application.
	Info(msg string, fields map[string]any)
	// Warn logs messages that indicate potentially harmful situations.
	Warn(msg string, fields map[string]any)
	// Error logs error messages that indicate a failure in the application.
	Error(msg string, fields map[string]any)
	// DPanic logs messages at the DPanic level, which is between Debug and Panic levels. It is used to log critical issues that are considered panics in development environments but are treated differently in production.
	DPanic(msg string, fields map[string]any)
	// Panic logs messages at the panic level and then panics.
	Panic(msg string, fields map[string]any)
	// Fatal logs messages at the fatal level and then calls os.Exit(1).
	Fatal(msg string, fields map[string]any)
	// Sync flushes any buffered log entries.
	Sync() error
}

Jump to

Keyboard shortcuts

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