# Where are exceptions logged in context\_change.py?

**URL:** <https://community.shotgridsoftware.com/t/where-are-exceptions-logged-in-context-change-py/4004>\
**Category:** Pipeline Integrations\
**Created:** [November 27, 2019, 10:55pm UTC](https://community.shotgridsoftware.com/t/where-are-exceptions-logged-in-context-change-py/4004 "2019-11-27T22:55:00Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![kramester](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/kramester/32/271_2.png) [@kramester](https://community.shotgridsoftware.com/u/kramester)\
**Post date:** [November 27, 2019, 10:55pm UTC](https://community.shotgridsoftware.com/t/where-are-exceptions-logged-in-context-change-py/4004/1 "2019-11-27T22:55:00Z")

</div>

I’m trying to add a core hook with context\_change.py and I’m getting an error in the tk-desktop2.log file that just says:

Exception raised while executing hook ‘[…]/context\_change.py’

I cant seem to find anyway to view that exception so that I can debug.

---

<div class="post-metadata">

**Author:** ![mmoshev](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/mmoshev/32/476_2.png) [@mmoshev](https://community.shotgridsoftware.com/u/mmoshev)\
**Post date:** [November 28, 2019, 11:06am UTC](https://community.shotgridsoftware.com/t/where-are-exceptions-logged-in-context-change-py/4004/2 "2019-11-28T11:06:16Z")

</div>

otoh, the hook itself has a logger instance, so you could catch the exception inside it and log it like  
`self.logger.error(traceback.format_exc())` which should go to one of the standard logs (`tk-shotgun` or `tk-desktop`, I guess).

I’d first check the hook script for syntax, undefined variables, etc. which could be the first thing to trip it. A static checker in your editor/ide helps greatly with this.

---

<div class="post-metadata">

**Author:** ![philip.scadding](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/philip.scadding/32/30_2.png) [@philip.scadding](https://community.shotgridsoftware.com/u/philip.scadding)\
**Post date:** [November 28, 2019, 12:10pm UTC](https://community.shotgridsoftware.com/t/where-are-exceptions-logged-in-context-change-py/4004/3 "2019-11-28T12:10:14Z")

</div>

I can replicate what you are seeing with the `tk-desktop` engine.  
I’ve tracked down the issue there, and I suspect it is the same in `tk-desktop2`.

Although a log.exception is called when the hook errors, the way the logging is handled, means that the exception gets lost. I’m going to try and put a pull request together, as I’ve got something working on my end.  
In the meantime, I would go with what Mois has suggested. Sorry for the frustration!

---

<div class="post-metadata">

**Author:** ![philip.scadding](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/philip.scadding/32/30_2.png) [@philip.scadding](https://community.shotgridsoftware.com/u/philip.scadding)\
**Post date:** [November 28, 2019, 12:32pm UTC](https://community.shotgridsoftware.com/t/where-are-exceptions-logged-in-context-change-py/4004/4 "2019-11-28T12:32:23Z")

</div>

Actually for me, `tk-desktop2` is generating a full error output. I get:

```auto
2019-11-28 12:31:23,391 [75895 ERROR sgtk.ext.tk-framework-shotgunutils.multi_context.external_runner] Could not start engine.
Traceback (most recent call last):
  File "/Users/philips1/Library/Application Support/Autodesk/Shotgun Create/ApplicationUpdates/b738a63/Shotgun Create.app/Contents/sgtk/bundle_cache/app_store/tk-framework-shotgunutils/v5.6.1/python/external_config/scripts/external_runner.py", line 110, in execute_command
    self._callback()
  File "/Users/philips1/Library/Application Support/Autodesk/Shotgun Create/ApplicationUpdates/b738a63/Shotgun Create.app/Contents/sgtk/bundle_cache/app_store/tk-framework-shotgunutils/v5.6.1/python/external_config/scripts/external_runner.py", line 371, in main
    arg_data.get("pre_cache") or False,
  File "/Users/philips1/Library/Application Support/Autodesk/Shotgun Create/ApplicationUpdates/b738a63/Shotgun Create.app/Contents/sgtk/bundle_cache/app_store/tk-framework-shotgunutils/v5.6.1/python/external_config/scripts/external_runner.py", line 277, in start_engine
    raise EngineStartupError(e)
EngineStartupError: bad things

```

Though as I say, `tk-desktop` does have an issue, for which I’ve now created a PR.

---

<div class="post-metadata">

**Author:** ![kramester](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/kramester/32/271_2.png) [@kramester](https://community.shotgridsoftware.com/u/kramester)\
**Post date:** [November 29, 2019, 7:03pm UTC](https://community.shotgridsoftware.com/t/where-are-exceptions-logged-in-context-change-py/4004/5 "2019-11-29T19:03:03Z")

</div>

I found it. I had a `self.log_debug()` in there that it didn’t like. Changed it to `self.logger.debug()` and now it works fine.

---

<div class="post-metadata">

**Author:** ![philip.scadding](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/philip.scadding/32/30_2.png) [@philip.scadding](https://community.shotgridsoftware.com/u/philip.scadding)\
**Post date:** [January 8, 2020, 3:01pm UTC](https://community.shotgridsoftware.com/t/where-are-exceptions-logged-in-context-change-py/4004/6 "2020-01-08T15:01:46Z")

</div>

Just to let you all know I’ve just pushed out a new version of the `tk-desktop` engine (`v2.4.13`) that should mean it will now log the full traceback, when an error occurs within a project in SG Desktop.

---

<div class="post-metadata">

**Author:** ![jaredauty](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/jaredauty/32/2364_2.png) [@jaredauty](https://community.shotgridsoftware.com/u/jaredauty)\
**Post date:** [May 22, 2020, 10:38am UTC](https://community.shotgridsoftware.com/t/where-are-exceptions-logged-in-context-change-py/4004/7 "2020-05-22T10:38:33Z")

</div>

I’m getting a similar issue with missing logs when trying to catch errors during the config startup. I’ve tried using the patch of tk-desktop but I’m still not seeing any logs.

I’ve got a framework that initializes during the tk-desktop bootstrap. However if there’s an error during the init it just doesn’t load the framework and there’s no trace in the logs. Ideally I’d want to see the full traceback if anything breaks.

Is this expected behavior or am I doing something wrong somewhere? Could it have anything to do with proxy based logging?

I get this in the logs:

> DEBUG] [PROXY] Project-level tk-desktop engine has now switched back to proxy based logging.

---

<div class="post-metadata">

**Author:** ![philip.scadding](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/philip.scadding/32/30_2.png) [@philip.scadding](https://community.shotgridsoftware.com/u/philip.scadding)\
**Post date:** [May 22, 2020, 10:43am UTC](https://community.shotgridsoftware.com/t/where-are-exceptions-logged-in-context-change-py/4004/8 "2020-05-22T10:43:08Z")

</div>

Looks like a similar issue to be discussed here as well:

> [@Tk-desktop console silently ignoring errors](https://community.shotgridsoftware.com/t/tk-desktop-console-silently-ignoring-errors/8570/26):
>
> I’ve actually been looking at the way the Desktop engine handles the logging for a separate reason, and I think I now understand a bit more. When Desktop is loading the app for the project, that logging is never getting passed to SG Desktop main UI process, however it should as far as I can see, and I’ve tested, still get output to the tk-desktop.log. So that explains why you wouldn’t see it in the console, but I’m still not sure why you are not getting a message in the log file. I get an error…

What version of `tk-desktop` are you running on both the project and site side?

---

<div class="post-metadata">

**Author:** ![jaredauty](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/jaredauty/32/2364_2.png) [@jaredauty](https://community.shotgridsoftware.com/u/jaredauty)\
**Post date:** [May 23, 2020, 7:14am UTC](https://community.shotgridsoftware.com/t/where-are-exceptions-logged-in-context-change-py/4004/9 "2020-05-23T07:14:21Z")

</div>

Ya seems more similar to the ticket about silently ignoring logging. FYI I’m on 2.4.14 for project level and then whatever is currently in tk-config-default for site (we’re currently tracking latest default).
