Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / September 2004

Tip: Looking for answers? Try searching our database.

Log4j Issue

Thread view: 
Ragavendra BC - 30 Aug 2004 15:37 GMT
Log4j Issue
-----------

Hi,
I am facing a problem related to Log4j...

The problem is such that I have two different Log4j files one in
.properties format and the other in the .xml format..

and their source code is like this

a.properties
--------------

log4j.appender.rollinglogfile=org.apache.log4j.RollingFileAppender
#log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.rollinglogfile.layout.ConversionPattern=%d{dd MMM yyyy
HH\:mm\:ss,SSS} %-5p %-20t %c{3} - %m%n
log4j.appender.rollinglogfile.Threshold=DEBUG
log4j.appender.rollinglogfile.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{dd MMM yyyy
HH\:mm\:ss,SSS} %-5p %-20t %c{3} - %m%n
log4j.debug=false
admincentral.dsl.vdr.docsrv=vdr
log4j.appender.stdout.Threshold=DEBUG
log4j.appender.rollinglogfile.MaxFileSize=10MB
log4j.appender.rollinglogfile.File=D\:\\Apache Tomcat
4.0\\bin\\AdminCentral.log
admincentral.dsl.vdr.port=1542
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.rollinglogfile.MaxBackupIndex=5
log4j.rootCategory=ERROR, stdout, rollinglogfile
admincentral.dsl.vdr.host=wksabc
log4j.layout.ConversionPattern=%d{dd MMM yyyy HH\:mm\:ss,SSS} %-5p
%-20t %c{3} - %m%n"
admincentral.dsl.list=xyz,

b.xml
-----
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j='http://jakarta.apache.org/log4j/'
debug="false">
<appender name="CONSOLE_APP"
class="org.apache.log4j.ConsoleAppender">
          <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="priority-%-5p;
class - %C; method - %M; message - %m%n"/>
         </layout>    
</appender>

<appender name="FILE_APP_DEBUG"
class="org.apache.log4j.RollingFileAppender">
          <param name="File" value="debug.log" />
          <param name="MaxFileSize" value="10000KB" />
          <param name="MaxBackupIndex" value="5" />
          <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d{MM-dd-yyyy
hh:mm:ss a}; thread-[%t]; priority-%-5p;  class - %C; method - %M;
message - %m%n"/>
          </layout>    
          <filter class="org.apache.log4j.varia.PriorityMatchFilter">
                 <param name="PriorityToMatch" value="DEBUG" />
                 <param name="AcceptOnMatch" value="true" />
  </filter>
</appender>
<appender name="FILE_APP_INFO"
class="org.apache.log4j.RollingFileAppender">
          <param name="File" value="info.log" />
          <param name="MaxFileSize" value="10000KB" />
          <param name="MaxBackupIndex" value="5" />          
          <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d{MM-dd-yyyy
hh:mm:ss a}; thread-[%t]; priority-%-5p;  class - %C; method - %M;
message - %m%n"/>
          </layout>
          <filter class="org.apache.log4j.varia.PriorityMatchFilter">
                 <param name="PriorityToMatch" value="INFO" />
                 <param name="AcceptOnMatch" value="true" />
  </filter>    
</appender>
<appender name="FILE_APP_ERROR"
class="org.apache.log4j.RollingFileAppender">
          <param name="File" value="error.log" />
          <param name="MaxFileSize" value="10000KB" />
          <param name="MaxBackupIndex" value="5" />
          <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d{MM-dd-yyyy
hh:mm:ss a}; thread-[%t]; priority-%-5p;  class - %C; method - %M;
message - %m%n"/>
          </layout>    
          <filter class="org.apache.log4j.varia.PriorityMatchFilter">
                 <param name="PriorityToMatch" value="ERROR" />
                 <param name="AcceptOnMatch" value="true" />
  </filter>
</appender>
<appender name="CONSOLE_ERR"
class="org.apache.log4j.ConsoleAppender">
          <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="Date/Time: %d,
Severity: %-5p, %m%n"/>
          </layout>    
</appender>
<appender name="FILE_APP_ERR_EVENT_LOG"
class="org.apache.log4j.RollingFileAppender">
   <param name="File" value="errorevent.log" />
   <param name="MaxFileSize" value="10000KB" />
   <param name="MaxBackupIndex" value="5" />                      
   <layout class="org.apache.log4j.PatternLayout">
    <param name="ConversionPattern" value="%d{MM-dd-yyyy hh:mm:ss a};
