diff --git a/src/script/logrotate-wifibox.conf b/src/script/logrotate-wifibox.conf index edc6176..4c5a672 100644 --- a/src/script/logrotate-wifibox.conf +++ b/src/script/logrotate-wifibox.conf @@ -9,5 +9,28 @@ create size 1000k missingok olddir /tmp/wifibox-rotated - copytruncate + + # as alternative to copytruncate (which *might* miss lines) we could implement + # SIGUSR1 in print3d and firmware to reopen their logs + copytruncate # 'create' is ignored with copytruncate, as the file stays in place + + prerotate + FIRST_N_LINES=500 + PRINT3D_LOGHEAD_FILE=print3d-loghead + WIFIBOX_LOGHEAD_FILE=wifibox-loghead + ROTATED_FILES_PATH=/tmp/wifibox-rotated + + #Note: by looking at creation date of the print3d socket and comparing against that + # of print3d-loghead we could detect a server restart (e.g. due to reconnected printer) + + echo "$1" | grep -q "print3d-.*\.log" + if [ $? -eq 0 -a ! -f "$ROTATED_FILES_PATH/$PRINT3D_LOGHEAD_FILE" ]; then + head -q -n$FIRST_N_LINES "$1" > "$ROTATED_FILES_PATH/$PRINT3D_LOGHEAD_FILE" + fi + + echo "$1" | grep -q "wifibox.log" + if [ $? -eq 0 -a ! -f "$ROTATED_FILES_PATH/$WIFIBOX_LOGHEAD_FILE" ]; then + head -q -n$FIRST_N_LINES "$1" > "$ROTATED_FILES_PATH/$WIFIBOX_LOGHEAD_FILE" + fi + endscript }