Skip to content

A flexible, reusable logging module for Bash scripts that provides standardized logging functionality with various configuration options.

License

Notifications You must be signed in to change notification settings

GingerGraham/bash-logger

Bash Logger

GitHub Release Release Tests

A flexible, reusable logging module for Bash scripts that provides standardized logging functionality with various configuration options.

Note

This is a expansion of the originally published bash_logging GitHub gist published by @GingerGraham.

Primary artifact

The core deliverable of this repository is logging.sh. It is intentionally kept as a single, self-contained (and yes, long) Bash file so you can drop it next to your scripts and source it without any packaging steps. Everything else in the repo - docs, demos, and pipeline scripts - exists to support using that file.

Features

  • Standard syslog log levels (DEBUG, INFO, WARN, ERROR, CRITICAL, etc.)
  • Console output with color-coding by severity
  • Configurable stdout/stderr output stream split
  • Optional file output
  • Optional systemd journal logging
  • Customizable log format
  • UTC or local time support
  • INI configuration file support
  • Runtime configuration changes
  • Special handling for sensitive data

Quick Start

# 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"

See Getting Started for detailed installation and basic usage instructions.

Documentation

Core Documentation

Advanced Topics

Reference

Common Use Cases

Basic Script Logging

source /path/to/logging.sh
init_logger
log_info "Script starting"

See: Getting Started

Logging to File

init_logger --log "/var/log/myapp.log" --level INFO

See: Initialization

Using Configuration Files

init_logger --config /etc/myapp/logging.conf

See: Configuration

Journal Integration

init_logger --journal --tag "myapp"

See: Journal Logging

Testing

The project includes a comprehensive test suite to verify all functionality. To run the tests:

cd tests
./run_tests.sh

See tests/README.md and Testing for more information.

Contributing

Contributions are welcome! Please see CONTRIBUTING.md for guidelines.

The project uses pre-commit hooks for code quality checks (ShellCheck, MarkdownLint, etc.). The CI lint workflow runs these same hooks, so tool versions are centralized in .pre-commit-config.yaml. See docs/PRE-COMMIT.md for setup instructions.

Maintainers

This project is currently maintained by @GingerGraham.

License

This module is provided under the MIT License.

About

A flexible, reusable logging module for Bash scripts that provides standardized logging functionality with various configuration options.

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Packages

No packages published

Contributors 6

Languages