简体   繁体   中英

List of dictConfig configuration options for Python logging handlers?

Where can I find a list of configuration options for Python's logging handlers? For example, the docs say that the TimedRotatingFileHandler takes a "when" argument. How can this be defined using dictConfig?

Like this?:

'handlers': {
    'file': {
        'level': 'DEBUG',
        'formatter':'default',
        'class': 'logging.handlers.TimedRotatingFileHandler',
        'when': 'midnight',
          ....
    },
},

If so, do all the option names for dictConfig correcpond exactly to the code examples on the docs? Just wondering, since I have yet to find a separate page listing the option names for use with dictConfig.

The idea is for the key names in the configuration dict to be the same as the named args in the corresponding call to construct the handler (or formatter, or filter). This will then work with externally defined handlers, too. Given a dict config which holds the configuration of an object (like a handler), the configuration code does the equivalent of

constructor = config['class'] # or '()' for a custom object being configured
kwargs = dict([(k, config[k]) for k in config if valid_ident(k)])
obj = constructor(**kwargs)

to get the configured object. Any keys that are not valid identifiers are ignored. In the case of handlers, level, formatter and filters` are also ignored in the constructor call, as they have special significance in the logging configuration.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM