Hi,
I've opened feature issue #6395 to enable log rotation in pgAdmin4 v5.
Please find the attached basic patch as a starter for 10. It's the same
patch attached to the feature issue.
Thanks a lot,
Tom
diff -Naur orig/__init__.py new/__init__.py
--- orig/__init__.py 2021-04-16 17:22:51.816949501 +0100
+++ new/__init__.py 2021-04-16 17:24:46.583081282 +0100
@@ -10,6 +10,7 @@
"""The main pgAdmin module. This handles the application initialisation tasks,
such as setup of logging, dynamic loading of modules etc."""
import logging
+from logging.handlers import RotatingFileHandler
import os
import sys
import re
@@ -254,11 +255,17 @@
# Ensure the various working directories exist
from pgadmin.setup import create_app_data_directory
create_app_data_directory(config)
+
+ if config.LOG_ROTATION_MAX_BYTES and config.LOG_ROTATION_NUM_BACKUPS:
+ # Rotated File logging
+ fh = RotatingFileHandler(config.LOG_FILE, mode='a', maxBytes=config.LOG_ROTATION_MAX_BYTES, backupCount=config.LOG_ROTATION_NUM_BACKUPS, encoding='utf-8', delay=False)
+ else:
+ # File logging
+ fh = logging.FileHandler(config.LOG_FILE, encoding='utf-8')
- # File logging
- fh = logging.FileHandler(config.LOG_FILE, encoding='utf-8')
fh.setLevel(config.FILE_LOG_LEVEL)
fh.setFormatter(logging.Formatter(config.FILE_LOG_FORMAT))
+
app.logger.addHandler(fh)
logger.addHandler(fh)