Commit f3a487bd authored by Matt Traudt's avatar Matt Traudt Committed by juga
Browse files

Add [logging] section to config and validate it

parent 11fac0c6
......@@ -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
......@@ -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'
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment