Source files of fsfe.org, pdfreaders.org, freeyourandroid.org, ilovefs.org, drm.info, and test.fsfe.org. Contribute: https://fsfe.org/contribute/web/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

logging.sh 943B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/bin/sh
  2. inc_logging=true
  3. logname(){
  4. name="$1"
  5. if [ -w "$statusdir" ] && touch "$statusdir/$name"; then
  6. echo "$statusdir/$name"
  7. elif echo "$forcedlog" |egrep -q "^${name}=.+"; then
  8. echo "$forcedlog" \
  9. | sed -rn "s;^${name}=;;p"
  10. else
  11. echo /dev/null
  12. fi
  13. }
  14. forcelog(){
  15. name="$1"
  16. [ "$(logname "$name")" = "/dev/null" ] \
  17. && forcedlog="$forcedlog\n${name}=$(mktemp -t w3bldXXXXXXXXX --suffix $$)"
  18. }
  19. [ -z "$USER" ] && USER="$(whoami)"
  20. trap "trap - 0 2 3 6 9 15; find \"${TMPDIR:-/tmp}/\" -maxdepth 1 -user \"$USER\" -name \"w3bld*$$\" -delete" 0 2 3 6 9 15
  21. logstatus(){
  22. # pipeline atom to write data streams into a log file
  23. tee "$(logname "$1")"
  24. }
  25. t_logstatus(){
  26. # pipeline atom to write data streams into a log file
  27. while read line; do
  28. printf "[$(date +%T)] %s\n" "$line"
  29. done |logstatus "$@"
  30. }
  31. logappend(){
  32. # pipeline atom to write data streams into a log file
  33. tee -a "$(logname "$1")"
  34. }