M Sumantha Kannantha | 14 Jan 03:49 2015

Log4j2 error in the console

Hi All,

We are getting below error in stderr.

java.io.StreamCorruptedException: invalid stream header: 1B252D31


        at java.io.ObjectInputStream.<init>(ObjectInputStream.java:299)







        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
(Continue reading)

ppiman | 8 Jan 06:02 2015

Log4j2 - Custom HTML Layout footer not getting called to end the log file


I've run into a problem that I just can't figure out and I'm hoping you
will be able to help me.

My goal is to have log4j keep adding to the log file and at some point be
able called the log url address and my app display the log file on the fly
with out stopping the app or undeploying it.

So here goes:

I'm trying to do a log file for a web app. My app is JSF 2 (xhtml). I've
got my custom HTML Layout  that I extend from AbstractStringLayout. (Reason
I made custom HTML Layout was with XHTML this line in the log4j HTMLLayout
was throwing an error:  sbuf.append("<hr size=\"1\" noshade">") and XHTML
wants an <hr size=\"1\" noshade=\"noshade\">)

Now when I run my app, the log is generated and everthing is working except
the getFooter() method never gets called to finish the table and file.
Which when I call the URL to the log file I get a error saying the document
structure is not complete.

log4j2.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="INFO" packages="com.qualcomm.asictracker.util">
        <Property name="log-path">${web:rootDir}/WEB-INF/logs</Property>
(Continue reading)

Jason Novotny | 8 Jan 01:50 2015

how to override log4j.properties bundled in jar


I have a WAR file that contains a jar file that has a log4j.properties 
file baked into it. I want to override that with my own production 
log4j.properties file.

I thought it would be sufficient to just add

-Dlog4j.configuration=/tmp/log4j.properties to my java command line 

but I see that doesn't work. Any ideas on how to do this?

Thanks, Jason
Goran Karlic | 5 Jan 07:13 2015

Redirect log4j to JUL


How can I configure log4j to redirect output to java.util.logging?

Thank you!
David Kellerman | 3 Jan 20:08 2015

Converting log4j.properties file for Tomcat to work with Log4j2

(I originally posted a version of this question to stackoverflow, where it was suggested 
I might find more knowledgeable help on an apache mailing list.)

I'm trying to configure Tomcat 8 (Apache Tomcat/8.0.14 (Debian)) to use Log4j 2.1 
for logging.

I've found this reference for Logging in Tomcat using Log4j (not Log4j 2): 
http://tomcat.apache.org/tomcat-8.0-doc/logging.html#Using_Log4j. It provides a 
sample log4j.properties file that configures Log4j to match Tomcat's internal logging. 
Most of this looks pretty straightforward to convert for Log4j2, but the section at the 
end that maps loggers to appenders has me stumped:

    # Configure which loggers log to which appenders
    log4j.logger.org.apache.catalina.core.ContainerBase.[Catalina].[localhost] = INFO, LOCALHOST
    log4j.logger.org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager] =\
    log4j.logger.org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/host-manager] =\

Has anyone converted this configuration to work with Log4j2? I've been working 
from the Log4j2 configuration documentation and have read through the Log4j2 
Architecture page, but I haven't found much material (examples, in particular) on 
how to do this sort of container mapping in Log4j2.

I suppose I could do a separate configuration for each container, but I'd prefer to 
keep it in one place, as in the sample Log4j configuration.


(Continue reading)

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. http://logging.apache.org/log4j/2.x/manual/layouts.html - 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)