log

package
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2025 License: Apache-2.0 Imports: 6 Imported by: 4

Documentation

Overview

Package log provides a lightweight thread-safe logging facility using structured logging (slog) with JSON output format. It offers a singleton logger instance with configurable log levels through environment variables and convenience methods for fatal error logging.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Fatal

func Fatal(fName string, details string)

Fatal logs a message at Fatal level. The fName parameter indicates the function name from which the call is made. The details parameter contains the error message or details to log. This function panics before exiting.

func FatalF

func FatalF(fName string, format string, args ...any)

FatalF logs a formatted message at Fatal level. The fName parameter indicates the function name from which the call is made. The format parameter is a printf-style format string. The args parameter contains values to be formatted according to the format string. It follows the printf formatting rules. This function panics before exiting.

func FatalLn

func FatalLn(fName string, args ...any)

FatalLn logs a message at Fatal level with a line feed. The fName parameter indicates the function name from which the call is made. The args parameter contains the values to be logged, which will be formatted and joined. This function panics before exiting.

func Level

func Level() slog.Level

Level returns the logging level for the SPIKE components.

It reads from the SPIKE_SYSTEM_LOG_LEVEL environment variable and converts it to the corresponding slog.Level value. Valid values (case-insensitive) are:

  • "DEBUG": returns slog.LevelDebug
  • "INFO": returns slog.LevelInfo
  • "WARN": returns slog.LevelWarn
  • "ERROR": returns slog.LevelError

If the environment variable is not set or contains an invalid value, it returns the default level slog.LevelWarn.

func Log

func Log() *slog.Logger

Log returns a thread-safe singleton instance of slog.Logger configured for JSON output. If the logger hasn't been initialized, it creates a new instance with the log level specified by the environment. Further calls return the same logger instance.

By convention, when using the returned logger, the first argument (msg) should be the function name (fName) from which the logging call is made.

Types

This section is empty.

Jump to

Keyboard shortcuts

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