log

package
v0.12.39 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 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 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.

By default, this function exits cleanly with status code 1 to avoid leaking sensitive information through stack traces in production. To enable stack traces for development and testing, set SPIKE_STACK_TRACES_ON_LOG_FATAL=true.

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