python-logging

How to find a thread id in Python

萝らか妹 提交于 2019-11-27 04:12:45
问题 I have a multi-threading Python program, and a utility function, writeLog(message) , that writes out a timestamp followed by the message. Unfortunately, the resultant log file gives no indication of which thread is generating which message. I would like writeLog() to be able to add something to the message to identify which thread is calling it. Obviously I could just make the threads pass this information in, but that would be a lot more work. Is there some thread equivalent of os.getpid()

How to add a custom loglevel to Python's logging facility

心已入冬 提交于 2019-11-26 12:34:50
问题 I\'d like to have loglevel TRACE (5) for my application, as I don\'t think that debug() is sufficient. Additionally log(5, msg) isn\'t what I want. How can I add a custom loglevel to a Python logger? I\'ve a mylogger.py with the following content: import logging @property def log(obj): myLogger = logging.getLogger(obj.__class__.__name__) return myLogger In my code I use it in the following way: class ExampleClass(object): from mylogger import log def __init__(self): \'\'\'The constructor with

Where is a complete example of logging.config.dictConfig?

送分小仙女□ 提交于 2019-11-26 07:58:06
问题 I\'d like to use dictConfig, but the documentation is a little bit abstract. Where can I find a concrete, copy+paste-able example of the dictionary used with dictConfig ? 回答1: How about here! LOGGING_CONFIG = { 'version': 1, 'disable_existing_loggers': True, 'formatters': { 'standard': { 'format': '%(asctime)s [%(levelname)s] %(name)s: %(message)s' }, }, 'handlers': { 'default': { 'level': 'INFO', 'formatter': 'standard', 'class': 'logging.StreamHandler', 'stream': 'ext://sys.stdout', #