Skip to content

Instantly share code, notes, and snippets.

@sjessa
Last active July 13, 2016 00:52
Show Gist options
  • Save sjessa/5e1565cb3af1949b9c867e1c4b88e713 to your computer and use it in GitHub Desktop.
Save sjessa/5e1565cb3af1949b9c867e1c4b88e713 to your computer and use it in GitHub Desktop.
log your make commands & output
# Usage: $ lmake <make options here> <optional make target>
function lmake ()
{
echo "Appending make command output to make.log"
echo "Running command..."
echo "" >>make.log
echo "------------------------------------------" >>make.log
echo " MAKE LAUNCHED" >>make.log
echo " start: $(date +"%Y-%m-%d %H:%M")" >>make.log
echo " command: make $@" >>make.log
echo "------------------------------------------" >>make.log
make $@ \
2> >(perl -pe 'use POSIX strftime; print strftime "[%Y-%m-%d %H:%M:%S] [ERR]: ", localtime') \
1> >(perl -pe 'use POSIX strftime; if ($_ =~ m/failed/) {print strftime "[%Y-%m-%d %H:%M:%S] [ERR]: ", localtime} else {print strftime "[%Y-%m-%d %H:%M:%S] [OUT]: ", localtime'}) \
| tee -a make.log
echo "" >>make.log
echo "------------------------------------------" >>make.log
echo " MAKE COMPLETE" >>make.log
echo " end: $(date +"%Y-%m-%d %H:%M")" >>make.log
echo "------------------------------------------" >>make.log
}
@sjessa
Copy link
Author

sjessa commented Jul 12, 2016

log your make commands!
  • record exact command with options
  • prepend every line of output with a timestamp
  • prepend STDOUT lines with OUT
  • prepend STDERR lines with ERR
  • append all output to make.log in the working dir and display on screen
usage:

Add the lmake function to your .bashrc and do source ~/.bashrc
To run, simply replace make with lmake in your command as in $ lmake <make options here> <optional make target>

example:
$ lmake -k -j 4
Appending make command output to make.log
Running command...
[2016-07-12 16:33:07] [OUT]:  make: Nothing to be done for 'all'.

$ cat make.log
------------------------------------------
 MAKE LAUNCHED
 start: 2016-07-12 16:33
 command: make -k -j 4
------------------------------------------
[2016-07-12 16:33:07] [OUT]:  make: Nothing to be done for 'all'.

------------------------------------------
 MAKE COMPLETE
 end: 2016-07-12 16:33
------------------------------------------

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment