Last active
December 12, 2015 06:49
-
-
Save nixpulvis/4732407 to your computer and use it in GitHub Desktop.
shell logging
This file contains 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
# Color escapes | |
RESET="\e[0m" | |
RED="\e[31m" | |
GREEN="\e[32m" | |
YELLOW="\e[33m" | |
LOGFILE_DIR="$HOME" | |
DATETIME=`date "+%m_%d_%Y_%H.%M.%S"` | |
LOGFILE="$LOGFILE_DIR/build_$DATETIME.log" | |
touch $LOGFILE | |
# Log and display both STDOUT and STDERR | |
log() { | |
$@ 2>&1 | tee -a $LOGFILE | |
} | |
# Log both STDOUT and STDERR but display only STDERR | |
log!() { | |
($@ >> $LOGFILE) 2>&1 | tee -a $LOGFILE >&2 | |
} | |
log_and_print_red() { | |
printf "$RED"; log $@; printf "$RESET" | |
} | |
log_and_print_red!() { | |
printf "$RED"; log! $@; printf "$RESET" | |
} | |
log_and_print_green() { | |
printf "$GREEN"; log $@; printf "$RESET" | |
} | |
log_and_print_green!() { | |
printf "$GREEN"; log! $@; printf "$RESET" | |
} | |
log_and_print_yellow() { | |
printf "$YELLOW"; log $@; printf "$RESET" | |
} | |
log_and_print_yellow!() { | |
printf "$YELLOW"; log! $@; printf "$RESET" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment