logger

package
v1.0.2 Latest Latest
Warning

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

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

Documentation

Overview

Package logger provides logging functionality for StreamSQL. Supports different log levels and configurable log output backends.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

func Debug(format string, args ...any)

Debug uses the default logger to record debug information

func DebugFields added in v1.0.0

func DebugFields(msg string, fields ...Field)

func Error

func Error(format string, args ...any)

Error uses the default logger to record errors

func ErrorFields added in v1.0.0

func ErrorFields(msg string, fields ...Field)

func Info

func Info(format string, args ...any)

Info uses the default logger to record information

func InfoFields added in v1.0.0

func InfoFields(msg string, fields ...Field)

InfoFields emits a structured INFO entry on the default logger. If the default does not implement StructuredLogger (a custom printf-only logger), the fields are folded into a single text message so no context is lost.

func SetDefault

func SetDefault(logger Logger)

SetDefault sets the global default logger

func Warn

func Warn(format string, args ...any)

Warn uses the default logger to record warnings

func WarnFields added in v1.0.0

func WarnFields(msg string, fields ...Field)

Types

type Field added in v1.0.0

type Field struct {
	Key   string
	Value any
}

Field is a structured key-value pair attached to a log entry.

func Any added in v1.0.0

func Any(k string, v any) Field

Any captures an arbitrary value under k. Prefer a typed constructor when one exists; Any defers formatting to the renderer.

func Bool added in v1.0.0

func Bool(k string, v bool) Field

func Duration added in v1.0.0

func Duration(k string, d time.Duration) Field

Duration records a duration as its human-readable string form (e.g. "12ms").

func Err added in v1.0.0

func Err(err error) Field

Err records an error under the conventional "error" key. A nil error is preserved as a null value rather than panic.

func Float64 added in v1.0.0

func Float64(k string, v float64) Field

func Int added in v1.0.0

func Int(k string, v int) Field

func Int64 added in v1.0.0

func Int64(k string, v int64) Field

func String added in v1.0.0

func String(k, v string) Field

Field constructors cover the common value types so callers get typed capture at the call site (and avoid boxing mistakes).

type Format added in v1.0.0

type Format int

Format selects the encoding of structured log entries.

const (
	// TextFormat emits "[ts] [LEVEL] msg key=value" (logfmt-style). Default.
	TextFormat Format = iota
	// JSONFormat emits one JSON object per line.
	JSONFormat
)

type Level

type Level int

Level defines log levels

const (
	// DEBUG debug level, displays detailed debug information
	DEBUG Level = iota
	// INFO info level, displays general information
	INFO
	// WARN warning level, displays warning information
	WARN
	// ERROR error level, only displays error information
	ERROR
	// OFF disables logging
	OFF
)

func (Level) String

func (l Level) String() string

String returns string representation of log level

type Logger

type Logger interface {
	// Debug records debug level logs
	Debug(format string, args ...any)
	// Info records info level logs
	Info(format string, args ...any)
	// Warn records warning level logs
	Warn(format string, args ...any)
	// Error records error level logs
	Error(format string, args ...any)
	// SetLevel sets the log level
	SetLevel(level Level)
}

Logger interface defines basic methods for logging

func GetDefault

func GetDefault() Logger

GetDefault gets the global default logger

func NewDiscardLogger

func NewDiscardLogger() Logger

NewDiscardLogger creates a logger that discards all logs Used in scenarios where log output is not needed

func NewLogger

func NewLogger(level Level, output io.Writer) Logger

NewLogger creates a new logger Parameters:

  • level: log level
  • output: output destination, such as os.Stdout, os.Stderr, or file

Returns:

  • Logger: logger instance

Example:

logger := NewLogger(INFO, os.Stdout)
logger.Info("Application started")

func NewLoggerWithFormat added in v1.0.0

func NewLoggerWithFormat(level Level, output io.Writer, format Format) Logger

NewLoggerWithFormat is like NewLogger but selects the structured output encoding. TextFormat matches NewLogger's historical output.

type StructuredLogger added in v1.0.0

type StructuredLogger interface {
	DebugFields(msg string, fields ...Field)
	InfoFields(msg string, fields ...Field)
	WarnFields(msg string, fields ...Field)
	ErrorFields(msg string, fields ...Field)
}

StructuredLogger is the optional structured variant of Logger. Loggers that implement it emit key-value context; the printf-style Logger methods remain available alongside. Package-level helpers (InfoFields, ...) use this when present and otherwise fall back to the printf method.

Jump to

Keyboard shortcuts

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