Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- SCRIPT_LOG=/var/log/mycustom.log
- touch $SCRIPT_LOG
- function SCRIPTENTRY(){
- timestamp=$(date +"%F %T")
- script_name=$(basename "$0")
- script_name="${script_name%.*}"
- echo "[$timestamp] [DEBUG] > $script_name $FUNCNAME[0]" >> $SCRIPT_LOG
- }
- function SCRIPTEXIT(){
- script_name=$(basename "$0")
- script_name="${script_name%.*}"
- echo "[$timestamp] [DEBUG] < $script_name $FUNCNAME[0]" >> $SCRIPT_LOG
- }
- function ENTRY(){
- local cfn="${FUNCNAME[1]}"
- timestamp=$(date +"%F %T")
- echo "[$timestamp] [DEBUG] > $cfn $FUNCNAME[0]" >> $SCRIPT_LOG
- }
- function EXIT(){
- local cfn="${FUNCNAME[1]}"
- timestamp=$(date +"%F %T")
- echo "[$timestamp] [DEBUG] < $cfn $FUNCNAME[0]" >> $SCRIPT_LOG
- }
- function INFO(){
- local function_name="${FUNCNAME[1]}"
- local msg="$1"
- timestamp=$(date +"%F %T")
- echo "[$timestamp] [INFO] $msg" >> $SCRIPT_LOG
- }
- function DEBUG(){
- local function_name="${FUNCNAME[1]}"
- local msg="$1"
- timestamp=$(date +"%F %T")
- echo "[$timestamp] [DEBUG] $msg" >> $SCRIPT_LOG
- }
- function ERROR(){
- local function_name="${FUNCNAME[1]}"
- local msg="$1"
- timestamp=$(date +"%F %T")
- echo "[$timestamp] [ERROR] $msg" >> $SCRIPT_LOG
- }
- #### Usage: ####
- #!/bin/bash
- #source ./logger.sh
- #SCRIPTENTRY
- #function testFunction(){
- # ENTRY
- # DEBUG "Argument 1: $1, Argument 2: $2"
- # INFO "something something"
- # EXIT
- #}
- #INFO "Updating user details..."
- #testFunction "test" "0123"
- #SCRIPTEXIT
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement