GeeCON Prague 2014*
The moose likes Other Open Source Projects and the fly likes log4j.xml configuration for configuring input from specific file only to consider logging. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "log4j.xml configuration for configuring input from specific file only to consider logging." Watch "log4j.xml configuration for configuring input from specific file only to consider logging." New topic
Author

log4j.xml configuration for configuring input from specific file only to consider logging.

ravi ch
Greenhorn

Joined: Jul 26, 2007
Posts: 1
Hi,
I am using log4j for logging statements to different files. But for logger.debug it is logging all the logs inside the jars which it uses.
But i want to log statements form specific file only. I used log4j.xml . let me know how can i configure this to take input from specific file.
what is the property name for FileAppennder. below is the log4j.xml i used. Any body please solve this ASAP.



<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd" >
<log4j:configuration>
<appender name="inforef"
class="org.apache.log4j.RollingFileAppender">
<param name="maxFileSize" value="100KB" />
<param name="maxBackupIndex" value="5" />
<param name="File" value="D:/Avago/Ravi/workspace_eclipse/Sample/logs/info.log" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern"
value="%d %5p %c{1}:%L - %m%n" />
</layout>
<filter class="org.apache.log4j.varia.LevelMatchFilter">
<param name="LevelToMatch" value="info" />
<param name="AcceptOnMatch" value="true"/>
</filter>
<filter class="org.apache.log4j.varia.DenyAllFilter" />

</appender>

<appender name="debugref"
class="org.apache.log4j.RollingFileAppender">
<param name="maxFileSize" value="100KB" />
<param name="maxBackupIndex" value="5" />
<param name="File" value="D:/Avago/Ravi/workspace_eclipse/Sample/logs/debug.log" />
<param name="Location" value="com.avagotech"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern"
value="%d %5p %c{1}:%L - %m%n" />
</layout>
<filter class="org.apache.log4j.varia.LevelMatchFilter">
<param name="LevelToMatch" value="debug" />
<param name="AcceptOnMatch" value="true"/>
</filter>
<filter class="org.apache.log4j.varia.DenyAllFilter" />

</appender>

<!-- <appender name="warnref"
class="org.apache.log4j.RollingFileAppender">
<param name="maxFileSize" value="100KB" />
<param name="maxBackupIndex" value="5" />
<param name="File" value="D:/Avago/Ravi/workspace_eclipse/Sample/logs/warn.log" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern"
value="%d %5p %c{1}:%L - %m%n" />
</layout>
<filter class="org.apache.log4j.varia.LevelMatchFilter">
<param name="LevelToMatch" value="warn" />
<param name="AcceptOnMatch" value="true"/>
</filter>
<filter class="org.apache.log4j.varia.DenyAllFilter" />

</appender>-->

<appender name="errorref"
class="org.apache.log4j.RollingFileAppender">
<param name="maxFileSize" value="100KB" />
<param name="maxBackupIndex" value="5" />
<!-- <param name="DatePattern" value="yyyy-MM-dd-HH-mm" /> -->
<param name="File" value="D:/Avago/Ravi/workspace_eclipse/Sample/logs/error.log" />
<!-- <param name="threshold" value="error" />-->
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern"
value="%d %5p %c{1}:%L - %m%n" />
</layout>
<filter class="org.apache.log4j.varia.LevelMatchFilter">
<param name="LevelToMatch" value="error" />
<param name="AcceptOnMatch" value="true"/>
</filter>
<filter class="org.apache.log4j.varia.DenyAllFilter" />

</appender>
<!-- <appender name="mail" class="org.apache.log4j.net.SMTPAppender">
<param name="SMTPHost" value="smtp.myservername.xx" />
<param name="From" value="email@fromemail.xx" />
<param name="To" value="toemail@toemail.xx" />
<param name="Subject" value="[LOG] ..." />
<param name="BufferSize" value="1" />
<param name="threshold" value="error" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern"
value="%d{ABSOLUTE} %5p %c{1}:%L - %m%n" />
</layout>
</appender> -->
<root>
<priority value="debug"></priority>
<!-- <priority value="warn"></priority> -->
<appender-ref ref="debugref" />
<appender-ref ref="inforef" />
<appender-ref ref="errorref" />
</root>
</log4j:configuration>

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

Moving to Other Open Source Proejcts.

And please read your private messages.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Tanzy Akhtar
Ranch Hand

Joined: Jul 19, 2009
Posts: 110
Hi Ravi,

You may resolve this problem in many ways.
But what i found really easy and also applied in my project to resolve this kind of issue.

Steps are as follows--

1. create a class, define it's own logger and a method (name is your choice) which calls nothing
but log.debug().

2. Now call this method wherever this debug is needed to be logged.

You may take help from this.

Any query, please ask it.

Thanks,
Tanzy.

Roll with punchers, there is always tomorrow.
Techie Blog -- http://jtanzy.blogspot.com/
 
GeeCON Prague 2014
 
subject: log4j.xml configuration for configuring input from specific file only to consider logging.