Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow multiple backup logs #148

Open
djh42 opened this issue Jan 28, 2021 · 0 comments
Open

Allow multiple backup logs #148

djh42 opened this issue Jan 28, 2021 · 0 comments

Comments

@djh42
Copy link

djh42 commented Jan 28, 2021

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       #######################
 #######################################################################
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant