Kamal Mettananda | 28 Mar 21:00 2016
Picon
Gravatar

XMLLayout indents, but not the first child tag (<Event>)

Hi all

I am using log4j 2.5 to print the logs via XMLLayout. I have set
compact="true", hence the new line and indents of sub tags work correctly.
However I have noticed that the first child tag is not indented corrected.
Following is such a sample where <Events> and <Event> are at the same
indent level (0 indent). I do think this is a formatting issue in the code
rather than expected behavior; but I might be wrong?

<?xml version="1.0" encoding="UTF-8"?>
<Events xmlns="http://logging.apache.org/log4j/2.0/events">
<Event xmlns="http://logging.apache.org/log4j/2.0/events"
timeMillis="1459191034362" thread="main" level="INFO"
loggerName="org.logging.learn.log4j.Main" endOfBatch="false"
loggerFqcn="org.apache.logging.log4j.spi.AbstractLogger">
  <Message>6 + 4 = 10</Message>
</Event>

<Event xmlns="http://logging.apache.org/log4j/2.0/events"
timeMillis="1459191034457" thread="main" level="INFO"
loggerName="org.logging.learn.log4j.Main" endOfBatch="false"
loggerFqcn="org.apache.logging.log4j.spi.AbstractLogger">
  <Message>6 - 4 = 2</Message>
</Event>

</Events>

Thanks
Maple Wang | 28 Mar 10:35 2016
Picon

is there any way to add a marker to a logger rather than a log

Hi,

Marker is great feature for classifying and filtering log content, but I
have a question about how to use marker in logging API. In official guide
for log4j2.x, normally, we need to do as blow:

Marker myMarker =  MarkerManager.getMarker("myMarker");

LOGGER.info(myMarker,"some log message");

This is good, but in my situation, I want to add a marker directly to a
LOGGER, then, every time user use "LOGGER.info("some log message");", the
marker will be added automatically. Is there any way to help me to achieve
this?

Thanks in advance.

Best regards.

Mike Tod | 24 Mar 16:10 2016

JMSAppender

Has anyone been able to get the JMSAppender working on Log4j2?

If so do you have any example config?

Below is my config file :

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
  <Appenders>

    <Console name="Console" target="SYSTEM_OUT">
      <PatternLayout pattern="%d{HH:mm:ss.SSS} %-5level %class{36} %L %M - %msg%xEx%n"/>
    </Console>

   <File name="LogFile" fileName="c:/temp/ReportGenerationTesting/Logs/appjms.log">
      <PatternLayout>
        <Pattern>%d{HH:mm:ss.SSS} %-5level %c{1.} %M:%L - %msg%xEx%n</Pattern>
      </PatternLayout>
    </File>

    <JMS name="jmsQueue"
          factoryName="org.apache.activemq.jndi.ActiveMQInitialContextFactory"
          factoryBindingName="ConnectionFactory"
          providerURL="tcp://localhost:61616"
          destinationBindingName ="jmsTest"
          userName="admin"
          password="admin"
    />

  </Appenders>
(Continue reading)

Kamal Mettananda | 22 Mar 19:30 2016
Picon
Gravatar

Header does not end with a new line in Console appender

Hi all

This is my first email, so please raise if I have not correctly understood
the usage of the header attribute.

When I add a text to the header attribute of PatternLayout inside Console
appender, the header will not end with a new line hence the first log line
will also be using the same line as the header line; but this is not the
case for footer attribute.

Example output:
My Header in Log2016-03-22 23:23:48,487 [main] INFO
 org.logging.learn.log4j.Main - some log1
2016-03-22 23:23:48,487 [main] INFO  org.logging.learn.log4j.Main - some
log2
Footer

Below is the sample of my log4j2.xml

<Configuration status="WARN">
  <Appenders>
    <Console name="Console" target="SYSTEM_OUT">
      <PatternLayout pattern="%d [%t] %-5level %logger - %msg%n" header="My
Header in Log" footer="Footer"/>
    </Console>
  </Appenders>
  <Loggers>
    <Root level="info">
      <AppenderRef ref="Console"/>
    </Root>
(Continue reading)

Thomas Papke | 22 Mar 11:48 2016
Picon

Issues with JMX Mbean

Hello all,

I start using Log4j2 2.5 with an Apache Tomcat container. The integration works so fare, but I have
identified some issues with the exposed Jconsole Mbean.

1.       The loggers run into a NullPointer if someone use an incorrect logger name. After this nullpointer, the
Mbean display "Unavailable" for this logger, so the whole config file must be reloaded. Here the log
output of my local testing. I would expect that the logger do not except the incorrect value and internally
remain with the previous value (maybe throw a IllegalArgumentException to give a feedback to the user).

validating [row=4, column=1]: Level=asdfasdf

setAttribute(Level=asdfasdf)

java.lang.NullPointerException

               at org.apache.logging.log4j.core.config.LoggerConfig.getLevel(LoggerConfig.java:261)

               at org.apache.logging.log4j.core.Logger$PrivateConfig.<init>(Logger.java:312)

               at org.apache.logging.log4j.core.Logger.updateConfiguration(Logger.java:293)

               at org.apache.logging.log4j.core.LoggerContext.updateLoggers(LoggerContext.java:595)

               at org.apache.logging.log4j.core.LoggerContext.updateLoggers(LoggerContext.java:585)

               at org.apache.logging.log4j.core.jmx.LoggerConfigAdmin.setLevel(LoggerConfigAdmin.java:82)

