简体   繁体   中英

Python logging library - beyond logging levels

The python logging library allows to log based on different levels: https://docs.python.org/3/howto/logging.html#logging-levels But I would like to use it to log based on custom tags, for example "show_intermediate_results" or "display_waypoints_in_the_code" or "report_time_for_each_module" and so on... Those tags cannot be measured in a severity ladder, during development i would sometimes want to see them and sometimes not depending on what i am developing/debugging at the moment. So the question is if I can use the logging library to do that? Btw, i DO want to use the library and not write something by myself because i want it to be thread safe.

As per the documentation , you can use logging.Filter objects with Logger and Handler instances

for more sophisticated filtering than is provided by levels.

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