-
Notifications
You must be signed in to change notification settings - Fork 0
/
logging-pre.sh
41 lines (35 loc) · 950 Bytes
/
logging-pre.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/bin/bash
#require posix-mode
#require file
#require string
# some of the bash features not available in POSIX mode, is needed here
posix_mode_disable
log_level_names=(emergency alert critical error warning notice info debug)
log_level_get_integer() {
case "$1" in
[0-7])
echo -n "$1"
;;
*)
local level
level="$(to_lower "$1")"
for ((i=0; i<${#log_level_names[@]}; ++i)); do
[ "$level" != "${log_level_names[$i]}" ] || {
echo -n "$i"
return 0
}
done
return 1
;;
esac
}
: "${log_level:=6}"
log_set_level() {
log_level="$(log_level_get_integer "$1")" || {
echo "Unknown log level" 1>&2
exit 1
}
}
# Is common log line prefix (application name and/or pid) defined?
# log_common_prefix=app-name
# log_common_prefix="app-name[$$]"