Skip to content

Commit 60b185d

Browse files
authored
Improve log_history function and limit max log file (hestiacp#3280)
Log files could exceed over xxx mb due lack of pruning Now deletes the first 251 lines when passing 750 lines
1 parent ef0f869 commit 60b185d

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

func/main.sh

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,20 +128,19 @@ log_history() {
128128
fi
129129
touch $log
130130

131-
# TODO: Improve log pruning and pagination
132-
#
133-
#if [ '1000' -lt "$(wc -l $log |cut -f 1 -d ' ')" ]; then
134-
# tail -n 499 $log > $log.moved
135-
# mv -f $log.moved $log
136-
# chmod 660 $log
137-
#fi
131+
if [ '750' -lt "$(wc -l $log | cut -f 1 -d ' ')" ]; then
132+
tail -n 499 $log > $log.moved
133+
mv -f $log.moved $log
134+
chmod 660 $log
135+
fi
138136

139137
if [ -z "$date" ]; then
140138
time_n_date=$(date +'%T %F')
141139
time=$(echo "$time_n_date" | cut -f 1 -d \ )
142140
date=$(echo "$time_n_date" | cut -f 2 -d \ )
143141
fi
144-
curr_str=$(grep "ID=" $log | cut -f 2 -d \' | sort -n | tail -n1)
142+
143+
curr_str=$(tail -n1 $log | grep "ID=" --text | cut -f2 -d \')
145144
id="$((curr_str + 1))"
146145
echo "ID='$id' DATE='$date' TIME='$time' LEVEL='$evt_level' CATEGORY='$evt_category' MESSAGE='$message'" >> $log
147146
}

0 commit comments

Comments
 (0)