Events in log4j can be generated in two ways:
- log methods in code (logger.debug, etc)
- a receiver

Appenders can process events generated by either of these mechanisms.

In your case, you want to process events stored in a log file 
(LogFilePatternReceiver) and store those events in a database (JDBCAppender).

Specify both the receiver and appender configuration in the same xml config 
file and it should work fine.

All you should need to do is create a simple class whose main method calls 
DomConfigurator.configure("c:/log4j/log4j.xml").

Here's an example configuration that provides a logfilepatternreceiver and a 
consoleappender with an attached expressionfilter (requires log4j 1.3 alpha 
jars and jakarta-oro jar).

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration >
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"; 
debug="true">
   <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
     <layout class="org.apache.log4j.SimpleLayout"/>
     <filter class="org.apache.log4j.filter.ExpressionFilter">
       <param name="Expression" value="msg ~= 'SPECIFY CASE-INSENSITIVE MSG 
MATCH HERE'" />
       <param name="AcceptOnMatch" value="true"/>
     </filter>
     <filter class="org.apache.log4j.filter.DenyAllFilter"/>
   </appender>
   
   <plugin name="LOGFILE" class="org.apache.log4j.varia.LogFilePatternReceiver">
     <param name="fileURL" value="file:///c:/some.log"/>
     <param name="timestampFormat" value="yyyy-MM-dd HH:mm:ss,SSS"/> 
     <param name="logFormat" value="TIMESTAMP LEVEL [LOGGER] MESSAGE"/> 
     <param name="name" value="my log file"/>
     <param name="tailing" value="true"/> 
   </plugin>
   
   <root>
      <level value="DEBUG"/>
      <appender-ref ref="CONSOLE"/>
   </root>
</log4j:configuration>

ExpressionFilter supports all fields on logging events and provides a number of 
operators.  See the tutorial in Chainsaw V2 for a better explanation of the 
syntax used by ExpressionFilter (used in Chainsaw to colorize/filter/search 
events): http://logging.apache.org/log4j/docs/chainsaw.html

NOTE: The denyallfilter ensures events are dropped if they weren't accepted by 
the expressionfilter.

Something appears to be wrong with logfilepatternreceiver in the alpha8 
distribution - if you have the alpha7 jars, use them instead for now.


Scott Deboy
COMOTIV SYSTEMS
111 SW Columbia Street Ste. 950
Portland, OR  97201

Telephone:      503.224.7496
Cell:           503.997.1367
Fax:            503.222.0185

[EMAIL PROTECTED]

www.comotivsystems.com



-----Original Message-----
From: Alexey Vorobiev [mailto:[EMAIL PROTECTED]
Sent: Tue 2/14/2006 5:33 AM
To: Log4J Users List
Subject: Re: Help with LogFilePatternReceiver 
 
There is no way i can change config files for the 
application.
I've written the program to parse log file using 
logfilepatternreciever
  but how can I get the log records from it?
Where are they stored during parsing?

Thanks in advance.


On Mon, 13 Feb 2006 07:02:46 -0800
  "Scott Deboy" <[EMAIL PROTECTED]> wrote:
> Can you modify the app's log4j config file?  If so, add 
>a database appender to it.
> 
> If not, yes, you can specify both a 
>logfilepatternreceive  and a database appender in the 
>same config file.
> 
> 
> Scott Deboy
> COMOTIV SYSTEMS
> 111 SW Columbia Street Ste. 950
> Portland, OR  97201
> 
> Telephone:      503.224.7496
> Cell:           503.997.1367
>Fax:            503.222.0185
> 
> [EMAIL PROTECTED]
> 
> www.comotivsystems.com
> 
> 
> 
> -----Original Message-----
>From: Alexey Vorobiev [mailto:[EMAIL PROTECTED]
> Sent: Mon 2/13/2006 5:47 AM
> To: [email protected]
> Subject:  Help with LogFilePatternReceiver 
> 
> Hello,
> 
> Could someone help me please?
> 
> I need to parse log files with my program and insert 
> filtered rows to the Database. I don't have access to 
>the 
> program that writes this logs but it is using log4j and 
>i 
> know the format. Is it possible to use 
> LogFilePatternReceiver to read information from this log 
> file?
> Could someone provide example on how to get events data?
> 
> Thanks in advance.
> 
> With Regards,
> Alexey Vorobiev
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: 
>[EMAIL PROTECTED]
>For additional commands, e-mail: 
>[EMAIL PROTECTED]
> 
> 
> 

With Regards,
Alexey Vorobiev

Tel: +7 (095) 1045136

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to