Skip to content

Instantly share code, notes, and snippets.

@amxv
Created June 24, 2025 00:49
Show Gist options
  • Select an option

  • Save amxv/8f1c3f800283d883d8adad28bffad68d to your computer and use it in GitHub Desktop.

Select an option

Save amxv/8f1c3f800283d883d8adad28bffad68d to your computer and use it in GitHub Desktop.
logdev - Run development commands with continuous logging to logs/server.log
#!/bin/bash
# logdev - Run development commands with continuous logging to logs/server.log
# Usage: logdev <command> [args...]
# Example: logdev next dev --turbo
# Check if any arguments were provided
if [ $# -eq 0 ]; then
echo "Usage: logdev <command> [args...]"
echo "Example: logdev next dev --turbo"
exit 1
fi
# Ensure logs directory exists
mkdir -p logs
# Run command with logging: clear log file, run with color, strip ANSI codes for file, add timestamps
( : > logs/server.log && FORCE_COLOR=1 "$@" 2>&1 ) | tee >(perl -pe 's/\x1B\[[0-9;]*[a-zA-Z]//g; $|=1' | while IFS= read -r line; do printf "[%s] %s\n" "$(date +'%Y-%m-%d %H:%M:%S')" "$line" >> logs/server.log; done)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment