So, in bash shell script use
#!/bin/bash . logger.sh info starting .... info finished #ENDwhere logger.sh is somewhere in your path and has the content
#!/bin/bash
# logger.sh
#
# info, warning, error and fatal functions to display timestamped
# messages to stderr. Use the infof, warningf, errorf and fatalf
# functions to format the message using printf. A newline is
# automatically added and should not be included in your printf
# format string.
function info {
log INFO $*
}
function infof {
logf INFO $*
}
function warning {
log WARNING $*
}
function warningf {
logf WARNING $*
}
function error {
log ERROR $*
}
function errorf {
logf ERROR $*
}
function fatal {
log FATAL $*
exit 1;
}
function fatalf {
logf FATAL $*
exit 1;
}
function log {
echo $(date +'%F %T') $* 1>&2
}
function logf {
level=$1
format=$2
shift 2
printf "$(date +'%F %T') $level $format\n" $* 1>&2
}
# END
Most other languages have extensive logging support.Hardly seems worth posting such an obvious piece of advice, but look around into your scripts -- as I did mine -- and notice how few provide this data.