@@ -19,9 +19,77 @@ RED='\033[0;31m'
19
19
GREEN=' \033[0;32m'
20
20
YELLOW=' \033[0;33m'
21
21
BLUE=' \033[0;34m'
22
- NC=' \033[0m' # No Color
22
+ NC=' \033[0m' # No Colo# Logging display and formatting functions
23
23
24
- # Assume this script lives in share/github-backup-utils/ when setting the root
24
+ # Log a message to stdout
25
+ log_level () {
26
+ local level=$1
27
+ shift
28
+ local message=$*
29
+ local display=" "
30
+ local timestamp
31
+ timestamp=$( date -u " +%FT%TZ" )
32
+
33
+
34
+ if [ " $TERM " = " dumb" ] || [[ " $OUTPUT_COLOR " != " yes" ]]; then
35
+ if [ " $level " = " info" ]; then
36
+ display=" INFO"
37
+ elif [ " $level " = " warn" ]; then
38
+ display=" WARN"
39
+ elif [ " $level " = " error" ]; then
40
+ display=" ERROR"
41
+ elif [ " $level " = " verbose" ]; then
42
+ display=" INFO"
43
+ elif [ " $level " = " rsync" ]; then
44
+ display=" RSYNC"
45
+ elif [ " $level " = " ssh" ]; then
46
+ display=" SSH"
47
+ else
48
+ display=" -"
49
+ fi
50
+ else
51
+ if [ " $level " = " info" ]; then
52
+ display=" ${GREEN} INFO${NC} "
53
+ elif [ " $level " = " warn" ]; then
54
+ display=" ${YELLOW} WARN${NC} "
55
+ elif [ " $level " = " error" ]; then
56
+ display=" ${RED} ERROR${NC} "
57
+ elif [ " $level " = " verbose" ]; then
58
+ display=" ${GREEN} INFO${NC} "
59
+ elif [ " $level " = " rsync" ]; then
60
+ display=" ${GREEN} RSYNC${NC} "
61
+ elif [ " $level " = " ssh" ]; then
62
+ display=" ${GREEN} SSH${NC} "
63
+ else
64
+ display=" -"
65
+ fi
66
+ fi
67
+ echo -e " $timestamp $display $message "
68
+ }
69
+
70
+ log_info (){
71
+ log_level " info" " $1 "
72
+ }
73
+
74
+ log_warn (){
75
+ log_level " warn" " $1 "
76
+ }
77
+
78
+ log_error (){
79
+ log_level " error" " $1 "
80
+ }
81
+
82
+ log_verbose (){
83
+ log_level " verbose" " $1 "
84
+ }
85
+
86
+ log_rsync (){
87
+ log_level " rsync" " $1 "
88
+ }
89
+
90
+ log_ssh (){
91
+ log_level " ssh" " $1 "
92
+ } Assume this script lives in share/github-backup-utils/ when setting the root
25
93
GHE_BACKUP_ROOT=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) /../.." && pwd) "
26
94
27
95
# Get the version from the version file.
@@ -576,74 +644,4 @@ restore-secret() {
576
644
577
645
578
646
579
- # Logging display and formatting functions
580
647
581
- # Log a message to stdout
582
- log_level () {
583
- local level=$1
584
- shift
585
- local message=$*
586
- local display=" "
587
- local timestamp
588
- timestamp=$( date -u " +%FT%TZ" )
589
-
590
-
591
- if [ " $TERM " = " dumb" ] || [[ " $OUTPUT_COLOR " != " yes" ]]; then
592
- if [ " $level " = " info" ]; then
593
- display=" INFO"
594
- elif [ " $level " = " warn" ]; then
595
- display=" WARN"
596
- elif [ " $level " = " error" ]; then
597
- display=" ERROR"
598
- elif [ " $level " = " verbose" ]; then
599
- display=" INFO"
600
- elif [ " $level " = " rsync" ]; then
601
- display=" RSYNC"
602
- elif [ " $level " = " ssh" ]; then
603
- display=" SSH"
604
- else
605
- display=" -"
606
- fi
607
- else
608
- if [ " $level " = " info" ]; then
609
- display=" ${GREEN} INFO${NC} "
610
- elif [ " $level " = " warn" ]; then
611
- display=" ${YELLOW} WARN${NC} "
612
- elif [ " $level " = " error" ]; then
613
- display=" ${RED} ERROR${NC} "
614
- elif [ " $level " = " verbose" ]; then
615
- display=" ${GREEN} INFO${NC} "
616
- elif [ " $level " = " rsync" ]; then
617
- display=" ${GREEN} RSYNC${NC} "
618
- elif [ " $level " = " ssh" ]; then
619
- display=" ${GREEN} SSH${NC} "
620
- else
621
- display=" -"
622
- fi
623
- fi
624
- echo -e " $timestamp $display $message "
625
- }
626
-
627
- log_info (){
628
- log_level " info" " $1 "
629
- }
630
-
631
- log_warn (){
632
- log_level " warn" " $1 "
633
- }
634
-
635
- log_error (){
636
- log_level " error" " $1 "
637
- }
638
-
639
- log_verbose (){
640
- log_level " verbose" " $1 "
641
- }
642
-
643
- log_rsync (){
644
- log_level " rsync" " $1 "
645
- }
646
-
647
- log_ssh (){
648
- log_level " ssh" " $1 "
649
- }
0 commit comments