This repository has been archived by the owner on Mar 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #90 from Modicrumb/dev
Logging added to bash files and logs appended to /var/log/cakephp/cak…
- Loading branch information
Showing
7 changed files
with
169 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#!/usr/bin/env bash | ||
|
||
SCRIPT_LOG=/var/log/cakephp/cakebox.cli.log | ||
|
||
## Given a timestamp, message, and tag generate a LogStash Log | ||
function generate_log() { | ||
declare -A logArray | ||
logArray[timestamp]="\"$1\"" | ||
logArray[source]='"cakebox"' | ||
logArray[fields]="{\"channel\":\"cli.cakebox\",\"level\":100,\"ctxt_scope\":[]}" | ||
logArray[message]="\"$2\"" | ||
logArray[tags]="[\"cli.cakebox\", \"$3\"]" | ||
logArray[type]='"cakephp"' | ||
|
||
printf '{' | ||
for lkey in "${!logArray[@]}" | ||
do | ||
printf '"@%s":%s,' "$lkey" "${logArray[$lkey]}" | ||
done | ||
echo '}' | ||
|
||
} | ||
|
||
|
||
function SCRIPTENTRY(){ | ||
timestamp=$( date -u +"%Y-%m-%dT%H:%M:%S.%3N%:z" ) | ||
script_name=`basename "$0"` | ||
script_name="${script_name%.*}" | ||
message="started $script_name" | ||
generate_log "$timestamp" "$message" 'debug' >> $SCRIPT_LOG | ||
} | ||
|
||
function SCRIPTEXIT(){ | ||
script_name=`basename "$0"` | ||
script_name="${script_name%.*}" | ||
message="exited $script_name" | ||
generate_log "$timestamp" "$message" 'debug' >> $SCRIPT_LOG | ||
} | ||
|
||
function ENTRY(){ | ||
local cfn="${FUNCNAME[1]}" | ||
timestamp=$( date -u +"%Y-%m-%dT%H:%M:%S.%3N%:z" ) | ||
message="$cfn $FUNCNAME" | ||
generate_log "$timestamp" "$message" 'debug' >> $SCRIPT_LOG | ||
} | ||
|
||
function EXIT(){ | ||
local cfn="${FUNCNAME[1]}" | ||
timestamp=$( date -u +"%Y-%m-%dT%H:%M:%S.%3N%:z" ) | ||
message="$cfn $FUNCNAME" | ||
generate_log "$timestamp" "$message" 'debug' >> $SCRIPT_LOG | ||
} | ||
|
||
|
||
function INFO(){ | ||
local function_name="${FUNCNAME[1]}" | ||
local message="$1" | ||
timestamp=$( date -u +"%Y-%m-%dT%H:%M:%S.%3N%:z" ) | ||
generate_log "$timestamp" "$message" 'info' >> $SCRIPT_LOG | ||
} | ||
|
||
|
||
function DEBUG(){ | ||
local function_name="${FUNCNAME[1]}" | ||
local message="$1" | ||
timestamp=$( date -u +"%Y-%m-%dT%H:%M:%S.%3N%:z" ) | ||
generate_log "$timestamp" "$message" 'debug' >> $SCRIPT_LOG | ||
} | ||
|
||
function ERROR(){ | ||
local function_name="${FUNCNAME[1]}" | ||
local message="$1" | ||
timestamp=$( date -u +"%Y-%m-%dT%H:%M:%S.%3N%:z" ) | ||
generate_log "$timestamp" "$message" 'error' >> $SCRIPT_LOG | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.