2.       The ConfigLocationUri is also editable in the Mbean, but the behavior is a bit strange. If I type in the
correct location e.g. "file:/opt/tomcat /apache-tomcat/conf/log4j2.xml" it correctly load the file
(Continue reading)

Ron Gonzalez | 21 Mar 17:05 2016
Picon

Async Appender - Consumer thread dying - new thread unable to start

We are seeing a situation where the consumer thread
"AsyncLoggerConfig-1" is apparently dying.
We do see a new consumer thread trying to start up, but it is blocked
waiting for a lock, so no logging is happening.

Is this a defect in log4j?
Is the original consumer thread dying due to perhaps an unhandled exception ?
Is that original consumer thread not terminating gracefully and
releasing the locked object so the new consumer thread can start?

Please see attached screenshot.  Top of screen is normal
asyncloggerconfig thread (consumer).
Bottom is thread trace when logging stops, we no longer see an
"asyncloggerconfig-1" thread, instead a new thread is trying to start
but never does "asyncloggerconfig-2".


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe <at> logging.apache.org
For additional commands, e-mail: log4j-user-help <at> logging.apache.org
WangMaple | 18 Mar 15:34 2016
Picon

how to suppress stacktrace for PatternLayout in ConsoleAppender in Log4j 2.x

Hi,

I'm trying to realize a feature which can programmatically
suppress exception's stacktrace for PatternLayout in ConsoleAppender in Log4j
2.x.  Actually it’s very easy to do that in Log4j 1.x, I just extend the
PatternLayout like below:

public class MyPatternLayout extends PatternLayout {

…

        Public void
format(LoggingEvent event) {

               
// according to event to decide if ignores throwable

        }

        Public Boolean
ignoresThrowable() {

               
Return ignoresThrowable;

        } 

…

}
(Continue reading)

Prasanth Jayachandran | 16 Mar 01:08 2016
Picon

Async Logger

Hi All

We are using log4j2 in Apache Hive project. We are exploring the option of using Async Logger. From the doc,
https://logging.apache.org/log4j/2.x/manual/async.html#AllAsync the requirements for async
loggers are the presence of disruptor jar in classpath and the system property Log4jContextSelector to
be set to org.apache.logging.log4j.core.async.AsyncLoggerContextSelector. 

But I noticed that even without setting the system property, just by having the disruptor jar in the
classpath enables Async logging. Is this a bug or am I missing something here? 

Thanks
Prasanth
Bilguun Ariunbold | 15 Mar 20:12 2016
Picon

How to create the custom marker in log4j2/slf4j?

down votefavorite
<https://stackoverflow.com/questions/36018016/how-to-create-the-custom-marker-in-slf4j-log4j2#>

I am trying to create custom marker using slf4j and log4j2. Below is how I
created the marker and used it:

Marker marker =
org.slf4j.MarkerFactory.getMarker("WebService");logger.info(marker,
"service called");

And below is my log4j2-test.xml:

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="DEBUG">
    <Properties>
        <Property name="layout">%d | %-5p | [%t] | %c{2} | %M | %m%n</Property>
    </Properties>
    <Appenders>
        <File name="WebServices"
fileName="${sys:user.home}/logs/service_requests.log">
            <MarkerFilter marker="WebService" onMatch="ACCEPT"
onMismatch="DENY" />
            <JSONLayout>
            </JSONLayout>
        </File>
    </Appenders>
    <Loggers>
        <Root level="TRACE">
            <AppenderRef ref="WebServices" level="INFO" />
        </Root>
(Continue reading)

Denis Kostousov | 14 Mar 06:45 2016
Picon

Different log4j v2 config file for different ear

Hello, All.

I want to use log4j from my own JavaEE applications. These applications consist of some ejb-jars and wars. I
need to use separate config file for each application.
I tried to write  <at> Singleton EJB that reconfigures log4j with specific file:
<code>
        LoggerContext context = (org.apache.logging.log4j.core.LoggerContext) LogManager.getContext(false);
        context.setConfigLocation(myConfigFILE.toURI());
</code>

But this didn't work in my case.
How I can specify the log4j config file name in ear?

--

-- 
Denis Kostousov
email: denisATkst-dDOTnet
jabber: sandelloATjabber.ru
fingerprint: 8333 395D 395A B7D7 2CDF BBBF 14E2 EE1E E797 04EB
linkedin: http://www.linkedin.com/profile/view?id=101014719
Andrei Ivanov | 8 Mar 16:12 2016
Picon

default value for empty ${web:contextPath}

Hello,
In the hope that someone else might have a better solution, I'm trying here.

As you can see in
http://stackoverflow.com/questions/35729590/log4j2-lookup-default-value-with-empty-contextpath,
I'm trying to set the filename of an appender using the context path
of the web application.

It works except the case when the app is deployed as the root of the
virtual host, case when the contextPath is an empty string (not null).

The default (specified in the Properties section) is only used when
the lookup returns null.

Is there anything else I can do besides writing a plugin just for this?

Regards

Gmane