public inbox for [email protected]
help / color / mirror / Atom feed[pgAdmin][Patch] - Feature #6395 - Feature request: Log Rotation
4+ messages / 2 participants
[nested] [flat]
* [pgAdmin][Patch] - Feature #6395 - Feature request: Log Rotation
@ 2021-05-25 05:23 Yogesh Mahajan <[email protected]>
2021-05-25 07:39 ` Re: [pgAdmin][Patch] - Feature #6395 - Feature request: Log Rotation Akshay Joshi <[email protected]>
0 siblings, 1 reply; 4+ messages in thread
From: Yogesh Mahajan @ 2021-05-25 05:23 UTC (permalink / raw)
To: pgadmin-hackers
Hi,
Please find the attached patch which rotates the pgadmin log file with
context to the parameters specified in the config file.
# Log rotation setting
LOG_ROTATION_SIZE = 10 # In MBs
LOG_ROTATION_AGE = 1440 # In minutes
LOG_ROTATION_MAX_LOGS = 90 # Maximum number of backups to retain
Thanks,
Yogesh Mahajan
EnterpriseDB
Attachments:
[application/x-patch] RM6395_v1.patch (3.8K, 3-RM6395_v1.patch)
download | inline diff:
diff --git a/web/config.py b/web/config.py
index 4d1f98698..663788e50 100644
--- a/web/config.py
+++ b/web/config.py
@@ -286,6 +286,10 @@ if SERVER_MODE and not IS_WIN:
else:
LOG_FILE = os.path.join(DATA_DIR, 'pgadmin4.log')
+# Log rotation setting
+LOG_ROTATION_SIZE = 10 # In MBs
+LOG_ROTATION_AGE = 1440 # In minutes
+LOG_ROTATION_MAX_LOGS = 90 # Maximum number of backups to retain
##########################################################################
# Server Connection Driver Settings
##########################################################################
diff --git a/web/pgadmin/__init__.py b/web/pgadmin/__init__.py
index a73335371..6449806f2 100644
--- a/web/pgadmin/__init__.py
+++ b/web/pgadmin/__init__.py
@@ -255,8 +255,14 @@ def create_app(app_name=None):
from pgadmin.setup import create_app_data_directory
create_app_data_directory(config)
- # File logging
- fh = logging.FileHandler(config.LOG_FILE, encoding='utf-8')
+ # File logging # Rotated File logging
+ from pgadmin.utils.enhanced_log_rotation import \
+ EnhancedRotatingFileHandler
+ fh = EnhancedRotatingFileHandler(config.LOG_FILE,
+ config.LOG_ROTATION_SIZE,
+ config.LOG_ROTATION_AGE,
+ config.LOG_ROTATION_MAX_LOGS)
+
fh.setLevel(config.FILE_LOG_LEVEL)
fh.setFormatter(logging.Formatter(config.FILE_LOG_FORMAT))
app.logger.addHandler(fh)
diff --git a/web/pgadmin/utils/enhanced_log_rotation.py b/web/pgadmin/utils/enhanced_log_rotation.py
new file mode 100644
index 000000000..b46c53420
--- /dev/null
+++ b/web/pgadmin/utils/enhanced_log_rotation.py
@@ -0,0 +1,46 @@
+##########################################################################
+#
+# pgAdmin 4 - PostgreSQL Tools
+#
+# Copyright (C) 2013 - 2021, The pgAdmin Development Team
+# This software is released under the PostgreSQL Licence
+#
+##########################################################################
+
+import re
+import logging.handlers as handlers
+
+
+class EnhancedRotatingFileHandler(handlers.TimedRotatingFileHandler,
+ handlers.RotatingFileHandler):
+ """
+ Handler for logging to a set of files, which switches from one file
+ to the next when the current file reaches a certain size, or at certain
+ timed intervals
+ """
+ def __init__(self, filename, max_bytes=1, interval=60, backup_count=0,
+ encoding=None, when='M'):
+ max_bytes = max_bytes * 1000000
+ handlers.TimedRotatingFileHandler.__init__(self, filename=filename,
+ when=when,
+ interval=interval,
+ backupCount=backup_count,
+ encoding=encoding)
+
+ handlers.RotatingFileHandler.__init__(self, filename=filename,
+ mode='a',
+ maxBytes=max_bytes,
+ backupCount=backup_count,
+ encoding=encoding)
+
+ # Time & Size combined rollover
+ def shouldRollover(self, record):
+ return handlers.TimedRotatingFileHandler.shouldRollover(self, record) \
+ or handlers.RotatingFileHandler.shouldRollover(self, record)
+
+ # Roll overs current file
+ def doRollover(self):
+ self.suffix = "%Y-%m-%d_%H-%M-%S"
+ self.extMatch = r"^\d{4}-\d{2}-\d{2}_\d{2}-\d{2}-\d{2}(\.\w+)?$"
+ self.extMatch = re.compile(self.extMatch, re.ASCII)
+ handlers.TimedRotatingFileHandler.doRollover(self)
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: [pgAdmin][Patch] - Feature #6395 - Feature request: Log Rotation
2021-05-25 05:23 [pgAdmin][Patch] - Feature #6395 - Feature request: Log Rotation Yogesh Mahajan <[email protected]>
@ 2021-05-25 07:39 ` Akshay Joshi <[email protected]>
2021-05-25 11:28 ` Re: [pgAdmin][Patch] - Feature #6395 - Feature request: Log Rotation Yogesh Mahajan <[email protected]>
0 siblings, 1 reply; 4+ messages in thread
From: Akshay Joshi @ 2021-05-25 07:39 UTC (permalink / raw)
To: Yogesh Mahajan <[email protected]>; +Cc: pgadmin-hackers
Hi Yogesh
Following are the review comments:
- LOG_ROTATION_MAX_LOGS should be renamed to LOG_ROTATION_MAX_LOG_FILES
- Rollover file name should have '.log' extension at the end instead of "
pgadmin4.log.2021-05-25_12-17-43"
- Add comments in the 'enhanced_log_rotation.py' file.
- 'enhanced_log_rotation.py' file line no 23 should be "max_bytes =
max_bytes * 1024 * 1024" instead of "max_bytes = max_bytes * 1000000"
On Tue, May 25, 2021 at 10:54 AM Yogesh Mahajan <
[email protected]> wrote:
> Hi,
>
> Please find the attached patch which rotates the pgadmin log file with
> context to the parameters specified in the config file.
>
> # Log rotation setting
> LOG_ROTATION_SIZE = 10 # In MBs
> LOG_ROTATION_AGE = 1440 # In minutes
> LOG_ROTATION_MAX_LOGS = 90 # Maximum number of backups to retain
>
>
> Thanks,
> Yogesh Mahajan
> EnterpriseDB
>
--
*Thanks & Regards*
*Akshay Joshi*
*pgAdmin Hacker | Principal Software Architect*
*EDB Postgres <http://edbpostgres.com>*
*Mobile: +91 976-788-8246*
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: [pgAdmin][Patch] - Feature #6395 - Feature request: Log Rotation
2021-05-25 05:23 [pgAdmin][Patch] - Feature #6395 - Feature request: Log Rotation Yogesh Mahajan <[email protected]>
2021-05-25 07:39 ` Re: [pgAdmin][Patch] - Feature #6395 - Feature request: Log Rotation Akshay Joshi <[email protected]>
@ 2021-05-25 11:28 ` Yogesh Mahajan <[email protected]>
2021-05-25 14:49 ` Re: [pgAdmin][Patch] - Feature #6395 - Feature request: Log Rotation Akshay Joshi <[email protected]>
0 siblings, 1 reply; 4+ messages in thread
From: Yogesh Mahajan @ 2021-05-25 11:28 UTC (permalink / raw)
To: pgadmin-hackers
Hello,
Please find the attached file incorporated with the above comments except
the 2nd one.
Thanks,
Yogesh Mahajan
EnterpriseDB
On Tue, May 25, 2021 at 1:09 PM Akshay Joshi <[email protected]>
wrote:
> Hi Yogesh
>
> Following are the review comments:
>
> - LOG_ROTATION_MAX_LOGS should be renamed to LOG_ROTATION_MAX_LOG_FILES
> - Rollover file name should have '.log' extension at the end instead
> of "pgadmin4.log.2021-05-25_12-17-43"
> - Add comments in the 'enhanced_log_rotation.py' file.
> - 'enhanced_log_rotation.py' file line no 23 should be "max_bytes =
> max_bytes * 1024 * 1024" instead of "max_bytes = max_bytes * 1000000"
>
>
> On Tue, May 25, 2021 at 10:54 AM Yogesh Mahajan <
> [email protected]> wrote:
>
>> Hi,
>>
>> Please find the attached patch which rotates the pgadmin log file with
>> context to the parameters specified in the config file.
>>
>> # Log rotation setting
>> LOG_ROTATION_SIZE = 10 # In MBs
>> LOG_ROTATION_AGE = 1440 # In minutes
>> LOG_ROTATION_MAX_LOGS = 90 # Maximum number of backups to retain
>>
>>
>> Thanks,
>> Yogesh Mahajan
>> EnterpriseDB
>>
>
>
> --
> *Thanks & Regards*
> *Akshay Joshi*
> *pgAdmin Hacker | Principal Software Architect*
> *EDB Postgres <http://edbpostgres.com>*
>
> *Mobile: +91 976-788-8246*
>
Attachments:
[application/octet-stream] RM6395_v2.patch (4.3K, 3-RM6395_v2.patch)
download | inline diff:
diff --git a/web/config.py b/web/config.py
index 4d1f98698..bdb2e6f3f 100644
--- a/web/config.py
+++ b/web/config.py
@@ -286,6 +286,13 @@ if SERVER_MODE and not IS_WIN:
else:
LOG_FILE = os.path.join(DATA_DIR, 'pgadmin4.log')
+# Log rotation setting
+# Log file will be rotated considering values for LOG_ROTATION_SIZE
+# & LOG_ROTATION_AGE. Rotated file will be named in format
+# - LOG_FILE.Y-m-d_H-M-S
+LOG_ROTATION_SIZE = 10 # In MBs
+LOG_ROTATION_AGE = 1440 # In minutes
+LOG_ROTATION_MAX_LOG_FILES = 90 # Maximum number of backups to retain
##########################################################################
# Server Connection Driver Settings
##########################################################################
diff --git a/web/pgadmin/__init__.py b/web/pgadmin/__init__.py
index a73335371..4fdc1e009 100644
--- a/web/pgadmin/__init__.py
+++ b/web/pgadmin/__init__.py
@@ -256,7 +256,13 @@ def create_app(app_name=None):
create_app_data_directory(config)
# File logging
- fh = logging.FileHandler(config.LOG_FILE, encoding='utf-8')
+ from pgadmin.utils.enhanced_log_rotation import \
+ EnhancedRotatingFileHandler
+ fh = EnhancedRotatingFileHandler(config.LOG_FILE,
+ config.LOG_ROTATION_SIZE,
+ config.LOG_ROTATION_AGE,
+ config.LOG_ROTATION_MAX_LOG_FILES)
+
fh.setLevel(config.FILE_LOG_LEVEL)
fh.setFormatter(logging.Formatter(config.FILE_LOG_FORMAT))
app.logger.addHandler(fh)
diff --git a/web/pgadmin/utils/enhanced_log_rotation.py b/web/pgadmin/utils/enhanced_log_rotation.py
new file mode 100644
index 000000000..00c5e9399
--- /dev/null
+++ b/web/pgadmin/utils/enhanced_log_rotation.py
@@ -0,0 +1,59 @@
+##########################################################################
+#
+# pgAdmin 4 - PostgreSQL Tools
+#
+# Copyright (C) 2013 - 2021, The pgAdmin Development Team
+# This software is released under the PostgreSQL Licence
+#
+##########################################################################
+
+import re
+import logging.handlers as handlers
+
+
+class EnhancedRotatingFileHandler(handlers.TimedRotatingFileHandler,
+ handlers.RotatingFileHandler):
+ """
+ Handler for logging to a set of files, which switches from one file
+ to the next when the current file reaches a certain size, or at certain
+ timed intervals
+ @filename - log file name
+ @max_bytes - file size in bytes to rotate file
+ @interval - Duration to rotate file
+ @backup_count - Maximum number of files to retain
+ @encoding - file encoding
+ @when - 'when' events supported:
+ # S - Seconds
+ # M - Minutes
+ # H - Hours
+ # D - Days
+ # midnight - roll over at midnight
+ # W{0-6} - roll over on a certain day; 0 - Monday
+ Here we are defaulting rotation with minutes interval
+ """
+ def __init__(self, filename, max_bytes=1, interval=60, backup_count=0,
+ encoding=None, when='M'):
+ max_bytes = max_bytes * 1024 * 1024
+ handlers.TimedRotatingFileHandler.__init__(self, filename=filename,
+ when=when,
+ interval=interval,
+ backupCount=backup_count,
+ encoding=encoding)
+
+ handlers.RotatingFileHandler.__init__(self, filename=filename,
+ mode='a',
+ maxBytes=max_bytes,
+ backupCount=backup_count,
+ encoding=encoding)
+
+ # Time & Size combined rollover
+ def shouldRollover(self, record):
+ return handlers.TimedRotatingFileHandler.shouldRollover(self, record) \
+ or handlers.RotatingFileHandler.shouldRollover(self, record)
+
+ # Roll overs current file
+ def doRollover(self):
+ self.suffix = "%Y-%m-%d_%H-%M-%S"
+ self.extMatch = r"^\d{4}-\d{2}-\d{2}_\d{2}-\d{2}-\d{2}(\.\w+)?$"
+ self.extMatch = re.compile(self.extMatch, re.ASCII)
+ handlers.TimedRotatingFileHandler.doRollover(self)
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: [pgAdmin][Patch] - Feature #6395 - Feature request: Log Rotation
2021-05-25 05:23 [pgAdmin][Patch] - Feature #6395 - Feature request: Log Rotation Yogesh Mahajan <[email protected]>
2021-05-25 07:39 ` Re: [pgAdmin][Patch] - Feature #6395 - Feature request: Log Rotation Akshay Joshi <[email protected]>
2021-05-25 11:28 ` Re: [pgAdmin][Patch] - Feature #6395 - Feature request: Log Rotation Yogesh Mahajan <[email protected]>
@ 2021-05-25 14:49 ` Akshay Joshi <[email protected]>
0 siblings, 0 replies; 4+ messages in thread
From: Akshay Joshi @ 2021-05-25 14:49 UTC (permalink / raw)
To: Yogesh Mahajan <[email protected]>; +Cc: pgadmin-hackers
Thanks, patch applied.
On Tue, May 25, 2021 at 4:59 PM Yogesh Mahajan <
[email protected]> wrote:
> Hello,
>
> Please find the attached file incorporated with the above comments except
> the 2nd one.
>
> Thanks,
> Yogesh Mahajan
> EnterpriseDB
>
>
> On Tue, May 25, 2021 at 1:09 PM Akshay Joshi <
> [email protected]> wrote:
>
>> Hi Yogesh
>>
>> Following are the review comments:
>>
>> - LOG_ROTATION_MAX_LOGS should be renamed to
>> LOG_ROTATION_MAX_LOG_FILES
>> - Rollover file name should have '.log' extension at the end instead
>> of "pgadmin4.log.2021-05-25_12-17-43"
>> - Add comments in the 'enhanced_log_rotation.py' file.
>> - 'enhanced_log_rotation.py' file line no 23 should be "max_bytes =
>> max_bytes * 1024 * 1024" instead of "max_bytes = max_bytes * 1000000"
>>
>>
>> On Tue, May 25, 2021 at 10:54 AM Yogesh Mahajan <
>> [email protected]> wrote:
>>
>>> Hi,
>>>
>>> Please find the attached patch which rotates the pgadmin log file with
>>> context to the parameters specified in the config file.
>>>
>>> # Log rotation setting
>>> LOG_ROTATION_SIZE = 10 # In MBs
>>> LOG_ROTATION_AGE = 1440 # In minutes
>>> LOG_ROTATION_MAX_LOGS = 90 # Maximum number of backups to retain
>>>
>>>
>>> Thanks,
>>> Yogesh Mahajan
>>> EnterpriseDB
>>>
>>
>>
>> --
>> *Thanks & Regards*
>> *Akshay Joshi*
>> *pgAdmin Hacker | Principal Software Architect*
>> *EDB Postgres <http://edbpostgres.com>*
>>
>> *Mobile: +91 976-788-8246*
>>
>
--
*Thanks & Regards*
*Akshay Joshi*
*pgAdmin Hacker | Principal Software Architect*
*EDB Postgres <http://edbpostgres.com>*
*Mobile: +91 976-788-8246*
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2021-05-25 14:49 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2021-05-25 05:23 [pgAdmin][Patch] - Feature #6395 - Feature request: Log Rotation Yogesh Mahajan <[email protected]>
2021-05-25 07:39 ` Akshay Joshi <[email protected]>
2021-05-25 11:28 ` Yogesh Mahajan <[email protected]>
2021-05-25 14:49 ` Akshay Joshi <[email protected]>
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox