commit f3a487bd8fd950fb2f9e41d1a944bc87aca49e44 Author: Matt Traudt sirmatt@ksu.edu Date: Mon Jun 25 09:58:30 2018 -0400
Add [logging] section to config and validate it --- sbws/config.default.ini | 11 +++++++++++ sbws/util/config.py | 22 +++++++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-)
diff --git a/sbws/config.default.ini b/sbws/config.default.ini index 80ddc8b..10a2fb3 100644 --- a/sbws/config.default.ini +++ b/sbws/config.default.ini @@ -4,6 +4,7 @@ v3bw_dname = ${sbws_home}/v3bw v3bw_fname = ${v3bw_dname}/{}.v3bw started_filepath = ${sbws_home}/started_at log_filepath = ${sbws_home}/sbws.log +log_dname = ${sbws_home}/log
[destinations] # How often to check if a destional is usable @@ -81,3 +82,13 @@ measure_authorities = off fraction_relays = 0.05 # The minimum number of best priority relays we are willing to return min_relays = 50 + +[logging] +# Level to log at. Debug, info, warning, error. +level = debug +# Whether or not to log to a rotating file the directory paths.log_dname +to_file = yes +# Whether or not to log to stdout +to_stdout = no +# Format string to use when logging +format = [%(asctime)s] [%(name)s] [%(levelname)s] %(message)s diff --git a/sbws/util/config.py b/sbws/util/config.py index 0bfa072..c24ac23 100644 --- a/sbws/util/config.py +++ b/sbws/util/config.py @@ -109,6 +109,7 @@ def validate_config(conf): errors.extend(_validate_paths(conf)) errors.extend(_validate_destinations(conf)) errors.extend(_validate_relayprioritizer(conf)) + errors.extend(_validate_logging(conf)) return len(errors) < 1, errors
@@ -156,7 +157,7 @@ def _validate_paths(conf): err_tmpl = Template('$sec/$key ($val): $e') unvalidated_keys = [ 'datadir', 'sbws_home', 'v3bw_fname', 'v3bw_dname', - 'started_filepath', 'log_filepath'] + 'started_filepath', 'log_filepath', 'log_dname'] all_valid_keys = unvalidated_keys allow_missing = ['sbws_home'] errors.extend(_validate_section_keys(conf, sec, all_valid_keys, err_tmpl, @@ -227,6 +228,25 @@ def _validate_relayprioritizer(conf): return errors
+def _validate_logging(conf): + errors = [] + sec = 'logging' + err_tmpl = Template('$sec/$key ($val): $e') + enums = { + 'level': {'choices': ['debug', 'info', 'warning', 'error']}, + } + bools = { + 'to_file': {}, + 'to_stdout': {}, + } + unvalidated = ['format'] + all_valid_keys = list(bools.keys()) + list(enums.keys()) + unvalidated + errors.extend(_validate_section_keys(conf, sec, all_valid_keys, err_tmpl)) + errors.extend(_validate_section_bools(conf, sec, bools, err_tmpl)) + errors.extend(_validate_section_enums(conf, sec, enums, err_tmpl)) + return errors + + def _validate_destinations(conf): errors = [] sec = 'destinations'
tor-commits@lists.torproject.org