Skip to content

Commit 556cdf6

Browse files
committed
distinguish between log levels
1 parent 255588f commit 556cdf6

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

scripts/log-levels.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
3+
VERBOSE=false
4+
HOST="google.com"
5+
PID="$$"
6+
PROGRAM_NAME="$0"
7+
THIS_HOST=$(hostname)
8+
9+
logit () {
10+
local LOG_LEVEL=$1
11+
shift
12+
MSG=$@
13+
TIMESTAMP=$(date +"%Y-%m-%d %T")
14+
if [ $LOG_LEVEL = 'ERROR' ] || $VERBOSE
15+
then
16+
echo "${TIMESTAMP} ${THIS_HOST} ${PROGRAM_NAME}[${PID}]: ${LOG_LEVEL} ${MSG}"
17+
fi
18+
}
19+
20+
logit INFO "Processing data."
21+
22+
fetch-data $HOST || logit ERROR "Could not fetch data from $HOST"

0 commit comments

Comments
 (0)