logger

package
v0.2.0-beta.1 Latest Latest
Warning

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

Go to latest
Published: May 27, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

README

Logger - Logging Utilities

Go Reference

The logger package provides structured logging for Kure. All logging in the project should use this package instead of fmt.Print or the standard log package.

Overview

The logger provides a simple interface for structured key-value logging with support for different log levels. It wraps an underlying structured logger and provides convenience functions.

Usage

import "github.com/go-kure/kure/pkg/logger"

// Default logger
log := logger.Default()

// Log with context
log.Info("loading package", "path", "/path/to/package")
log.Error("failed to parse", "error", err, "file", "config.yaml")

// No-op logger (for quiet mode)
log := logger.Noop()

Log Levels

Level Usage
Info Normal operational messages
Error Error conditions
Debug Detailed debugging information
Warn Warning conditions

Conventions

  • Use key-value pairs for structured data: log.Info("msg", "key1", val1, "key2", val2)
  • Use logger.Noop() when verbose output is disabled
  • Pass the logger through function parameters or options structs
  • Use logger.Default() only at initialization points (CLI entry, tests)

All Kure packages use this logger. See the errors package for error handling patterns.

Documentation

Overview

Package logger provides a structured logging interface for the Kure library. It supports different log levels (Debug, Info, Warn, Error) and can be configured with verbosity settings.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatBytes

func FormatBytes(bytes int64) string

Helper function for formatting byte sizes

func FormatDuration

func FormatDuration(nanos int64) string

Helper function to format durations in a human-readable way

Types

type Level

type Level int

Level represents the severity level of a log message

const (
	// LevelDebug is for detailed debugging information
	LevelDebug Level = iota
	// LevelInfo is for informational messages
	LevelInfo
	// LevelWarn is for warning messages
	LevelWarn
	// LevelError is for error messages
	LevelError
)

type Logger

type Logger interface {
	// Debug logs a debug message (only shown in verbose/debug mode)
	Debug(format string, args ...any)
	// Info logs an informational message
	Info(format string, args ...any)
	// Warn logs a warning message
	Warn(format string, args ...any)
	// Error logs an error message
	Error(format string, args ...any)
	// WithPrefix returns a new logger with an additional prefix
	WithPrefix(prefix string) Logger
	// SetLevel sets the minimum log level
	SetLevel(level Level)
}

Logger is the interface for structured logging in Kure

func Default

func Default() Logger

Default creates a logger with default options

func New

func New(opts Options) Logger

New creates a new logger with the given options

func Noop

func Noop() Logger

Noop returns a logger that discards all messages

type Options

type Options struct {
	// Output is where logs are written (default: os.Stderr)
	Output io.Writer
	// Level is the minimum log level (default: LevelInfo)
	Level Level
	// Prefix is the log prefix (default: empty)
	Prefix string
	// ShowTimestamp indicates whether to include timestamps (default: true)
	ShowTimestamp bool
}

Options configures a logger instance

func DefaultOptions

func DefaultOptions() Options

DefaultOptions returns the default logger options

Jump to

Keyboard shortcuts

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