youri flement | 12 Nov 12:01 2014

Log to REST service


I was wondering if it is possible to configure Log4j to send my logs to a
REST service?
I have taken a look at the SocketAppender but I don't think that's what I'm
looking for.

Kind regards,
David KOCH | 10 Nov 17:32 2014

Unable to create detached markers via log4j-slf4j-impl 2.1.


I am unable to create detached versions of existing markers when using
log4j2 through the slf4j facade - log4j2 version is 2.1.


import org.slf4j.Marker;
import org.slf4j.MarkerFactory;

public class TestMarker {

    public static void main(String[] args) {
       Marker markerA = MarkerFactory.getMarker("testA");
       Marker markerB = MarkerFactory.getMarker("testB");
       Marker markerANew = MarkerFactory.getDetachedMarker("testA");
       // Iteration below will fail if this line is uncommented.
       //System.out.println("Removing reference from detached markerA: " +

       System.out.println("Has reference marker A: " +
       System.out.println("Has reference detached marker A: " +

       Iterator<Marker> mRef = markerA.iterator();
       while (mRef.hasNext()) {
(Continue reading) | 10 Nov 08:16 2014

[log4j2_2.1] How to write different log-messages to different log-files?

I want to write the 'trace' and 'debug' messages to debug.log, 'info' messages to info.log, and
'warn','error','fafal' messages to error.log

Here is a sample java code,
package com.r7oad.udsp.common.cache.test;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class Log4j2Test {
    private static final Logger logger = LogManager.getLogger(Log4j2Test.class);
    public static void main(String[] args){
        logger.trace("Hello world - trace log");
        logger.debug("Hello world - debug log");"Hello world - info log");
        logger.warn("Hello world - warn log");
        logger.error("Hello world - error log");
        logger.fatal("Hello world - fatal log");

<?xml version="1.0" encoding="UTF-8"?>

<configuration debug="off" monitorInterval="1800">
        <Property name="log-path">d://logs</Property>

(Continue reading)

Andrew Munn | 10 Nov 01:29 2014

Custom appender needed to HTTP POST log msgs?

I use the Slack chat application and I can post msgs to it using http POST 
like this:

curl -X POST --data-urlencode 'payload={"channel": "#general", "username": 
"webhookbot", "text": "This is the errort.", "icon_emoji": ":ghost:"}'

Is there a way to configure an off-the-shelf appender to HTTP POST log 
messsages like this directly?  Or do I need to create a custom appender?  
I know I could just log to a file, tail the file, and piece together that 
curl command in a shell script each time the file is appended to. 

Alexey Zavizionov | 5 Nov 20:03 2014

How to print timestamp on each log line of a stack trace?

Here is the output, when an application is throwing an exception, logging
it to log, including its stack trace.

E 1105-2042:17,349 c.e.TestLog error-message [main]
java.lang.Exception: SomeError
  at com.examples.TestLog.main(

Want to see the timestamp "E 1105-2042:17,349" on each log line.
How can I do? Is it possible with configuration file?
public class TestLog {
private static final Logger LOGGER = LoggerFactory.getLogger(TestLog.class);
public static void main(String[] args) {
LOGGER.error("error-", new Exception("SomeError"));

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
        <RollingRandomAccessFile name="server" fileName="server.log"
filePattern="" immediateFlush="false">
            <ThresholdFilter level="DEBUG" />
                <pattern>%level{length=1} %date{MMdd-HHmm:ss,SSS}
(Continue reading)

Paul Benedict | 3 Nov 22:38 2014

Re: log4j2.xml in EAR

Well I have the classes loading now. I still can't find my log4j2.xml but
at least the "api" and "core" libraries are being exposed to my application.

Okay, so to test this, make sure your "api" and "core" libraries are set to
"provided" scope in Maven. You don't want them already bundled; we want to
use the single copy installed in Wildfly.

My module file looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.3" name="org.apache.log4j2">
        <resource-root path="log4j-api-2.1.jar"/>
        <resource-root path="log4j-core-2.1.jar"/>
        <module name="javaee.api" />

It seems "core" is dependent upon JMX and other EE APIs; so I had to
include a dependency. We can probably figure out which EE modules are
really needed (and slim down), but I don't have the time to prune -- so I
included everything EE.

Next was my jboss-deployment-structure.xml. I have to export the log4j
libraries so my EJB modules can see them:

<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.0">
(Continue reading)

Shawn Heisey | 2 Nov 18:13 2014

RollingFileAppender appears to be losing log entries

I asked this question on the solr-user mailing list first, but got no response.  It's a major party weekend,
so I'm not really surprised, and I think this is probably a problem with log4j, not Solr.

There appear to be large blocks of time missing in my solr logfiles created with slf4j->log4j and rotated
using the log4j config:

End of solr.log.1: INFO  - 2014-10-31 12:52:25.073;
Start of solr.log: INFO  - 2014-11-01 02:27:27.404;

End of solr.log.2: INFO  - 2014-10-29 06:30:32.661;
Start of solr.log.1: INFO  - 2014-10-30 07:01:34.241;

There is about 2.5 hours missing for the first pair, and over 24 hours missing for the second.  I have not
checked all the logfiles to see if they are missing time.

Queries happen at a fairly constant low level at almost all hours, and updates happen once a minute, so I know
for sure that there is activity during the missing blocks of time.  I had a weird problem during the time that
is missing, so I have no way to determine what happened.

This is the log4j configuration that I'm using:

These are the logging jars that I have in jetty's lib/ext:

-rw-r--r-- 1 ncindex ncindex  16515 Apr 11  2014 jcl-over-slf4j-1.7.6.jar
-rw-r--r-- 1 ncindex ncindex   4959 Apr 11  2014 jul-to-slf4j-1.7.6.jar
-rw-r--r-- 1 ncindex ncindex 489883 Apr 11  2014 log4j-1.2.17.jar
-rw-r--r-- 1 ncindex ncindex  28688 Apr 11  2014 slf4j-api-1.7.6.jar
-rw-r--r-- 1 ncindex ncindex   8869 Apr 11  2014 slf4j-log4j12-1.7.6.jar
(Continue reading)

Paul Benedict | 1 Nov 18:56 2014

lo4j2.xml in EAR

When I used log4j 1.x, I could put my log4j.xml in the <EarRoot>/META-INF
folder and it was found. I did try this with log4j 2.0.2 and the
configuration was not found.

I read this but it only talks about WARs. I don't have a WAR but an EAR
with EJB modules.

So is this feature missing in 2.x? Or did I do something wrong?

David KOCH | 31 Oct 00:47 2014

Exception when using Syslog appender with RFC5424 layout


Log4j2 version is 2.0.2, my Syslog appender is configured like so:

<Syslog name="LogStash"  format="RFC5424" host=""
port="5000" protocol="UDP"/>

and I get the following exception:

2014-10-31 00:36:40,916 DEBUG Calling createAppender on class
org.apache.logging.log4j.core.appender.SyslogAppender for element Syslog
with params(host="", port="5000", protocol="UDP", null,
reconnectionDelay="0", immediateFail="true", name="LogStash",
immediateFlush="true", ignoreExceptions="true", facility="LOCAL0",
id="bidder", enterpriseNumber="18060", includeMdc="true", mdcId="null",
mdcPrefix="null", eventPrefix="null", newLine="false",
newLineEscape="null", appName="null", messageId="audit",
mdcExcludes="null", mdcIncludes="null", mdcRequired="null",
format="RFC5424", null,
Configuration(/Users/xxxx/Work/xxxxx/scripts/log4j2.xml), charset="UTF-8",
exceptionPattern="null", ={}, advertise="false")
2014-10-31 00:36:41,018 DEBUG Generated plugins in 0.099533 seconds,
packages: [org.apache.logging.log4j.core], preload: false.
2014-10-31 00:36:41,019 ERROR catching
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
(Continue reading)

konrad.mrozek | 27 Oct 18:25 2014

Logging level based on context name


I'm working in a project where we have few applications that have to use logs structure forced by client. I
want to use the same configuration file but separate log files. I thought about using "contextName"
property to generate file names for appenders. I also wanted to use automatic reconfiguration
(monitorInterval) but I stumbled upon one problem.

E.g. All applications use Spring. I wanted to set higher logging level for Spring in one of the
applications. Is it possible to set logging level for package for given context name? I've searched for
specific attribute/tag but I couldn't find one.


Alexander Lehmann | 26 Oct 23:32 2014

log4j2 how to write a wrapper that passes the class name of my own

 I am trying to write a log wrapper for log4j2 for a application server
that uses it's own logger with a wrapper for log4j 1.2, slf4j or JUL.

To be able to log method names and line numbers, the log4j 1.2 wrapper
currently passes the class name of the Logger to the log() method to
make it possible to log the correct method, otherwise only the log
method of the wrapper class is logged.
I am not able to figure out how to do that with log4j2 where the log
methods do not have a parameter for the class name.

(On a side-note, when I use log2j 1.2 and the log4j 1.2-api for log4j
2.x, logging method names works, so I'm probably missing something obvious)

Thanks for your help
bye, Alexander


Alexander Lehmann <alexlehm <at>>