Mercurial > p > roundup > code
diff test/test_config.py @ 8443:39a6825d10ca
feat: allow admin to set logging format from config.ini
This is prep work for adding a per thread logging variable that can be
used to tie all logs for a single request together.
This uses the same default logging format as before, just moves it to
config.ini.
Also because of configparser, the logging format has to have doubled %
signs. So use:
%%(asctime)s
not '%(asctime)s' as configparser tries to interpolate that string and
asctime is not defined in the configparser's scope. Using %%(asctime)s
is not interpolated by configparser and is passed into Roundup.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Mon, 01 Sep 2025 21:54:48 -0400 |
| parents | 66284037142e |
| children | 14c7c07b32d8 |
line wrap: on
line diff
--- a/test/test_config.py Mon Sep 01 20:35:54 2025 -0400 +++ b/test/test_config.py Mon Sep 01 21:54:48 2025 -0400 @@ -1112,6 +1112,43 @@ self.assertIn("nati", string_rep) self.assertIn("'whoosh'", string_rep) + def testLoggerFormat(self): + config = configuration.CoreConfig() + + # verify config is initalized to defaults + self.assertEqual(config['LOGGING_FORMAT'], + '%(asctime)s %(levelname)s %(message)s') + + # load config + config.load(self.dirname) + self.assertEqual(config['LOGGING_FORMAT'], + '%(asctime)s %(levelname)s %(message)s') + + # break config using an incomplete format specifier (no trailing 's') + self.munge_configini(mods=[ ("format = ", "%%(asctime)s %%(levelname) %%(message)s") ], section="[logging]") + + # load config + with self.assertRaises(configuration.OptionValueError) as cm: + config.load(self.dirname) + + self.assertIn('Unrecognized use of %(...) in: %(levelname)', + cm.exception.args[2]) + + # break config by not dubling % sign to quote it from configparser + self.munge_configini(mods=[ ("format = ", "%(asctime)s %%(levelname) %%(message)s") ], section="[logging]") + + with self.assertRaises( + configuration.ParsingOptionError) as cm: + config.load(self.dirname) + + self.assertEqual(cm.exception.args[0], + "Error in _test_instance/config.ini with section " + "[logging] at option format: Bad value substitution: " + "option 'format' in section 'logging' contains an " + "interpolation key 'asctime' which is not a valid " + "option name. Raw value: '%(asctime)s %%(levelname) " + "%%(message)s'") + def testDictLoggerConfigViaJson(self): # good base test case
