[Python-Dev] A new way to configure logging
vinay_sajip at yahoo.co.uk
Thu Oct 8 16:47:59 CEST 2009
> I've had bad experiences in the past with dictionary-based APIs. They seem
> "simpler" in the short run, because the user "only needs to create some
> dictionaries". Once the complexity of that nested dictionary grows to a certain
> point, though, one has to refer back to documentation constantly to make sure
Fair point, and agreed that the schema needs some care, here's roughly what I'm thinking of as an example configuration (YAML):
format: '%(levelname)-8s: %(name)-15s: %(message)s'
format: '%(asctime)s %(name)-15s %(levelname)-8s %(message)s'
class : logging.StreamHandler
level : INFO
stream : sys.stdout
class : logging.handlers.RotatingFileHandler
class : logging.FileHandler
level : ERROR
level : CRITICAL
level : DEBUG
handlers : [console, file]
It's not too deeply nested, and I can't see any need for it being more deeply nested. It more or less mirrors the way you'd have to write the corresponding ConfigParser-compatible configuration, but if you use a dict as a common format, you have the benefits which I mentioned of supporting JSON, YAML or Python code in a Django settings.py.
> the structure conforms to the "schema". Building a simple config tree using
> light-weight classes with documented APIs tends to be more sustainable in the
> long run.
When you say 'config tree using light-weight classes', I presume you mean a parallel set of classes to the actual logging classes which will be instantiated? ISTM logging classes are already reasonably usable for programmatic configuration, but this doesn't address e.g. updating configurations easily without program code changes, or the ability to configure from say a YAML node, where YAML may be being used for application configuration as a whole. (Unless of course I've misunderstood what you're getting at.)
More information about the Python-Dev