-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlogger.sh
80 lines (69 loc) · 1.91 KB
/
logger.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env bash
# debug calls
shared_debug=${shared_debug:-0}
shared_logger_sh_loaded=${shared_logger_sh_loaded:-0}
if [ "x1" == "x${shared_logger_sh_loaded}" ]; then
if [ "x1" == "x${shared_debug}" ]; then
log "logger.sh already included"
fi
else
shared_logger_sh_loaded=1
shared_logger_tag=${shared_logger_tag:-}
shared_verbose=${shared_verbose:-1}
shared_logger_colored=${shared_logger_colored:-1}
shared_logger_echo_cmd="/bin/echo -e"
RED=''
GREEN=''
BLUE=''
CYAN=''
ORANGE=''
NC=''
if [ "${shared_logger_colored}" -eq 1 ]; then
RED='\033[0;31m'
GREEN='\033[0;32m'
ORANGE='\033[0;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
NC='\033[0m'
fi
function logger::header() {
local content=${1:-}
logger::write
logger::write "${CYAN}***${NC} ${content} ${CYAN}***${NC}"
logger::write
}
function logger::write() {
local content=${1:-}
if [ "x" == "x${shared_logger_tag}" ]; then
if [ "x1" == "x${shared_verbose}" ]; then
${shared_logger_echo_cmd} "${content}"
fi
else
if [ "x1" == "x${shared_verbose}" ]; then
${shared_logger_echo_cmd} "${content}"
fi
${shared_logger_echo_cmd} "${content}" | logger -t "${shared_logger_tag}"
fi
}
function logger::writealways() {
local content=${1:-}
if [ "x" == "x${shared_logger_tag}" ]; then
${shared_logger_echo_cmd} "${content}"
else
${shared_logger_echo_cmd} "${content}"
${shared_logger_echo_cmd} "${content}" | logger -t "${shared_logger_tag}"
fi
}
function logger::warn() {
local content=${1:-}
logger::writealways "${ORANGE}??${NC} ${content} ${ORANGE}??${NC}"
}
function logger::error() {
local content=${1:-}
(>&2 logger::writealways "${RED}!!${NC} ${content} ${RED}??${NC}")
}
function logger::log() {
local content=${1:-}
logger::write "${BLUE}-->${NC} ${GREEN}${content}${NC}"
}
fi