-
Notifications
You must be signed in to change notification settings - Fork 0
/
fnc_logging.sh
189 lines (132 loc) · 3.8 KB
/
fnc_logging.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#
#
#
# assigments of logging channels
# 1 = stdout = exec 1> >(stdoutlog) # [STDOUT]
# 2 = stderr = exec 2> >(sterrlog) # [STDERR]
# 3 = info1 = exec 3>> $log3 # [info1]
# 4 = info2 = exec 4>> $log3 # [info2]
# 5 = debug = exec 5>> $log3 # [DEBUG]
# 6 = send = exec 6>> >(sendlog) # [send-1]
# 7 = send = exec 7>> $log6 # formating for zfs send
# 8 = recv = exec 8>> >(recvlog) # [recv-1]
# 9 = recv = exec 9>> $log3 # formating for zfs recv
log3="$log_file3"
log6="$log_file6"
#1
stdoutlog () {
while read line ;do
echo "[STDOUT] $line" >> $log3
done
}
#2
stderrlog () {
while read line ;do
echo "[STDERR] $line" >> $log3
done
}
#6 incrementaly skips more send progress lines simple version 1
sendlog1 () {
local lcount=0 #line count before print , then reset, and repeat
local tcount=0 #total line count with numbers , for sorting cond
while read line ;do
#majority of send lines with time upfront that we want to prune
if [ -n "$(echo $line | grep ^[0-9][0-9]:)" ] ; then
((lcount++))
((tcount++))
#echo "lcount=($lcount) tcount=($tcount)" 1>&5 # for debugging
if [ "$tcount" -le 10 ] ;then
echo "[send-1] $line" >> $log6
lcount=0
elif [ "$tcount" -le 100 ] && [ "$lcount" -eq 5 ] ;then
echo "[send-1] $line" >> $log6
lcount=0
elif [ "$tcount" -gt 100 ] && [ "$lcount" -eq 10 ] ;then
echo "[send-1] $line" >> $log6
lcount=0
fi
[ "$tcount" -eq 10 ] && echo "[send-1] print every 5-th line" >> $log6
[ "$tcount" -eq 100 ] && echo "[send-1] print every 10-th line" >> $log6
#minority of send info lines we want to keep
else
lcount=0
tcount=0
if [ -n "$(echo $line | grep ^'send from')" ] ; then
echo "[send-1] $line " | sed 's! to !\n[send-1] to -----> !g' >> $log6
else
echo "[send-1] $line" >> $log6
fi
fi
done
}
#6 incrementaly skips more send progress lines version 2 (unfinished)
sendlog2 () {
local lcount=0 #line count before print , then reset, and repeat
local lskip=1 #increments the nth line to print
local count=0 #counts printed lines before incrementing skip
while read line ;do
#majority of send lines with time upfront that we want to prune
if [ -n "$(echo $line | grep ^[0-9][0-9]:)" ] ; then
((lcount++))
#echo "lcount=($lcount) skip=($skip) count=($count)" 1>&3 # for debugging
if [ "$lcount" -eq "$lskip" ] ;then
echo "[send-2] $line" >> $log6
((count++))
lcount=0
if [ "$count" -ge 5 ] ;then
((skip++))
count=0
echo "[send-2] switching to print every $lskip(d-th) line" >> $log6
fi
fi
#minority of send info lines we want to keep
else
echo "[send-2] $line" >> $log6
lcount=0
skip=1
fi
done
}
#8 adds [recv-1] to each line and splits up long recv lines in two
recvlog () {
while read line ;do
if [ -n "$(echo $line | grep "^receiving full")" ] ;then
echo "[recv-1] $line" | sed 's! into !\n[recv-1] into ------------------> !g' >> $log3
elif [ -n "$(echo $line | grep "^receiving incremental")" ] ;then
echo "[recv-1] $line" | sed 's! into !\n[recv-1] into -------------------------> !g' >> $log3
else
echo "[recv-1] $line" >> $log3
fi
done
}
exec 1> >(stdoutlog)
exec 2> >(stderrlog)
#verbose and debug
if [ "$verbose" = 1 ] ;then
exec 3>> $log3
exec 4> /dev/null
exec 5> /dev/null
elif [ "$verbose" = 2 ] ;then
exec 3>> $log3
exec 4>> $log3
exec 5> /dev/null
elif [ "$verbose" = 3 ] ;then
exec 3>> $log3
exec 4>> $log3
exec 5>> $log3
else
exec 3> /dev/null
exec 4> /dev/null
exec 5> /dev/null
fi
# send logging
exec 6> >(sendlog1)
exec 7>> $log6
# recv logging
if [ "$verbrecv" = 1 ] ;then
exec 8> >(recvlog)
exec 9>> $log3
else
exec 8> /dev/null
exec 9> /dev/null
fi