9 ms·
I can easily fork output manually; I can't do it reliably using Python's logger.
by thechao 4y ago
I can easily fork output manually; I can't do it reliably using Python's logger.
- maleldil 4y agoEchoing grandparent's comment, it's not that hard: https://docs.python.org/3/library/logging.html#logging.Logger.addHandler https://docs.python.org/3/library/logging.html#logging.Logge... For dictConfig, the documentation has examples https://docs.python.org/3/library/logging.config.html#object-connections https://docs.python.org/3/library/logging.config.html#object... Python's logging has its faults, but you're complaining about something I could find in 5 minutes of Google.
- thechao 4y agoNone of which work reliably across multiple modules all fighting for control of the logger. Reliable is the key term, here.
- oblvious-earth 4y agoDon't write code where every module tries to make a root logger or set the logger config then. Each module should use `logger = logging.getLogger(__name__)` and the logger config can set in one place, conventionally in the `__main__` script. https://docs.python.org/3/howto/logging.html#advanced-logging-tutorial https://docs.python.org/3/howto/logging.html#advanced-loggin...
- funstuff007 4y agotrue that. but I've never figured out a good way to do this and have a single test runner module log when invoked directly: python3 test_foo.py and indirectly python3 -m unittest test_foo
- slaymaker1907 4y agoEh, it's really not that bad. I implemented this for a tool at work last year and it seemed pretty straightforward.