Integrating USD Tf.Warn with Python logging.Logger

Hi everyone,

I’m trying to route USD’s Tf.Warn messages to Python’s logging.Logger in our project but haven’t had success with Tf.Notice listeners or redirecting stderr. Does anyone have experience or tips on how to capture these warnings directly into a Python logger? Any advice or examples would be greatly appreciated!

Thanks!

Nick

You may find a custom TfDiagnosticDelegate useful. Here is one that we provide as part of OpenUSD for DCC’s to use, should they want to (we hope to use it in usdview someday).

Just keep in mind that a process can currently only have one Delegate installed and active, so it is possible, in some USD-using contexts you do not fully control, that you could find yourself fighting the app.

1 Like

Would it be reasonable for OpenUSD to try to convert TfWarning into python warning module warnings if there’s no registered delegate?

There are then multiple facilities in warnings module for silencing warnings, converting warnings to errors, or converting them to logging module.

I suspect this could be implemented as a boost python call policy that sets some state on the TfDiagnosticMgr so that in PostWarning, instead of _PrintDiagnostic, PyError_Warn is called instead.

1 Like