Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
ravi ch
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20527
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to Other Open Source Proejcts.

And please read your private messages.
 
Tanzy Akhtar
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic