Logging from app.py

Hi there,
Stupid question for a friday!
How do I get the logger in an app to print to the sg desktop log? eg the app.py in the starter-app?
I’ve tried
self.logger.info("blah")
self.engine.logger.info("blah")

Neither produce any output.
I’ve also tried a standard logger = sgtk.LogManager.get_logger(__name__) method… but no joy.

Is this the old “desktop ate my logs” issue rearing its head?

thanks
p.

1 Like

Hey Patrick

That is curious, are you able to run engine.logger.info("blah") from the Python Console in SG Desktop and have it appear in your logs?
I just tried that here and it worked on my side, also what OS are you on, just in case that makes a difference?

Best,
Phil

Thanks Philip,
Yes, I can get the logger to work from the Python console no problem.

It’s definitely not firing from the app.py at the top level of the starter-app.
I’ve also tried:-

self._log = sgtk.platform.get_logger(__name__)
self._log.info("################# TEST ########################")

But nothing is showing up either.

I assume logs from app app.py calls should appear after the core engine_init logs have appeared?

I’m seeing the logs from the engine when the app calls engine.register_command, so the code is being run without error (the log calls are prior to the engine.register_command call). The engine is also, by implication, up and running, so self.engine.logger.info should fire logs to the console I would have assumed?

Quite odd indeed!
Any other ideas?
Thanks
p.

Please could you post a screengrab of your SG Desktop about box?
I tried here but setting a log line in the initialization of the app did work for me.

Also I used self.logger.info("hey there!")

image

I’m thinking our core needs re-merged with latest…

1 Like

OK yeah quite a lot is out of date there, we did put a fix in for logging not all that long ago so updating hopefully should fix that for you. I can’t remember exactly which component it was in, I think tk-desktop.
For comparison here is my about box: