Uploaded image for project: 'Log4j 2'
  1. Log4j 2
  2. LOG4J2-2458

Log4j2 does not load @Plugin annotated Kotlin classes

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • 2.7
    • None
    • Plugins

    Description

      Recently I was trying to extend log4j2 library in my Kotlin project with @Plugin class. It is just simple converter, nothing special.

      The problem was that log4j2 didn't load @Plugin annotated Kotlin class at all.

      Made a small investigation and found out that Plugins are loaded by PluginProcessor during the compilation time(which is in my case was run by maven plugin). At that time Kotlin classes are not compiled yet, so PluginProcessor does not load Plugin class.

      It is quite known problem with annotation processing for Kotlin.

      Attaching some of Kotlin code if anybody wants to try it:

      // code placeholder
      @Plugin(name = "TestConverter", category = "Converter")
      @ConverterKeys("m")
      class TestConverter(name: String, style: String) : LogEventPatternConverter(name, style) {
      
          companion object {
              @JvmStatic
              fun newInstance(options: Array<String>): TestConverter {
                  return TestConverter("testConverter", Thread.currentThread().name)
              }
          }
      
          override fun format(logEvent: LogEvent, stringBuilder: StringBuilder) {
              //some stuff here
          }
      }
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            boson42 Sanat Serikuly
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: