log

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2026 License: EUPL-1.2 Imports: 7 Imported by: 0

Documentation

Overview

Package log provides structured logging for Core applications.

The package works standalone or integrated with the Core framework:

// Standalone usage
log.SetLevel(log.LevelDebug)
log.Info("server started", "port", 8080)
log.Error("failed to connect", "err", err)

// With Core framework
core.New(
    framework.WithName("log", log.NewService(log.Options{Level: log.LevelInfo})),
)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

func Debug(msg string, keyvals ...any)

Debug logs to the default logger.

func Error

func Error(msg string, keyvals ...any)

Error logs to the default logger.

func Info

func Info(msg string, keyvals ...any)

Info logs to the default logger.

func NewService

func NewService(opts Options) func(*framework.Core) (any, error)

NewService creates a log service factory for Core.

func SetDefault

func SetDefault(l *Logger)

SetDefault sets the default logger.

func SetLevel

func SetLevel(level Level)

SetLevel sets the default logger's level.

func Warn

func Warn(msg string, keyvals ...any)

Warn logs to the default logger.

Types

type Level

type Level int

Level defines logging verbosity.

const (
	LevelQuiet Level = iota
	LevelError
	LevelWarn
	LevelInfo
	LevelDebug
)

func (Level) String

func (l Level) String() string

String returns the level name.

type Logger

type Logger struct {

	// Style functions for formatting (can be overridden)
	StyleTimestamp func(string) string
	StyleDebug     func(string) string
	StyleInfo      func(string) string
	StyleWarn      func(string) string
	StyleError     func(string) string
	// contains filtered or unexported fields
}

Logger provides structured logging.

func Default

func Default() *Logger

Default returns the default logger.

func New

func New(opts Options) *Logger

New creates a new Logger with the given options.

func (*Logger) Debug

func (l *Logger) Debug(msg string, keyvals ...any)

Debug logs a debug message with optional key-value pairs.

func (*Logger) Error

func (l *Logger) Error(msg string, keyvals ...any)

Error logs an error message with optional key-value pairs.

func (*Logger) Info

func (l *Logger) Info(msg string, keyvals ...any)

Info logs an info message with optional key-value pairs.

func (*Logger) Level

func (l *Logger) Level() Level

Level returns the current log level.

func (*Logger) SetLevel

func (l *Logger) SetLevel(level Level)

SetLevel changes the log level.

func (*Logger) SetOutput

func (l *Logger) SetOutput(w io.Writer)

SetOutput changes the output writer.

func (*Logger) Warn

func (l *Logger) Warn(msg string, keyvals ...any)

Warn logs a warning message with optional key-value pairs.

type Options

type Options struct {
	Level  Level
	Output io.Writer // defaults to os.Stderr
}

Options configures a Logger.

type QueryLevel

type QueryLevel struct{}

QueryLevel returns the current log level.

type Service

type Service struct {
	*framework.ServiceRuntime[Options]
	*Logger
}

Service wraps Logger for Core framework integration.

func (*Service) OnStartup

func (s *Service) OnStartup(ctx context.Context) error

OnStartup registers query and task handlers.

type TaskSetLevel

type TaskSetLevel struct {
	Level Level
}

TaskSetLevel changes the log level.

Jump to

Keyboard shortcuts

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