_log.sh
1.1 KB
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
# import log utility and check the detail log file is ok
# @param log the log file path, default to /dev/null
#######################################
# color echo.
#######################################
RED="\\033[31m"
GREEN="\\033[32m"
YELLOW="\\033[33m"
BLACK="\\033[0m"
POS="\\033[94G"
# if need to log to file, change the log path.
if [[ ! $log ]]; then
log=/dev/null;
fi
ok_msg(){
echo -e "${1}${POS}${BLACK}[${GREEN} OK ${BLACK}]"
# write to log file.
echo "[info] ${1}" >> $log
}
warn_msg(){
echo -e "${1}${POS}${BLACK}[ ${YELLOW}WARN${BLACK} ]"
# write to log file.
echo "[error] ${1}" >> $log
}
failed_msg(){
echo -e "${1}${POS}${BLACK}[${RED}FAILED${BLACK}]"
# write to log file.
echo "[error] ${1}" >> $log
}
function check_log(){
log_dir="`dirname $log`"
(mkdir -p ${log_dir} && chmod 777 ${log_dir} && touch $log)
ret=$?; if [[ $ret -ne 0 ]]; then failed_msg "create log failed, ret=$ret"; return $ret; fi
ok_msg "create log( ${log} ) success"
echo "bravo-vms setup `date`" >> $log
ok_msg "see detail log: tailf ${log}"
return 0
}