logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sanjay Gupta \(sanjaygu\)" <sanja...@cisco.com>
Subject How to use categoryFactory element in the properties file?
Date Sat, 12 Jul 2003 00:21:54 GMT
I have extended Logger and LoggerFactory so that I can pass few params
such as hostname.

---------Extended LoggerFactory-------------
	public NtLoggerFactory(String appId, String hostName) {
	  this.appId = appId;
	  this.hostName = hostName;
	}

	 public Logger makeNewLoggerInstance(String name) {
	   return new NtLogger(name, this.appId, this.hostName);
	 }
-----------------------------------------------

My program works fine when I initialize and configure the logger from
the program but when I try to use DOMConfigurator using log4j.xml I am
lost. How so I specify LoggerFactory/CategoryFactory and the params in
the log4j.xml file? 

Here is the program that works without a Configurator/xml file -
-----------------
		Logger root = Logger.getRootLogger();
		NtLoggerFactory factory = new
NtLoggerFactory("LogWriterApp", "LocalMachine");
		Layout layout = new NtPatternLayout("%p <%a> =>%h=< [%t]
%c (%F:%L:%M) - %m%n");
		root.addAppender(new ConsoleAppender(layout,
ConsoleAppender.SYSTEM_OUT));
  	      NtLogger logger = (NtLogger)
NtLogger.getLogger("LogWriter", factory); 
     	      logger.info("Hello info ");

---------------

This is what I came up with log4j.xml and code that doesn't work------

-----------log4j.xml----
<log4j:configuration xmlns:log4j='http://jakarta.apache.org/log4j/'>
        <appender name="RBERR"
class="org.apache.log4j.RollingFileAppender">
           <param name="File" value="D:\\Logwriter\\test.log" />
           <param name="Threshold" value="DEBUG" />
           <param name="MaxFileSize" value="1024KB" />
           <param name="MaxBackupIndex" value="10" />
           <layout class="com.sanjay.log4j.NtPatternLayout">
              <param name="ConversionPattern" value="%p [%a] =)%h=( [%t]
%c (%F:%L:%M) - %m%n" />
           </layout>
        </appender>
        <logger name="LogWriter">
           <level value="debug"/>

           <appender-ref ref="RBERR" />

        </logger> 
        <categoryFactory
class="com.cisco.nettools.log4j.NtLoggerFactory">
          <param name="appId" value="MYAPPID" />
          <param name="hostName" value="LOCAL_MACHINE" />
        </categoryFactory>
</log4j:configuration>  
---------------------

And java code is ---
		  DOMConfigurator.configure(args[0]);
		  NtLogger logger = (NtLogger)
NtLogger.getLogger("LogWriter"); 
		  logger.info("Hello info ");

I get the error - 
log4j:WARN No such property [appId] in
com.cisco.nettools.log4j.NtLoggerFactory.
log4j:WARN No such property [hostName] in
com.cisco.nettools.log4j.NtLoggerFactory.
log4j:WARN No such property [appId] in
com.cisco.nettools.log4j.NtLoggerFactory.
log4j:WARN No such property [hostName] in
com.cisco.nettools.log4j.NtLoggerFactory.
java.lang.ClassCastException
	at com.sanjay.log4j.Log4jTest.main(Log4jTest.java:53)
Exception in thread "main" 
              


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org


Mime
View raw message