Skip to content

Instantly share code, notes, and snippets.

@shawngmc
Last active April 9, 2024 13:26
Show Gist options
  • Save shawngmc/58a2717b9ba66cbbc451aef8bd8040b6 to your computer and use it in GitHub Desktop.
Save shawngmc/58a2717b9ba66cbbc451aef8bd8040b6 to your computer and use it in GitHub Desktop.
Bash utils script
#!/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