“Great logs don't just tell you what went wrong — they help you understand why it happened.” Whether you're automating a deployment or writing a bash script to clean up temp files, there's one thing your future self will always thank you for: clear, timestamped, consistent logging. Why Even Bother With Logging? Shell scripts often get the job done fast — but when they go wrong, debugging them can feel like trying to read hieroglyphics in the dark. Logging provides a flashlight. It tells you what ran, when it ran, and how it ran — especially when you're not watching. This post walks you through a compact, reusable logger function for your shell scripts that: Categorizes messages by severity (INFO, DEBUG, ERROR, etc.) Automatically timestamps log entries Writes to a dedicated log file

May 5, 2025 - 16:06
 0

“Great logs don't just tell you what went wrong — they help you understand why it happened.”

Whether you're automating a deployment or writing a bash script to clean up temp files, there's one thing your future self will always thank you for: clear, timestamped, consistent logging.

Linux Logging

Why Even Bother With Logging?

Shell scripts often get the job done fast — but when they go wrong, debugging them can feel like trying to read hieroglyphics in the dark. Logging provides a flashlight. It tells you what ran, when it ran, and how it ran — especially when you're not watching.

This post walks you through a compact, reusable logger function for your shell scripts that:

  • Categorizes messages by severity (INFO, DEBUG, ERROR, etc.)
  • Automatically timestamps log entries
  • Writes to a dedicated log file