thread-[%t]; priority-%-5p;  class - %C; method - %M; message -
%m%n"/>
   </layout>    
   <filter class="org.apache.log4j.varia.PriorityMatchFilter">
   <param name="PriorityToMatch" value="ERROR_EVENT" />
   <param name="AcceptOnMatch" value="true" />
    </filter>
</appender>

<category name="package name">
 <priority value="error" />
 <appender-ref ref="CONSOLE_APP" />
    <!--appender-ref ref="FILE_ERR" /-->
</category>



<category name="package name" >
 <priority value="ERROR_EVENT" />
 <appender-ref ref="FILE_APP_ERR_EVENT_LOG" />
</category>


<root>
   <priority value ="DEBUG" />
</root>

</log4j:configuration>


The problem is that the logs of the a.properties are getting logged on
the Tomcat Server Console when run on the Tomcat Server,, And I have
seperate log files for the a.properties and b.xml, some of the logs of
the a.properties are getting logged on to the b.xml's log files and
some of the b.xml's logs are getting logged on to the a.properties log
file... WHICH should not(I mean to say the logs of a.properties should
get logged into the log files of the a.properties and the logs of the
b.xml should get logged onto the b.xml's log files only)...



I will be waiting for ur replies...

Please its very urgent.

Thanx in Advance...
Gutter Rat - 01 Sep 2004 04:18 GMT
> Log4j Issue
> -----------
[quoted text clipped - 152 lines]
>  
> Thanx in Advance...

Whassup?

I haven't seen Log4J used in an XML properties settings before or read
any documentation on it. But here is a sample of a log4j.properties file
used in one of my web apps:

# log4j.properties
#---------------------------------------------------------------
# Everything not explicitly stated will output ONLY warn & above (warn,
error, fatal)
#---------------------------------------------------------------
log4j.rootCategory=DEBUG, console, roll-error

#----------- my web
log4j.category.com.app.portal=DEBUG, roll-debug

#---------------------------------------------------------------
# Console Appender
#---------------------------------------------------------------
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.Threshold=INFO
log4j.appender.console.layout=org.apache.log4j.PatternLayout
# Pattern to output the caller's file name and line number.
#log4j.appender.console.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %
m%n
log4j.appender.console.layout.ConversionPattern=%d{MM/dd/yy HH:mm:ss,SSS}
%-5p %l - (%F:%L) %m%n

#---------------------------------------------------------------
# Rolling File Appender -- for errors
#---------------------------------------------------------------
log4j.appender.roll-error=org.apache.log4j.RollingFileAppender
log4j.appender.roll-error.File=C:/Tomcat
5.0.19/webapps/Portal/Logs/error.log
log4j.appender.roll-error.Threshold=WARN
log4j.appender.roll-error.MaxFileSize=1500KB
log4j.appender.roll-error.MaxBackupIndex=2
log4j.appender.roll-error.layout=org.apache.log4j.PatternLayout
log4j.appender.roll-error.layout.ConversionPattern=%d{MM/dd/yy
HH:mm:ss,SSS} %-5p %l - %m%n

#---------------------------------------------------------------
# Rolling File Appender - debugging for general
#---------------------------------------------------------------
log4j.appender.roll-debug=org.apache.log4j.RollingFileAppender
log4j.appender.roll-debug.File=C:/Tomcat
5.0.19/webapps/Portal/Logs/debug.log
log4j.appender.roll-debug.Threshold=DEBUG
log4j.appender.roll-debug.MaxFileSize=1000KB
log4j.appender.roll-error.MaxBackupIndex=0
log4j.appender.roll-debug.layout=org.apache.log4j.PatternLayout
log4j.appender.roll-debug.layout.ConversionPattern=%d{MM/dd/yy
HH:mm:ss,SSS} %-5p [%C{1}:%L] %m%n

Please note the following 2 lines that specify where the error and debug
logs are stored, which can be any location or file name that you specify.

log4j.appender.roll-error.File=
log4j.appender.roll-debug.File=

I'm not sure what documentation or who taught you how to use Log4J in the
manner in which you are using it. But hope this helps.

Later


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.