linux bash colorful log.

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

# Check for root
if [[ "$(id -u)" == "0" ]]
then
echo "$fail Do not run this script as root."
exit 1
fi

disableColor=""

if [[ $disableColor == "" ]] || [[ $disableColor == false ]]
then
fail="[$(tput setaf 1) FAIL $(tput sgr0)]"
ok="[$(tput setaf 2) OK $(tput sgr0)]"
running="[$(tput setaf 3) ** $(tput sgr0)]"
notice="[$(tput setaf 3)NOTICE$(tput sgr0)]"
warn="[$(tput setaf 3) WARN $(tput sgr0)]"
info="[$(tput setaf 6) INFO $(tput sgr0)]"
finish="[$(tput setaf 4) DONE $(tput sgr0)]"
elif [[ $disableColor == true ]]
then
fail="[ FAIL ]"
ok="[ OK ]"
running="[ ** ]"
notice="[NOTICE]"
warn="[ WARN ]"
info="[ INFO ]"
finish="[ DONE ]"
else
echo "Unknown disableColor setting."
exit 1
fi

echo "$fail this is fail."
echo "$ok this is OK."
echo "$running this is running."
echo "$notice this is notice."
echo "$warn this is warn."
echo "$info this is info."
echo "$finish this is finish."