1.15.2 How to use Log4j for custom logging?

Discussion in 'Spigot Plugin Development' started by aex32, Jan 25, 2020.

  1. I need to create custom log files for my plugin, preferably with rotation support.
    I wanted to try Log4j but it seems that it conflicts with built-in Log4j logger, no matter how I configure it, like logger still uses the same configuration as Spigot internal logger.

    So is it even possible?
    What is the better way for logging?
    I mean of course I can just write to files using simple Java IO but that's way worse for my needs.
     
  2. Here's how you can configure log4j: https://logging.apache.org/log4j/2.x/manual/configuration.html

    I'm guessing that Spigot (or vanilla Minecraft) specify their own log4j config. You'll need to override it. It looks like if you set the "log4j.configurationFile" property then you can override it since it's the first place that log4j will look.
     
    • Agree Agree x 1
  3. Not a great idea if you're planning to share the plugin. log4j configuration shouldn't be set by a library (or plugin), it should be set by the application.