Bash Logger

active

Structured, leveled logging for Bash scripts, with no runtime dependencies.

View on GitHub Latest release
  • bash
  • logging
  • cli
  • shell-scripting
  • linux
  • macos
  • zsh

Every developer knows that logging can be a vital tool for debugging and monitoring the behavior of their applications. In a blog post I argued that scripted tools should also include proper logging for all the same reasons. bash-logger is designed to provide that structure and give you the flexibility to log what you need where you need it.

bash-logger provides a structured logging library for Bash scripts including log levels, timestamps, and colour output and more. It can be sourced as a single file with no external dependencies.

# Source the logging module
source /path/to/logging.sh

# Initialize the logger
init_logger

# Log messages
log_info "Application started"
log_error "Something went wrong"

Full documentation can be found in the GitHub repository starting from getting started.

Demos

Below are demos of the logging module at different logging levels, writing to both a log file and the journal.

Bash Logging Module Demos
  • Default INFO logging level, writing to both a log file and the journal.

Logging Demo - INFO

Back to top

  • DEBUG logging level, writing to both a log file and the journal.

Logging Demo - DEBUG
Adding debug logging through a script switch

Back to top