Created
June 24, 2025 00:49
-
-
Save amxv/8f1c3f800283d883d8adad28bffad68d to your computer and use it in GitHub Desktop.
logdev - Run development commands with continuous logging to logs/server.log
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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