public inbox for [email protected]  
help / color / mirror / Atom feed
From: Thomas Greenwood <[email protected]>
To: [email protected]
Subject: Feature #6395 - Basic Log Rotation
Date: Fri, 16 Apr 2021 18:29:34 +0100
Message-ID: <[email protected]> (raw)

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

Attachments:

  [text/x-diff] pgAdmin4-rotation.patch (1.3K, 3-pgAdmin4-rotation.patch)
  download | inline diff:
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)
 


view thread (4+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected]
  Subject: Re: Feature #6395 - Basic Log Rotation
  In-Reply-To: <[email protected]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox