Compare commits
2 Commits
1a920e4e26
...
6f1714d100
Author | SHA1 | Date | |
---|---|---|---|
6f1714d100 | |||
b31d93b7be |
@ -16,7 +16,7 @@
|
|||||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import os
|
import os
|
||||||
from datetime import datetime, timezone
|
from datetime import datetime, timedelta, timezone
|
||||||
|
|
||||||
def clean_old_logs(log_dir, max_age_seconds=86400):
|
def clean_old_logs(log_dir, max_age_seconds=86400):
|
||||||
now = datetime.now(timezone.utc)
|
now = datetime.now(timezone.utc)
|
||||||
|
@ -122,13 +122,13 @@ int main(int argc, char* argv[]) {
|
|||||||
|
|
||||||
// Log rotation: Remove logs older than MAX_LOG_AGE_DAYS
|
// Log rotation: Remove logs older than MAX_LOG_AGE_DAYS
|
||||||
int maxLogAgeDays = config["MAX_LOG_AGE_DAYS"].as<int>();
|
int maxLogAgeDays = config["MAX_LOG_AGE_DAYS"].as<int>();
|
||||||
auto now = fs::file_time_type::clock::now(); // Use the same clock as file_time_type
|
auto now = fs::file_time_type::clock::now();
|
||||||
|
|
||||||
for (const auto& entry : fs::directory_iterator(LOG_DIR)) {
|
for (const auto& entry : fs::directory_iterator(LOG_DIR)) {
|
||||||
if (entry.is_regular_file()) {
|
if (entry.is_regular_file()) {
|
||||||
auto ftime = fs::last_write_time(entry.path());
|
auto ftime = fs::last_write_time(entry.path());
|
||||||
auto age = std::chrono::duration_cast<std::chrono::hours>(now - ftime).count() / 24;
|
auto age = std::chrono::duration_cast<std::chrono::hours>(now - ftime).count() / 24;
|
||||||
if (age > maxLogAgeDays) {
|
if (age >= maxLogAgeDays) {
|
||||||
fs::remove(entry.path());
|
fs::remove(entry.path());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user