Skip to content

Allow multiple backup logs #148

@djh42

Description

@djh42

When the logging level is DEBUG a 5 MB log file on my system fills up in about 3 hours. Since the reason for setting the log level high is to help diagnose an intermittent RF problem that might occur at any time that isn't long enough. Rather than just patch the number of files, I decided to make the number of files configurable. I would have submitted a pull request but since I'm running an older version of the code, it wouldn't apply cleanly. So here are the two patches that will need applying manually (sorry :( )

--- emonhub.py.orig	2018-08-02 10:52:11.525739194 +0000
+++ emonhub.py	2021-01-28 15:51:17.280490520 +0000
@@ -295,14 +295,28 @@
         # this ensures it is writable
         # Close the file for now and get its path
         args.logfile.close()
+        # djh 2021-01-27
+        # add ability to configure number of backup logs
+        try:
+            setup = ehs.EmonHubFileSetup(args.config_file)
+        except:
+            pass
+        if setup is None or not 'log_backups' in setup.settings['hub']:
+            backup_count = 1
+        else:
+            backup_count = int(setup.settings['hub']['log_backups'])
+#        backup_count = 5
+
         loghandler = logging.handlers.RotatingFileHandler(args.logfile.name,
-                                                       'a', 5000 * 1024, 1)
+                                            'a', 5000 * 1024, backup_count)
     # Format log strings
     loghandler.setFormatter(logging.Formatter(
             '%(asctime)s %(levelname)-8s %(threadName)-10s %(message)s'))
 
     logger.addHandler(loghandler)
 
+    logger.info('logging with ' + str(backup_count) + ' backup files')
+
     # Initialize hub setup
     try:
         setup = ehs.EmonHubFileSetup(args.config_file)

and

--- emonhub.conf.orig	2021-01-28 16:00:19.120076894 +0000
+++ emonhub.conf.patch	2021-01-28 15:58:37.920181377 +0000
@@ -13,6 +13,8 @@
 loglevel = DEBUG
 ### Uncomment this to also send to syslog
 # use_syslog = yes
+# added new setting - number of log backup files 2021-01-27 djh
+log_backups = 6
 #######################################################################
 #######################       Interfacers       #######################
 #######################################################################

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions