pygfx icon indicating copy to clipboard operation
pygfx copied to clipboard

Logging?

Open almarklein opened this issue 1 year ago • 1 comments

I figured I set gfx.logger.setLevel("INFO") so I can see when the pipelines update (these are info log messages). But I don't see anything.

We don't do anything fancy with logging in pygfx, so log messages fall back to the root logger, and because that one has no handlers either, Python's logging system falls back to its lastResort handler:

https://github.com/python/cpython/blob/1a1056d394a489d229b26c06c7c79aa9c06696f6/Lib/logging/init.py#L1288-L1289

But since that one has level WARNING, it won't print info messages. I think that earlier, I just turned info messages into warnings to see them, which is why I did not run into it before.

So ... what's good practice here to allow users to see log messages?

almarklein avatar Jan 15 '25 12:01 almarklein

Could this be why we (internally) have this in our codebase?

handler = logging.StreamHandler(sys.stderr)
handler.setLevel(logging.WARNING)

formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
handler.setFormatter(formatter)

# This helps debug errors that occur in the event callbacks
# Without this, we get no feedback
logger = logging.getLogger("wgpu")
logger.addHandler(handler)

I feel like we've gotten better at using WGPU/PyGFX and just haven't hit that many warnings recently so I'm not sure if the effect is still there.

I somewhat remember this being important to capture the errors for

hmaarrfk avatar Jan 15 '25 13:01 hmaarrfk