logging

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package logging provides logging helper functions for internal packages.

This package wraps the github.com/0verkilll/logger package to provide a consistent logging interface across all internal decoder packages.

Usage

Import this package in any internal package that needs logging:

import "github.com/0verkilll/jpeg/internal/logging"

Then use the helper functions:

logging.Debug("parsing marker", "offset", 123, "marker", "SOF0")
logging.Info("decode complete", "format", "JPEG-LS")
logging.Warn("using default table", "table", 0)
logging.Error("decode failed", "error", err)

Zero Overhead

When no logger is configured (the default), all logging calls are no-ops with zero allocations. The underlying logger uses NopLogger which immediately returns without processing any arguments.

Structured Logging

All log functions accept key-value pairs for structured logging:

logging.Debug("message", "key1", value1, "key2", value2)

See internal/README.md for the complete list of standard keys and usage patterns.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

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

Debug logs a message at debug level using the global logger. Use for detailed technical information useful during debugging: - Marker offsets and values - Coefficient decoding steps - Parsing progress

Parameters:

  • msg: The log message describing the event
  • args: Optional key-value pairs for structured context

Example:

logging.Debug("parsing marker", "offset", 123, "marker", "SOF0")

func Error

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

Error logs a message at error level using the global logger. Use for error conditions that don't halt execution: - Malformed data that can be skipped - Optional feature failures - Partial decode errors

Parameters:

  • msg: The log message describing the error
  • args: Optional key-value pairs for structured context

Example:

logging.Error("failed to decode block", "block", 42, "error", err)

func GetLogger

func GetLogger() logger.LeveledLogger

GetLogger returns the currently configured global logger, or nil if none is set. This allows internal packages to check if logging is enabled before performing expensive logging operations.

Example:

if logging.GetLogger() != nil {
    // Logging is enabled, safe to compute expensive log data
    details := computeExpensiveDebugInfo()
    logging.Debug("detailed info", "details", details)
}

func Info

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

Info logs a message at info level using the global logger. Use for significant events during normal operation: - Format detection results - Decode start and completion - Major processing milestones

Parameters:

  • msg: The log message describing the event
  • args: Optional key-value pairs for structured context

Example:

logging.Info("decode complete", "format", "JPEG-LS", "width", 1920, "height", 1080)

func IsEnabled

func IsEnabled() bool

IsEnabled returns true if a logger is currently configured. This is a convenience function for checking if logging is active.

Example:

if logging.IsEnabled() {
    logging.Debug("this will actually be logged")
}

func Warn

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

Warn logs a message at warning level using the global logger. Use for potentially problematic situations: - Deprecated features being used - Fallback behaviors triggered - Recoverable errors that don't stop processing

Parameters:

  • msg: The log message describing the warning
  • args: Optional key-value pairs for structured context

Example:

logging.Warn("using default quantization table", "table", 0)

Types

This section is empty.

Jump to

Keyboard shortcuts

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