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
  1. #! /bin/bash
  2.  
  3. # Include and initialise logging library
  4. source /usr/lib/outlogger.sh
  5. init_logging /var/log/example
  6.  
  7. # If we are running in quiet mode then redirect output to the log
  8. # otherwise tee output to the log and stdout
  9. if [[ -n ${QUIET} ]]; then
  10.     redirect_output_to_file update.out.log
  11. else
  12.     tee_output_to_file_stdout update.out.log
  13. fi
  14.  
  15. # Do a pretend update for the logs
  16. exec_and_log pretend_update "emerge --color n --nospinner -pvuDN world"
  17.  
  18. # End logging redirect
  19. end_log_redirect
  20.  
  21. # Bzip any log files larger than 100k
  22. bzip_large_logs 102400
  23.  
  24. # If we were asked to send email send the logs to root
  25. if [[ -n ${SENDEMAIL} ]]; then
  26.     send_logs_by_email "Automated update of ${BUILDSPACE_NAME}" root
  27. fi
  28.  
  29. # If we aren't running in quiet mode show a list of the log files we generated during the update
  30. if [[ -z ${QUIET} ]]; then
  31.     display_log_paths
  32. fi
Example code demonstrating basic use of the bash-outlogger library