diff --git a/webif/html/settings/modules/advanced/init.hook b/webif/html/settings/modules/advanced/init.hook
index ac2e8a9..9cf79eb 100644
--- a/webif/html/settings/modules/advanced/init.hook
+++ b/webif/html/settings/modules/advanced/init.hook
@@ -30,6 +30,7 @@ set pkgdev [$settings pkgdev]
set rtschedule [$settings rtschedule]
set logsize [$settings logsize]
set logkeep [$settings logkeep]
+set logage [$settings logage]
set cryptokey [system encryptionkey]
if {![catch {set ck_fd [open "/mod/boot/cryptokey"]}]} {
@@ -45,4 +46,5 @@ handle_int_update pkgdev $pkgdev "Development Package Display"
handle_int_update rtschedule $rtschedule "Real-time scheduling"
handle_int_update logsize $logsize "Log rotation size"
handle_int_update logkeep $logkeep "Logs to keep"
+handle_int_update logage $logage "Rotated log max age"
diff --git a/webif/html/settings/modules/advanced/settings.hook b/webif/html/settings/modules/advanced/settings.hook
index a086ebf..d32240c 100755
--- a/webif/html/settings/modules/advanced/settings.hook
+++ b/webif/html/settings/modules/advanced/settings.hook
@@ -41,6 +41,9 @@ puts "
setting_number logkeep "How many rotated logs to keep" $logkeep \
1 100
+setting_number logage "Delete old logs after X days" $logage \
+ 0 365
+
if {[system modversion 1] >= 214} {
setting_toggle "Disable telnet menu?" "xtelnet" \
[file exists /mod/boot/xtelnet] 0 1
diff --git a/webif/lib/bin/manage_logs b/webif/lib/bin/manage_logs
index 08af5b8..07680d5 100755
--- a/webif/lib/bin/manage_logs
+++ b/webif/lib/bin/manage_logs
@@ -6,18 +6,19 @@ require settings.class
set s [settings]
set logsize [$s logsize]
set logkeep [$s logkeep]
+set logage [$s logage]
-puts "Rotating at $logsize, keeping $logkeep"
+puts "Rotating at $logsize, keeping $logkeep, max age $logage"
set logdir "/mod/tmp"
set baselogs {}
puts "\n-- Rotate\n"
+set tstamp [clock format [clock seconds] -format {%Y%m%d%H%M%S}]
foreach log [glob -nocomplain -tail -directory $logdir *.log] {
puts "\[$log\]"
- set tstamp [clock format [clock seconds] -format {%Y%m%d%H%M%S}]
# Check for old-style rotated log.
if {[string match {*_old.log} $log]} {
@@ -30,6 +31,15 @@ foreach log [glob -nocomplain -tail -directory $logdir *.log] {
# Check for already rotated log.
if {[regexp -- {\.[0-9]{14}\.log$} $log]} {
puts " already rotated."
+ if {$logage > 0} {
+ set days $(
+ ([clock seconds] - [file mtime $logdir/$log])
+ / 86400)
+ if {$days > $logage} {
+ file tdelete "$logdir/$log"
+ puts " Deleting old log $log (age=$days)"
+ }
+ }
continue
}
@@ -61,7 +71,7 @@ foreach log $baselogs {
if {$num <= $logkeep} continue
lmap i [lrange [lsort -command logsort $old] 0 end-$logkeep] {
- puts " Deleting old log $i"
+ puts " Deleting old log $i"
file tdelete "$logdir/$i"
}
}
diff --git a/webif/lib/settings.class b/webif/lib/settings.class
index 5ce7e3f..cbbadab 100644
--- a/webif/lib/settings.class
+++ b/webif/lib/settings.class
@@ -49,6 +49,7 @@ class settings {
audiomp3 0
logsize 1048576
logkeep 2
+ logage 0
rtschedule 0
}
@@ -414,6 +415,11 @@ settings method logkeep {{num -1}} {
return $val
}
+settings method logage {{num -1}} {
+ set val [$self _nval_setting logage $num]
+ return $val
+}
+
settings method dedup_template {{pattern -1}} {
set val [$self _tval_setting dedup_template $pattern]
if {$val eq "0"} { set val "s%se%E - " }