Skip to content

Instantly share code, notes, and snippets.

@OleksandrKucherenko
Created August 17, 2022 08:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OleksandrKucherenko/95bc19b9ee32af9f3c82ac1845c1dfe7 to your computer and use it in GitHub Desktop.
Save OleksandrKucherenko/95bc19b9ee32af9f3c82ac1845c1dfe7 to your computer and use it in GitHub Desktop.
Sample script that demonstrate usage of the Logger feature.
#!/usr/bin/env bash
#set -x # Uncomment to DEBUG
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$SCRIPT_DIR/logger.sh"
logger token "$@" # controlled by DEBUG=token,*
logger refresh "$@" # controlled by DEBUG=refresh,*
# terminal colors and utility functions, like: cl_grey, cl_reset
source "$SCRIPT_DIR/common.sh"
token_file=.secrets/tokenfile.json
token=$(cat "$token_file")
# extract JWT
access_token=$(echo "${token}" | jq -r '.access_token')
# sample 1
if [[ "$access_token" == "null" ]]; then
echo "Error. No access token found in provided JSON."
echoToken "${cl_grey}| STDOUT & STDERR:${cl_reset}" >&2
echoToken "${cl_grey}| ${token}${cl_reset}"
exit 1
fi
# sample 2
echo "[--] Processing file: ${cl_yellow}$token_file${cl_reset}"
json=$(cat $token_file)
echoRefresh "${cl_grey}| FILE CONTENT (trimmed):${cl_reset}" >&2
echo "${json}" | while read -r line; do echoRefresh "${cl_grey}| ${cl_reset}${line}" >&2; done
@OleksandrKucherenko
Copy link
Author

# print all debug info
DEBUG=* ./sample-of-use.sh

# print only token tag info
DEBUG=token ./sample-of-use.sh

# print all except token
DEBUG=*,-token ./sample-of-use.sh

# print all selecetd tags
DEBUG=token,refresh,sample ./sample-of-use.sh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment