Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Log4j2 Custom appender: ERROR Attempted to append to non-started appender

I have created a custom appender in log4j2. While using the custom appender, I am getting the following error: "ERROR Attempted to append to non-started appender". Any help is appreciated.

like image 532
janeshs Avatar asked Aug 30 '16 13:08

janeshs


People also ask

What is Appender in log4j?

Log4j allows logging requests to print to multiple destinations. In log4j speak, an output destination is called an appender. Currently, appenders exist for the console, files, GUI components, remote socket servers, JMS, NT Event Loggers, and remote UNIX Syslog daemons. It is also possible to log asynchronously.

How do I use console Appenders in Log4j2?

Log4j2 ConsoleAppender ConfigurationThe target poperty specifies the target of the logging messages i.e. SYSTEM_OUT or SYSTEM_ERR . The follow attribute tells whether the appender should honor the reassignments of System. out or System. err made after the logging configuration has been initialized.


1 Answers

Log4j 2 checks for each log event that the appender is in a useable state. The error you are seeing is that Log4j detects that the appender is not ready to be used.

Some appenders need to do preparation before they can be used. The start() lifecycle method is the place where appenders can do initialization. Log4j will not route events to an appender that is not in a STARTED state.

If your appender is added by configuration, Log4j will call the lifecycle method. If your appender extends AbstractAppender, this will update the state and should be sufficient. Otherwise take a look at the lifecycle state management in AbstractAppender.

If you configure in code you may need to call start() explicitly.

like image 130
Remko Popma Avatar answered Sep 23 '22 05:09

Remko Popma