Basic use
Example 1
The following example code, taken from the update-buildspaces application,
demonstrates the basic use of the bash-outlogger library.
Listing 1
#! /bin/bash
# Include and initialise logging library
source /usr/lib/outlogger.sh
init_logging /var/log/example
# If we are running in quiet mode then redirect output to the log
# otherwise tee output to the log and stdout
if [[ -n ${QUIET} ]]; then
redirect_output_to_file update.out.log
else
tee_output_to_file_stdout update.out.log
fi
# Do a pretend update for the logs
exec_and_log pretend_update "emerge --color n --nospinner -pvuDN world"
# End logging redirect
end_log_redirect
# Bzip any log files larger than 100k
bzip_large_logs 102400
# If we were asked to send email send the logs to root
if [[ -n ${SENDEMAIL} ]]; then
send_logs_by_email "Automated update of ${BUILDSPACE_NAME}" root
fi
# If we aren't running in quiet mode show a list of the log files we generated during the update
if [[ -z ${QUIET} ]]; then
display_log_paths
fi