Is there a recommended way to get a separate log file for your plugin?

Sometimes it would be nice to ask users reporting bugs to supply a file of only logs relevant to your plugin rather than having them send the whole idea.log file. Is that a reasonable thing to do, record logs to a separate file for one plugin? If so, is there a way to do so?

Alternatively, perhaps this isn’t a good idea? Potentially it would be too easy to miss interactions between plugins, for example?

Starting from 2025.1, users can configure this in UI, via Help | Diagnostic Tools | Debug Log Settings.

Programmatically, this can be done by adding a custom handler to a logger instance obtained via java.util.logging.Logger.getLogger("category") call.

Thanks for the reply! A few follow up questions:

  1. Is this compatible with using com.intellij.openapi.diagnostic.Logger? Or would we need to change to using the java default logger? (The IJ logger is recommended from https://intellij-support.jetbrains.com/hc/en-us/community/posts/206779715/comments/206163615, though this link is pretty old)
  2. Can the Debug Log Settings UI change what file logs go to? I only see instructions for changing the log level of particular plugins: https://youtrack.jetbrains.com/articles/SUPPORT-A-43/How-to-enable-debug-logging-in-IntelliJ-IDEA
  1. Yes, this is compatible. com.intellij.openapi.diagnostic.Logger is a facade over JUL.
  2. There is no such possibility at the moment; the file name is based on a category (see LogLevelConfigurationManager.kt:155).

Great, thanks for clarifying. Can you point me to a code sample or help me understand in the below example?

So the state of my file:

import com.intellij.openapi.diagnostic.Logger;

public class MyClass {
  public static final Logger LOG = Logger.getInstance(MyClass.class) // IJ logger - is this the recommended way to use within a class?

  public MyClass() {
    LOG.setHandler(new LogHandler()) // LogHandler will write to a separate file, but how should this be done when `setHandler` is only available in java.util.logging.Logger?
  }
  public void logSomething() {
    LOG.info("Log something"); // I'd like this to go to a separate file
  }
}

Something like this:

//...
  public static final Logger LOG;
  static {
    var category = "#" + MyClass.class.getName();
    java.util.logging.Logger.getLogger(category).setHandler(new LogHandler());
    LOG = Logger.getInstance(category);
  }
//...

Thanks so much! I’ll try this out.