Thanks for the replies.  Let me ask a more pointed question now as rummaging 
through the source will probably take me hours.  I'm curious about the 
overloads with the throwable, for instance:


logger.error("some message", <some throwable>);


What's the expected behavior?  Meaning, what is the logging framework going to 
do with the message and the exception?  I know the message is usually output 
via the message property in the pattern layout.  But what happens with the 
throwable?  Is there some code responsible for constructing a message which 
combines the supplied message with the throwable exception message and 
callstack?


I wrote the following simple java sample:


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

public class Test
{
    private static final Logger logger = LogManager.getLogger(Test.class);

    public static void main(String[] args)
    {
         logger.info("entered main");
    try
            {
            throw(new IllegalArgumentException("bad argument"));
            }
    catch(Throwable t)
            {
            logger.error("caught exception", t);
            }
    logger.info("exiting main");
    }
}


Here is the log4j2.xml file:


<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
    <Appenders>
        <Console name="Console" >
            <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} \
- %msg%n"/>
        </Console>
    </Appenders>
    <Loggers>
    <Root level="info">
            <AppenderRef ref="Console"/>
    </Root>
    </Loggers>
</Configuration>


Here is the output to the console when I run the sample:


[nick@thinkpad log4j]$ java Test
16:37:57.681 [main] INFO  Test - entered main
16:37:57.683 [main] ERROR Test - caught exception
java.lang.IllegalArgumentException: bad argument
    at Test.main(Test.java:13) [log4j/:?]
16:37:57.689 [main] INFO  Test - exiting main


So there does seem to be some code which is combining the message with the 
exception.  Just wondering where that happens.  Now onto my specific problem.  
We've got someone saying that when they use the error() method which takes a 
string message and an throwable the exception information is not making it to 
our central repository.  We have written our own appender and our own layout.  
Here is a snippet from our appender:


String serializedEvent = (String) getLayout().toSerializable(logEvent);

Here is a snippet from our layout:


String message = logEvent.getMessage().getFormattedMessage();


It seems the message above does not include any exception info.  What are we 
doing wrong?


Thanks,

Nick

________________________________
From: Remko Popma <remko.po...@gmail.com>
Sent: Friday, November 4, 2016 10:42 AM
To: Log4J Users List
Subject: Re: looking for source

Sure. Start in AbstractLogger in the API module: 
https://github.com/apache/logging-log4j2/blob/master/log4j-api/src/main/java/org/apache/logging/log4j/spi/AbstractLogger.java

and at some point you probably also want to look at the concrete subclass 
Logger in the core module: 
https://github.com/apache/logging-log4j2/blob/master/log4j-core/src/main/java/org/apache/logging/log4j/core/Logger.java

Hope this helps to get you started.

It may be easier to use an IDE and check out the whole project 
(https://logging.apache.org/log4j/2.x/source-repository.html).
Log4j - Source Repository - Apache Log4j 
2<https://logging.apache.org/log4j/2.x/source-repository.html>
logging.apache.org
Access from Behind a Firewall. Refer to the documentation of the SCM used for 
more information about access behind a firewall.



Enjoy!
Remko

Sent from my iPhone

> On 4 Nov 2016, at 23:29, Nicholas Duane <nic...@msn.com> wrote:
>
> I'm not that familiar with java and java conventions, package names, etc.  
> I'm trying to find the source for log4j2's implementation of 
> logger.error(String, Throwable);.  Can someone point me to that?  I was 
> looking around here:
>
>
> https://git-wip-us.apache.org/repos/asf?p=logging-log4j2.git;a=tree;hb=refs/heads/master
>
>
> But couldn't seem to find what I was looking for.
>
>
> Thanks,
>
> Nick

Reply via email to