# Execute Pre load activity

**URL:** <https://platform.jetbrains.com/t/execute-pre-load-activity/958>\
**Category:** IntelliJ Platform\
**Created:** [March 17, 2025, 3:12pm UTC](https://platform.jetbrains.com/t/execute-pre-load-activity/958 "2025-03-17T15:12:35Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![tav](https://sea1.discourse-cdn.com/flex001/user_avatar/platform.jetbrains.com/tav/32/652_2.png) [@tav](https://platform.jetbrains.com/u/tav)\
**Post date:** [March 17, 2025, 3:12pm UTC](https://platform.jetbrains.com/t/execute-pre-load-activity/958/1 "2025-03-17T15:12:35Z")

</div>

**Hi everyone!**

I’m developing an IntelliJ plugin and using an environment variable to set my logger file path:

```auto
<file>${IDE_LOG_PATH}/plugin.log</file>

```

However, I’ve run into a problem: the static classes that use the logger are being loaded before the environment variable itself is set.

One potential solution is to force the initialization code to run before these static classes. For instance, I noticed a `preloadingActivity` implementation (see [example plugin.xml](https://github.com/jansorg/intellij-plugin-startup/blob/master/resources/META-INF/plugin.xml)), but I’m unsure if it’s the best approach or how exactly to implement it.

Another idea is to rely on IntelliJ’s existing environment variables that are already loaded prior to plugin initialization, such as `IDE_LOG_PATH`.

- What do you recommend for initializing the logger configuration before static class loading?

Thank you,  
Tomer

---

<div class="post-metadata">

**Author:** ![chriscarini](https://sea1.discourse-cdn.com/flex001/user_avatar/platform.jetbrains.com/chriscarini/32/695_2.png) [@chriscarini](https://platform.jetbrains.com/u/chriscarini)\
**Post date:** [March 17, 2025, 4:22pm UTC](https://platform.jetbrains.com/t/execute-pre-load-activity/958/2 "2025-03-17T16:22:17Z")

</div>

That looks like you are using an environment variable _IN_ your log path, but not using one _for_ the log path.

Which are you trying to accomplish, exactly?

1. _For_ your log path (e.g. `MY_LOG_PATH=~/foobar.log idea .`)
2. _In_ your log path (e.g. what you have in your example above)
3. Change an existing environment variable that’s used in log configuration (e.g. IDE starts with `IDE_LOG_PATH` set to one directory, but you want your plug-in to change it to another directory and have all logs using that env var go there instead)

If you’re looking for 1, then the path should certainly be set by the time any code, IDE or plugin, is invoked. If you’re looking for 2, then I think I’m confused by what you’re trying to accomplish. If your looking for 3, then that’s a much more difficult problem.

---

<div class="post-metadata">

**Author:** ![tav](https://sea1.discourse-cdn.com/flex001/user_avatar/platform.jetbrains.com/tav/32/652_2.png) [@tav](https://platform.jetbrains.com/u/tav)\
**Post date:** [March 24, 2025, 8:44am UTC](https://platform.jetbrains.com/t/execute-pre-load-activity/958/3 "2025-03-24T08:44:33Z")

</div>

Hi Chris,  
Thank you for your response. I want to go with the first option, The path needs to be set before it’s used, and ensure that the pre-load code is executed to assign the value.

---

<div class="post-metadata">

**Author:** ![yuriy.artamonov](https://sea1.discourse-cdn.com/flex001/user_avatar/platform.jetbrains.com/yuriy.artamonov/32/48_2.png) [@yuriy.artamonov](https://platform.jetbrains.com/u/yuriy.artamonov)\
**Post date:** [March 24, 2025, 9:09am UTC](https://platform.jetbrains.com/t/execute-pre-load-activity/958/4 "2025-03-24T09:09:29Z")

</div>

Plugins in our design must not affect IDE startup sequence, please avoid such design. Moreover, early startup extensions are reserved to IDE itlsef and prohibited for plugins.

---

<div class="post-metadata">

**Author:** ![ChananM](https://sea1.discourse-cdn.com/flex001/user_avatar/platform.jetbrains.com/chananm/32/111_2.png) [@ChananM](https://platform.jetbrains.com/u/ChananM)\
**Post date:** [March 24, 2025, 10:39am UTC](https://platform.jetbrains.com/t/execute-pre-load-activity/958/5 "2025-03-24T10:39:30Z")

</div>

Hi @yuriy.artamonov, we’re not looking to affect IDE startup sequence, only our plugin startup sequence. The problem is that our `ProjectActivity` defines an environment variable for our logger (we use Logback) and reloads the logger configuration, but other services in our plugin were already loaded, and the static logger in them uses the old configuration before the environment variable was set. We need to reset it in runtime because we use `PathManager.getLogPath()` to know where to put the file.  
What we are asking here is how can we execute code in our plugin that we can know for certain will run before any service is loaded to the class loader? Because `ProjectActivity` doesn’t provide that.

---

<div class="post-metadata">

**Author:** ![yuriy.artamonov](https://sea1.discourse-cdn.com/flex001/user_avatar/platform.jetbrains.com/yuriy.artamonov/32/48_2.png) [@yuriy.artamonov](https://platform.jetbrains.com/u/yuriy.artamonov)\
**Post date:** [March 24, 2025, 10:40am UTC](https://platform.jetbrains.com/t/execute-pre-load-activity/958/6 "2025-03-24T10:40:20Z")

</div>

> will run before any service is loaded

There is no such place for plugins unfortunately and we would like to not have them. Plugins start only after the platform

---

<div class="post-metadata">

**Author:** ![ChananM](https://sea1.discourse-cdn.com/flex001/user_avatar/platform.jetbrains.com/chananm/32/111_2.png) [@ChananM](https://platform.jetbrains.com/u/ChananM)\
**Post date:** [March 24, 2025, 10:41am UTC](https://platform.jetbrains.com/t/execute-pre-load-activity/958/7 "2025-03-24T10:41:12Z")

</div>

@yuriy.artamonov Let me correct myself - before any service **of my own plugin** is loaded

---

<div class="post-metadata">

**Author:** ![yuriy.artamonov](https://sea1.discourse-cdn.com/flex001/user_avatar/platform.jetbrains.com/yuriy.artamonov/32/48_2.png) [@yuriy.artamonov](https://platform.jetbrains.com/u/yuriy.artamonov)\
**Post date:** [March 24, 2025, 10:42am UTC](https://platform.jetbrains.com/t/execute-pre-load-activity/958/8 "2025-03-24T10:42:30Z")

</div>

Then it should be possible, you can put preloading code to static block of services/extensions. Platform itself does not load any service classes, but loads extensions code lazily and on-demand

---

<div class="post-metadata">

**Author:** ![chriscarini](https://sea1.discourse-cdn.com/flex001/user_avatar/platform.jetbrains.com/chriscarini/32/695_2.png) [@chriscarini](https://platform.jetbrains.com/u/chriscarini)\
**Post date:** [March 24, 2025, 12:06pm UTC](https://platform.jetbrains.com/t/execute-pre-load-activity/958/9 "2025-03-24T12:06:41Z")

</div>

> [@ChananM](#):
>
> we use `PathManager.getLogPath()` to know where to put the file.

Can you use this in a static block where/when the respective loggers are defined?

---

<div class="post-metadata">

**Author:** ![yuriy.artamonov](https://sea1.discourse-cdn.com/flex001/user_avatar/platform.jetbrains.com/yuriy.artamonov/32/48_2.png) [@yuriy.artamonov](https://platform.jetbrains.com/u/yuriy.artamonov)\
**Post date:** [March 24, 2025, 12:52pm UTC](https://platform.jetbrains.com/t/execute-pre-load-activity/958/10 "2025-03-24T12:52:51Z")

</div>

You can have such static function that inits loggers and wraps Logback API for instance

---

<div class="post-metadata">

**Author:** ![chriscarini](https://sea1.discourse-cdn.com/flex001/user_avatar/platform.jetbrains.com/chriscarini/32/695_2.png) [@chriscarini](https://platform.jetbrains.com/u/chriscarini)\
**Post date:** [March 24, 2025, 3:25pm UTC](https://platform.jetbrains.com/t/execute-pre-load-activity/958/11 "2025-03-24T15:25:58Z")

</div>

great minds think alike!

---

<div class="post-metadata">

**Author:** ![ChananM](https://sea1.discourse-cdn.com/flex001/user_avatar/platform.jetbrains.com/chananm/32/111_2.png) [@ChananM](https://platform.jetbrains.com/u/ChananM)\
**Post date:** [March 24, 2025, 3:31pm UTC](https://platform.jetbrains.com/t/execute-pre-load-activity/958/12 "2025-03-24T15:31:33Z")

</div>

Yes, and it works great. Thank you for your help!
