News for hackers. Stuff that matters.
Re:Logging in Python like a pro by thechao on Friday July 01, 2022 @12:41PM (#31949079)
I can't agree with you more. I switched to Python's logger off of my janky thing about 6 months ago, and I'm hating every second of it. I still have no clue how to turn it on, turn it off, get it to fork output (stdout, stderr, file), nor how to override its behavior.

It's literally easier to just have an IOBuffer laying around.

Re:Logging in Python like a pro by oefrha on Friday July 01, 2022 @01:56PM (#31950175)
There are valid complaints in the grandparent, but if you can’t figure out how to fork output to stdout, stderr and file in six months, that’s really on you. You should know how to register multiple handlers if you spent five minutes reading the documentation.
Re:Logging in Python like a pro by thechao on Friday July 01, 2022 @04:12PM (#31952136)
I can easily fork output manually; I can't do it reliably using Python's logger.
Re:Logging in Python like a pro by maleldil on Friday July 01, 2022 @05:07PM (#31952941)
Echoing grandparent's comment, it's not that hard:

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...

Python's logging has its faults, but you're complaining about something I could find in 5 minutes of Google.

Re:Logging in Python like a pro by thechao on Friday July 01, 2022 @05:17PM (#31953062)
None of which work reliably across multiple modules all fighting for control of the logger. Reliable is the key term, here.
Re:Logging in Python like a pro by oblvious-earth on Friday July 01, 2022 @08:26PM (#31954775)
Don'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-loggin...

Re:Logging in Python like a pro by funstuff007 on Friday July 01, 2022 @10:00PM (#31955373)
true 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
Re:Logging in Python like a pro by slaymaker1907 on Friday July 01, 2022 @05:20PM (#31953099)
Eh, it's really not that bad. I implemented this for a tool at work last year and it seemed pretty straightforward.