Last active
April 9, 2024 13:26
-
-
Save shawngmc/58a2717b9ba66cbbc451aef8bd8040b6 to your computer and use it in GitHub Desktop.
Bash utils script
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
#!/bin/bash | |
logMessage() { | |
local MESSAGE=$1; | |
local TIMESTAMP=""; | |
TIMESTAMP=$(date +%Y-%m-%dT%H:%M:%S.%3NZ); | |
local CALLER=""; | |
CALLER=$(readlink -f "$0"); | |
echo "$TIMESTAMP: [$CALLER] $MESSAGE"; | |
} | |
logJsonMessage() { | |
local MESSAGE=$1; | |
local TIMESTAMP=""; | |
TIMESTAMP=$(date +%Y-%m-%dT%H:%M:%S.%3NZ); | |
local CALLER=""; | |
CALLER=$(readlink -f "$0"); | |
local JSON_STRING=""; | |
JSON_STRING=$(jq -c -r -n --arg ts "$TIMESTAMP" --arg scr "$CALLER" --arg msg "$MESSAGE" "{time: \$ts, script: \$scr, message: \$msg}"); | |
echo "$JSON_STRING"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment