[tor-commits] [sbws/master] Add possibility to log to system log

pastly at torproject.org pastly at torproject.org
Wed Jul 11 15:05:40 UTC 2018


commit f0977a682c1c68e94ef47b7e2630b81d319056ba
Author: juga0 <juga at riseup.net>
Date:   Sat Jul 7 16:26:02 2018 +0000

    Add possibility to log to system log
    
    Since sbws migth be run as a system service, it should give some
    information to the system log.
    There are no new options to configure for the user, and it's
    disabled by default.
---
 sbws/config.default.ini     |  2 ++
 sbws/config.log.default.ini | 26 ++++++++++++--------------
 sbws/util/config.py         |  3 +++
 3 files changed, 17 insertions(+), 14 deletions(-)

diff --git a/sbws/config.default.ini b/sbws/config.default.ini
index d9e2622..04bdd61 100644
--- a/sbws/config.default.ini
+++ b/sbws/config.default.ini
@@ -87,6 +87,8 @@ min_relays = 50
 to_file = yes
 # Whether or not to log to stdout
 to_stdout = no
+# Whether or not to log to syslog
+to_syslog = no
 # If logging to file, how large (in bytes) should the file be allowed to get
 # before rotating to a new one. 10485760 is 10 MiB. If zero or number of
 # backups is zero, never rotate the log file.
diff --git a/sbws/config.log.default.ini b/sbws/config.log.default.ini
index 82e483e..d841ccf 100644
--- a/sbws/config.log.default.ini
+++ b/sbws/config.log.default.ini
@@ -2,10 +2,10 @@
 keys = root,sbws
 
 [handlers]
-keys = to_file,to_stdout
+keys = to_file,to_stdout,to_syslog
 
 [formatters]
-keys = to_file,to_stdout
+keys = to_file,to_stdout,to_syslog
 
 [logger_root]
 level = WARNING
@@ -27,20 +27,18 @@ class = handlers.RotatingFileHandler
 formatter = to_file
 args = ('/dev/null', )
 
-## for logging to system log
-#[handler_to_syslog]
-#class=handlers.SysLogHandler
-#formatter=to_syslog
-#level = INFO
-#args = ()
+# for logging to system log
+[handler_to_syslog]
+class=handlers.SysLogHandler
+formatter=to_syslog
+level = INFO
+args = ('/dev/log',)
 
 [formatter_to_stdout]
 
 [formatter_to_file]
 
-## syslog-like formater
-#[formatter_to_syslog]
-## 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
+# syslog-like formatter
+[formatter_to_syslog]
+format = %(asctime)s %(module)s[%(process)s]: <%(levelname)s> %(message)s
+datefmt = %b %d %H:%M:%S
diff --git a/sbws/util/config.py b/sbws/util/config.py
index 5813878..6917033 100644
--- a/sbws/util/config.py
+++ b/sbws/util/config.py
@@ -109,6 +109,8 @@ def configure_logging(args, conf):
         handlers.add('to_stdout')
     if can_log_to_file and conf.getboolean('logging', 'to_file'):
         handlers.add('to_file')
+    if conf.getboolean('logging', 'to_syslog'):
+        handlers.add('to_syslog')
     # Collect the handlers in the appropriate config option
     conf[logger]['handlers'] = ','.join(handlers)
     if 'to_file' in handlers:
@@ -286,6 +288,7 @@ def _validate_logging(conf):
     bools = {
         'to_file': {},
         'to_stdout': {},
+        'to_syslog': {},
     }
     ints = {
         'to_file_max_bytes': {'minimum': 0, 'maximum': None},





More information about the tor-commits mailing list