logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Scott Deboy" <sde...@comotivsystems.com>
Subject RE: Getting Log-Entries back with log4J
Date Fri, 22 Jul 2005 16:38:14 GMT
Try the file below.  You have to have the log4j 1.3 binaries in the classpath  (uses log4j
1.3's XmlDecoder).

Configure the app to use your log4j.xml file with whatever appenders you need (use the -Dlog4j.debug=true
and -Dlog4j.configuration=mylog4j.xml to get it configured).

I tested it using a SocketAppender which sent events to Chainsaw V2.  

The events I processed looked like this (no xml declaration or event set section):

<log4j:event logger="org.apache.log4j.some-other.LogUI" timestamp="1122046373629" sequenceNumber="1"
level="INFO" thread="Thread-6">
<log4j:message><![CDATA[Using '' for auto-configuration]]></log4j:message>
<log4j:properties>
    <log4j:data name="application" value="some-other-log"/>
    <log4j:data name="hostname" value="some-other"/>
    <log4j:data name="log4jid" value="1"/>
</log4j:properties>
</log4j:event>

<log4j:event logger="org.apache.log4j.some-other.help.HelpManager" timestamp="1122046373754"
sequenceNumber="2" level="WARN" thread="Thread-6">
<log4j:message><![CDATA[Could not find any local JavaDocs, you might want to consider
running 'ant javadoc'. The release version will be able to access Javadocs from the Apache
website.]]></log4j:message>
<log4j:properties>
    <log4j:data name="application" value="some-other-log"/>
    <log4j:data name="hostname" value="some-other"/>
    <log4j:data name="log4jid" value="2"/>
</log4j:properties>
</log4j:event>



Here's the code:

-------------
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Collection;
import java.util.Iterator;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.apache.log4j.spi.LoggingEvent;
import org.apache.log4j.xml.XMLDecoder;

public class XmlFileReappender {

    //initialize the log4j framework
    private static final Logger logger = LogManager.getLogger(XmlFileReappender.class.getName());

    public static void main(String[] args) {
        XMLDecoder decoder = new XMLDecoder();
        Collection c;
        try {
            c = decoder.decode(new URL("file:///c:/sampleevents.xml"));
            for (Iterator iter = c.iterator();iter.hasNext();) {
                LoggingEvent evt = (LoggingEvent)iter.next();
                Logger.getRootLogger().callAppenders(evt);
            }
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}


Scott

-----Original Message-----
From:	Sven Abels [mailto:News@abelssoft.de]
Sent:	Fri 7/22/2005 7:03 AM
To:	log4j-user@logging.apache.org
Cc:	
Subject:	Getting Log-Entries back with log4J
Hi guys,

I'm using log4J in a project and we use the XML output, which works fine. 
However: We will now need a way to retrieve log entries again.  Is there a
way to get back the log rentries with log4J without using an external XML
parser for our logfile?


Best greetings,

Sven



---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org






Mime
View raw message