Patrick Flaherty | 30 Dec 23:52 2014

Malformed JSONLayout output.

I was playing with using Log4j2 JSONLayout to push logs into Logstash and
on my setup it seems like Log4j is pushing out bad JSON. No comma's between
objects when complete="true". I have no idea if this is a bug, if it's
expected behavior, or if it's something upstream in jackson.

Here are the versions I am using:

OpenJDK 1.7.0_71  (centos 6 64 bit)

Here's a gist of the code, config, and output.

If I used the File appender, I get the exact same output (except in a
file). In an ideal world, there would be an append newline function like on
the syslog appender, which would make the files and the sockets much easier
to drive events off of (but that's getting a bit greedy).

Anyone have any thoughts on if this is a bug, where it would be filed, or
any work arounds?


p.s. - Doesn't list
JSONLayout in the manual menu on the left. Where do I file that?

(Continue reading)

James Hutton | 19 Dec 14:10 2014

Using markers or ThreadContext to select logger via slf4j

I have some libraries that leverage slf4j for logging (can't change it)
however my application leverages log4j2 and the slf4j-log4j2 bridge.  I was
wondering if there is a way I can at the beginning of the request flow set
a value in the ThreadContext or something so that the slf4j loggers will
route to a specific log4j2 logger instead of the root logger.  Is this

Mariano Gonzalez | 19 Dec 14:01 2014

Race condition stopping context


I have an application in which I'm using all async loggers. When I stop the
LoggerContext, there're still some events waiting in disruptor's buffer and
when it tries to execute them the context is already closed and thus those
events are lost.

Is there some kind of hook, callback or whatever I can use so that when the
context is stopped:

   - the loggers stop accepting new messages
   - the context waits for disruptor's buffer to be empty before actually

Ben Stover | 19 Dec 11:43 2014

How to write encrypted (!) lines to logfile ?

As far as I know the standard way of writing log output to logfiles is as plain human readable text.

Is there a way to configure log4j to enrypt lines before writing?
Or (re-)encrypt whole logfile after writing?

The encryption should NOT take place IN the writing application but be configured inside log4j configuration.

Alireza Fattahi | 17 Dec 15:32 2014

rThrowable does not call getLocalizedMessage

It seems that the %rThrowable{full} pattern will not use getLocalizedMessage by default, while the
%Throwable{full} will out put it.
The rThrowable{short.localizedMessage} is nor working
My pattern is:
<property name="consolelayoutPattern">%-5p %-30.30c{2} %m%n%rThrowable{full}</property>

Do you think the default behavior of rThrowable must be changed ? ~Regards,
~~Alireza Fattahi
Alireza Fattahi | 15 Dec 05:50 2014

Log4j2 web look up cannot access servletcontext attribute

We are using Tomcat 7.0.54. 
The web.xml:
 <context-param>        <param-name>log4jContextName</param-name>       
<param-value>SabaLog4jContext</param-value>    </context-param>
There is sample servlet which starts on load
        <servlet>            <servlet-name>startUp</servlet-name>           
<load-on-startup>1</load-on-startup>        </servlet>
The StartupServlet simple as:
    public class StartupServlet extends HttpServlet {         <at> Override        public void init()
throws ServletException {            getServletContext().setAttribute("test", "ATest");   
        super.init();        }        }
The log4j2 can not access the `test` attribute with `${web:attr.test}` and I got the warning as:
    INFO: org.apache.logging.log4j.web.WebLookup unable to resolve key 'test'
It seems that Log4j2 works fine but the problem is that it starts before my Startup. I tried to use a
`servletContextListener` class but no luck.
I also tried to disable Log4jAutoInitialization in web.xml and manually start set them as below.
  </listener>         <filter>       <filter-name>log4jServletFilter</filter-name>   
</filter>    <filter-mapping>       <filter-name>log4jServletFilter</filter-name>     
 <url-pattern>/*</url-pattern>       <dispatcher>REQUEST</dispatcher>     
<dispatcher>FORWARD</dispatcher>      <dispatcher>INCLUDE</dispatcher>     
<dispatcher>ERROR</dispatcher>    </filter-mapping>

But no luck:(
The log4j2.xml is as below:
    <property name="baseFolder">${web:rootDir}/../logs/${web:test}</property>
So how can setup my web.xml so that my code execute before Log4j context.
(Continue reading)

Mariano Gonzalez | 2 Dec 18:46 2014

ArrayIndexOutOfBoundsException with RollingFileApender


I'm progamatically creating an appender with the following code:

private static final String PATTERN_LAYOUT = "%-5p %d [%t] %c: %m%n";

private RollingFileAppender createRollingFileAppender(String logFilePath,
String filePattern, String appenderName, Configuration configuration)
    TriggeringPolicy triggeringPolicy =
TimeBasedTriggeringPolicy.createPolicy("1", "true");
    RolloverStrategy rolloverStrategy =
DefaultRolloverStrategy.createStrategy("30", "1", null,
String.valueOf(Deflater.NO_COMPRESSION), configuration);

    return RollingFileAppender.createAppender(logFilePath,
      logFilePath + filePattern,
      null, null,
      null, null, null, null,

private Layout<? extends Serializable> createLayout(Configuration
(Continue reading)

Yair Ogen (yaogen | 30 Nov 09:29 2014

includeLocation = true by default in LoggerConfig

I am using log4j2.1. any reason this flag is set to true by default? It is very expensive (cpu wise) and AFAIK
is something usually set by the pattern (i.e. display source file and source line).

J.Hoffmann | 25 Nov 17:49 2014

What happened to Telnet-Appender in log4j2?

Hi everybody,

We have used the Telnet-Appender with log4j.
When migrating to log4j2 I have seen, that it seem to doesn't exist anymore
in log4j2?
I was even not able to find any information at Apache. What happend to
Telnet Appender?

Thanks for reply.

Stephan Druskat | 24 Nov 10:58 2014

Using log4j2 2.1 over slf4j 1.7.7 in Eclipse RCP

Dear List,

I'm developing an Eclipse RCP based on Eclipse 3.7.2 (Indigo).

I'd like to use log4j2 (2.1) over slf4j 1.7.7, but I'm having trouble
getting it to work. I have done the following to add log4j2 and slf4j to
my application.

- I've built a p2 repo including slf4j.api_1.7.7.jar,

- I've consumed this p2 repo in my target platform + added it to the
parent POM of my project.

- I've added all 4 plugins to my Eclipse plugin project as dependencies

- I've created a file log4j2.xml in the project root in my Eclipse
plugin. Content below.

- I've added a private static final Logger logger =
LoggerFactory.getLogger(MyClass.class) field to MyClass

- In MyClass, I've called logger.error("Hi from logger").

However, when I run my application, I'm getting an error message: ERROR
StatusLogger Log4j2 could not find a logging implementation. Please add
log4j-core to the classpath. Using SimpleLogger to log to the console...
(Continue reading)

Dave Westerman | 21 Nov 17:18 2014

Commit errors using log4j2 JDBCAppender with DB2 in WebSphere Liberty Profile

I am trying to use the log4j2 JDBCAppender in my JEE application in 
WebSphere Liberty Profile with a DB2 DataSource. I'm wondering if I have a 
configuration error, because I am seeing the following error in my log:

Caused by: java.sql.SQLException: DSRA9350E: Operation Connection.commit 
is not allowed during a global transaction. 



    ... 84 more 
2014-11-20 20:23:33,663 ERROR An exception occurred processing Appender 
org.apache.logging.log4j.core.appender.AppenderLoggingException: Failed to 
commit transaction logging event or flushing buffer. 

Here is my log4j config data:

    <JDBC name="OneViewPrimaryLogDatabase" tableName="IONEVIEW.LOG"> 
        <DataSource jndiName="jdbc/OneViewPrimaryLogDataSource" /> 
        <Column name="LOGDATE" isEventTimestamp="true" /> 
        <Column name="LOGGER" pattern="%logger" isUnicode="false" /> 
        <Column name="LOGLEVEL" pattern="%level" isUnicode="false" /> 
        <Column name="MESSAGE" pattern="%message" isUnicode="false" /> 

And here is my DataSource config from WLP:
(Continue reading)