ulfben

logger.sh

Apr 21st, 2020
418
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2. SCRIPT_LOG=/var/log/mycustom.log
  3. touch $SCRIPT_LOG
  4.  
  5. function SCRIPTENTRY(){
  6.     timestamp=$(date +"%F %T")
  7.     script_name=$(basename "$0")
  8.     script_name="${script_name%.*}"
  9.     echo "[$timestamp] [DEBUG]  > $script_name $FUNCNAME[0]" >> $SCRIPT_LOG
  10. }
  11.  
  12. function SCRIPTEXIT(){
  13.     script_name=$(basename "$0")
  14.     script_name="${script_name%.*}"
  15.     echo "[$timestamp] [DEBUG]  < $script_name $FUNCNAME[0]" >> $SCRIPT_LOG
  16. }
  17.  
  18. function ENTRY(){
  19.     local cfn="${FUNCNAME[1]}"
  20.     timestamp=$(date +"%F %T")
  21.     echo "[$timestamp] [DEBUG]  > $cfn $FUNCNAME[0]" >> $SCRIPT_LOG
  22. }
  23.  
  24. function EXIT(){
  25.     local cfn="${FUNCNAME[1]}"
  26.     timestamp=$(date +"%F %T")
  27.     echo "[$timestamp] [DEBUG]  < $cfn $FUNCNAME[0]" >> $SCRIPT_LOG
  28. }
  29.  
  30.  
  31. function INFO(){
  32.     local function_name="${FUNCNAME[1]}"
  33.     local msg="$1"
  34.     timestamp=$(date +"%F %T")
  35.     echo "[$timestamp] [INFO]  $msg" >> $SCRIPT_LOG
  36. }
  37.  
  38.  
  39. function DEBUG(){
  40.     local function_name="${FUNCNAME[1]}"
  41.     local msg="$1"
  42.     timestamp=$(date +"%F %T")
  43.     echo "[$timestamp] [DEBUG]  $msg" >> $SCRIPT_LOG
  44. }
  45.  
  46. function ERROR(){
  47.     local function_name="${FUNCNAME[1]}"
  48.     local msg="$1"
  49.     timestamp=$(date +"%F %T")
  50.     echo "[$timestamp] [ERROR]  $msg" >> $SCRIPT_LOG
  51. }
  52.  
  53. #### Usage: ####
  54.  
  55. #!/bin/bash
  56. #source ./logger.sh
  57. #SCRIPTENTRY
  58. #function testFunction(){
  59. #    ENTRY
  60. #    DEBUG "Argument 1: $1, Argument 2: $2"
  61. #    INFO "something something"
  62. #    EXIT
  63. #}
  64. #INFO "Updating user details..."
  65. #testFunction "test" "0123"
  66. #SCRIPTEXIT
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×