Skip to content

Instantly share code, notes, and snippets.

@T1T4N
Last active January 9, 2018 08:41
Show Gist options
  • Save T1T4N/5f3264b174acd521b6f84682b2ce32fd to your computer and use it in GitHub Desktop.
Save T1T4N/5f3264b174acd521b6f84682b2ce32fd to your computer and use it in GitHub Desktop.
Simple bash logging to a file
#!/usr/bin/env bash
readonly LOG_FILE="/tmp/$(basename "$0").log"
log_i() { echo "[INFO] $*" | tee -a "$LOG_FILE" >&2; }
log_w() { echo "[WARNING] $*" | tee -a "$LOG_FILE" >&2; }
log_e() { echo "[ERROR] $*" | tee -a "$LOG_FILE" >&2; }
log_f() { echo "[FATAL] $*" | tee -a "$LOG_FILE" >&2; return 1; }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment