Win a copy of Emmy in the Key of Code this week in the General Computing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

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

 
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>

 
Sheriff
Posts: 21817
104
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to Other Open Source Proejcts.

And please read your private messages.
 
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.
 
Watchya got in that poodle gun? Anything for me? Or this tiny ad?
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!