• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Log4j2 Custom Appender won't get detected.

 
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to write a custom appender for log4j2, but I can't get it detected at runtime.

The class is:


in my log4j.xml file I have




on startup, I get this:



I am running log4j2 version 2.11.1

Any ideas? Most issues reported like this tell me to set the Configuration/packages setting, but I've done that and it makes no difference.

 
John Farrel
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I upgraded to log4j2 2.13.0, same problem.
 
Marshal
Posts: 4501
572
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you declare the package for your plugin in the  log4j2 config file?

I think for an XML file it would be something like:

Edit: Sorry .. I didn't notice that you already had done this.  
 
Ron McLeod
Marshal
Posts: 4501
572
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From Log4j 2 documentation:

packages
A comma separated list of package names to search for plugins. Plugins are only loaded once per classloader so changing this value may not have any effect upon reconfiguration.
 
Saloon Keeper
Posts: 27763
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Line 1 of your sample says "ipackage". Is that really what's in the file? Because it shouldn't even compile if it is.

One of the paramount rules of log4j is that it works by being in the application classpath, including the log4 configuration file itself. So for webapps, that would be /WEB-INF/classes/log4j,xml. And, of course custom extensions would have to be located at their proper package stations as well.
 
John Farrel
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I've generated a Log4j2Plugins.dat file, and put it in a resources directory.
On startup, I still get the error messages, but later the appender does get called. Not ideal, but a step forward.
 
Ron McLeod
Marshal
Posts: 4501
572
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The factory method to create a plugin instance includes name, filter, and layout:
But in your config file, you only specify name:
Maybe the problem is that the signatures don't line-up??
 
Ron McLeod
Marshal
Posts: 4501
572
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is not an Appender plugin , but this is working code for a Log4j 2 Layout plugin that I wrote a while back.  Maybe it can provide some help?
 
John Farrel
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

For those that care, I still get an error on startup about not finding the appender, but the appender is getting called.
 
reply
    Bookmark Topic Watch Topic
  • New Topic