logging

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package logging provides logging functionalities for Kite applications.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CallerConfigurer

type CallerConfigurer interface {
	SetShowCaller(show bool)
}

CallerConfigurer is an optional interface for loggers that support enabling/disabling caller information in log output.

type ContextLogger

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

ContextLogger is a wrapper around a base Logger that injects the current trace ID (if present in the context) into log messages automatically.

It is intended for use within request-scoped contexts where OpenTelemetry trace information is available.

func NewContextLogger

func NewContextLogger(ctx context.Context, base Logger) *ContextLogger

NewContextLogger creates a new ContextLogger that wraps the provided base logger and automatically appends OpenTelemetry trace information (trace ID) to log output when available in the context.

func (*ContextLogger) ChangeLevel

func (l *ContextLogger) ChangeLevel(level Level)

func (*ContextLogger) Debug

func (l *ContextLogger) Debug(args ...any)

func (*ContextLogger) Debugf

func (l *ContextLogger) Debugf(f string, args ...any)

func (*ContextLogger) Error

func (l *ContextLogger) Error(args ...any)

func (*ContextLogger) Errorf

func (l *ContextLogger) Errorf(f string, args ...any)

func (*ContextLogger) Fatal

func (l *ContextLogger) Fatal(args ...any)

func (*ContextLogger) Fatalf

func (l *ContextLogger) Fatalf(f string, args ...any)

func (*ContextLogger) Info

func (l *ContextLogger) Info(args ...any)

func (*ContextLogger) Infof

func (l *ContextLogger) Infof(f string, args ...any)

func (*ContextLogger) Log

func (l *ContextLogger) Log(args ...any)

func (*ContextLogger) Logf

func (l *ContextLogger) Logf(f string, args ...any)

func (*ContextLogger) Notice

func (l *ContextLogger) Notice(args ...any)

func (*ContextLogger) Noticef

func (l *ContextLogger) Noticef(f string, args ...any)

func (*ContextLogger) Warn

func (l *ContextLogger) Warn(args ...any)

func (*ContextLogger) Warnf

func (l *ContextLogger) Warnf(f string, args ...any)

type Level

type Level int

Level represents different logging levels.

const (
	DEBUG Level = iota + 1
	INFO
	NOTICE
	WARN
	ERROR
	FATAL
)

func GetLevelFromString

func GetLevelFromString(level string) Level

GetLevelFromString converts a string to a logging level.

func GetLogLevelForError

func GetLogLevelForError(err error) Level

GetLogLevelForError extracts the log level from an error if it implements LogLevelResponder. If the error does not implement this interface, it defaults to ERROR level. This is useful for determining the appropriate log level when handling errors.

func (Level) MarshalJSON

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

func (Level) String

func (l Level) String() string

String returns the string representation of the log level.

type LogLevelResponder

type LogLevelResponder interface {
	LogLevel() Level
}

LogLevelResponder provides a method to get the log level.

type Logger

type Logger interface {
	Debug(args ...any)
	Debugf(format string, args ...any)
	Log(args ...any)
	Logf(format string, args ...any)
	Info(args ...any)
	Infof(format string, args ...any)
	Notice(args ...any)
	Noticef(format string, args ...any)
	Warn(args ...any)
	Warnf(format string, args ...any)
	Error(args ...any)
	Errorf(format string, args ...any)
	Fatal(args ...any)
	Fatalf(format string, args ...any)
	ChangeLevel(level Level)
}

Logger defines the interface for structured logging across different log levels such as Debug, Info, Warn, Error, and Fatal. It allows formatted logs and log level control.

func NewFileLogger

func NewFileLogger(path string) Logger

NewFileLogger creates a new Logger instance that writes logs to the specified file. If the file cannot be opened or created, logs are discarded.

func NewLogger

func NewLogger(level Level) Logger

NewLogger creates a new Logger instance configured with the given log level. Logs will be printed to stdout and stderr depending on the level.

func NewMockLogger

func NewMockLogger(level Level) Logger

type MockLogger

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

func (*MockLogger) ChangeLevel

func (m *MockLogger) ChangeLevel(level Level)

func (*MockLogger) Debug

func (m *MockLogger) Debug(args ...any)

func (*MockLogger) Debugf

func (m *MockLogger) Debugf(format string, args ...any)

func (*MockLogger) Error

func (m *MockLogger) Error(args ...any)

func (*MockLogger) Errorf

func (m *MockLogger) Errorf(format string, args ...any)

func (*MockLogger) Fatal

func (m *MockLogger) Fatal(args ...any)

func (*MockLogger) Fatalf

func (m *MockLogger) Fatalf(format string, args ...any)

func (*MockLogger) Info

func (m *MockLogger) Info(args ...any)

func (*MockLogger) Infof

func (m *MockLogger) Infof(format string, args ...any)

func (*MockLogger) Log

func (m *MockLogger) Log(args ...any)

func (*MockLogger) Logf

func (m *MockLogger) Logf(format string, args ...any)

func (*MockLogger) Notice

func (m *MockLogger) Notice(args ...any)

func (*MockLogger) Noticef

func (m *MockLogger) Noticef(format string, args ...any)

func (*MockLogger) Warn

func (m *MockLogger) Warn(args ...any)

func (*MockLogger) Warnf

func (m *MockLogger) Warnf(format string, args ...any)

type PrettyPrint

type PrettyPrint interface {
	PrettyPrint(writer io.Writer)
}

PrettyPrint defines an interface for objects that can render themselves in a human-readable format to the provided writer.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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