Execute Pre load activity

Hi everyone!

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

<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), 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

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.

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.

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.

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.

1 Like

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

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

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

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

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

great minds think alike!

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