[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [sbws/master] Add logging to a file by default, as well as stdout



commit 149f4adad4734346a2fc9cba35841bb69ee6fffa
Author: juga0 <juga@xxxxxxxxxx>
Date:   Wed Jun 6 12:26:46 2018 +0000

    Add logging to a file by default, as well as stdout
---
 sbws/config.default.ini     |  1 +
 sbws/config.log.default.ini | 23 +++++++++++++++++------
 sbws/util/config.py         |  6 +++++-
 3 files changed, 23 insertions(+), 7 deletions(-)

diff --git a/sbws/config.default.ini b/sbws/config.default.ini
index c9106e8..15ab014 100644
--- a/sbws/config.default.ini
+++ b/sbws/config.default.ini
@@ -2,6 +2,7 @@
 datadir = ${sbws_home}/datadir
 v3bw_fname = ${sbws_home}/v3bw.txt
 started_filepath = ${sbws_home}/started_at
+log_filepath = ${sbws_home}/sbws.log
 
 [destinations]
 # How often to check if a destional is usable
diff --git a/sbws/config.log.default.ini b/sbws/config.log.default.ini
index 1defe20..4294c6e 100644
--- a/sbws/config.log.default.ini
+++ b/sbws/config.log.default.ini
@@ -2,10 +2,10 @@
 keys = root,sbws
 
 [handlers]
-keys = sbwsdefault,sbwsdebug
+keys = sbwsdefault,sbwsdebug,sbwsfile
 
 [formatters]
-keys = sbwsdefault,sbwsdebug
+keys = sbwsdefault,sbwsdebug,sbwssys
 
 [logger_root]
 level = WARNING
@@ -15,13 +15,13 @@ qualname=root
 
 [logger_sbws]
 level = INFO
-handlers = sbwsdefault
+# add here sbwssys for also logging to system log
+handlers = sbwsdefault,sbwsfile
 propagate = 0
 qualname=sbws
 
 [handler_sbwsdefault]
 class = StreamHandler
-# add here sbwsys for also logging to system log
 formatter = sbwsdefault
 args = (sys.stdout,)
 
@@ -48,5 +48,16 @@ level = INFO
 
 # syslog-like formater
 [formatter_sbwssys]
-format = %(module)s[%(process)s]: %(message)s
-datefmt = %Y-%m-%d %H:%M:%S
+# hostname should be added here with a context filter, dunno if there is a way
+# to add it here
+format = %(asctime)s %(module)s[%(process)s]: <%(levelname)s> %(message)s
+datefmt = %b %d %H:%M:%S
+
+[handler_sbwsfile]
+class = handlers.RotatingFileHandler
+formatter = sbwssys
+# when not using level, it seems to be using the one passed as cli arg,
+# which is the desired behaviour
+# dunno if there is a way to have log file as a variable
+# setting one as default
+args = ('sbws.log',)
diff --git a/sbws/util/config.py b/sbws/util/config.py
index 7bf73df..cdf8601 100644
--- a/sbws/util/config.py
+++ b/sbws/util/config.py
@@ -87,6 +87,10 @@ def get_user_example_config():
 
 def configure_logging(conf):
     assert isinstance(conf, ConfigParser)
+    # log_filepath is not a variable in config.log.default.ini,
+    # so adding it here. Maybe there is a better way to do this
+    conf['handler_sbwsfile']['args'] = \
+        "('{}',)".format(conf['paths']['log_filepath'])
     with NamedTemporaryFile('w+t') as fd:
         conf.write(fd)
         fd.seek(0, 0)
@@ -146,7 +150,7 @@ def _validate_paths(conf):
     err_tmpl = Template('$sec/$key ($val): $e')
     unvalidated_keys = [
         'datadir', 'sbws_home', 'v3bw_fname',
-        'started_filepath']
+        'started_filepath', 'log_filepath']
     all_valid_keys = unvalidated_keys
     allow_missing = ['sbws_home']
     errors.extend(_validate_section_keys(conf, sec, all_valid_keys, err_tmpl,



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits