You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Marco Tedone <m_...@hotmail.com> on 2003/03/08 09:58:20 UTC

FW: Commons Logging Configuration


-----Original Message-----
From: ashokd [mailto:ashokd@visualsoft-tech.com] 
Sent: Friday, March 08, 2002 3:57 AM
To: Marco Tedone
Subject: Re: Commons Logging Configuration


Hi Marco,

Thanks for your help. Their is any documentation on this?
Your mail helps me a lot.

Thanks & Regards,
Ashok.D
----- Original Message -----
From: "Marco Tedone" <m_...@hotmail.com>
To: "'ashokd'" <as...@visualsoft-tech.com>
Sent: Saturday, March 08, 2003 3:35 AM
Subject: RE: Commons Logging Configuration


> Hi, I put a commons-logging.properties file under WEB-INF/classes
directory
> with the following content:
>
>
org.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4jCategory
> Log
>
> Then, you still need to configure the log4j properties file or xml 
> file. Here there is an example of what I've done:
>
> <?xml version="1.0" encoding="UTF-8" ?>
> <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
>
> <log4j:configuration xmlns:log4j='http://jakarta.apache.org/log4j/'>
>
>   <appender name="STDOUT" class="org.apache.log4j.ConsoleAppender">
>     <layout class="org.apache.log4j.PatternLayout">
>       <param name="ConversionPattern" value="[%t] %-5p %c - %m%n"/>
>     </layout>
>   </appender>
>
>   <appender name="A2" class="org.apache.log4j.FileAppender">
>       <param name="File" value="${log4j.log.dir}/A2.log"/>
>         <layout class="org.apache.log4j.PatternLayout">
>   <param name="ConversionPattern" value="%r %p [%t] %c - %m%n"/>
>         </layout>
>   </appender>
>
>   <appender name="ROLLING" class="org.apache.log4j.RollingFileAppender">
>     <param name="File" value="${log4j.log.dir}/xmlop-logs.log"/>
>     <param name="MaxFileSize" value="100KB"/>
>     <param name="MaxBackupIndex" value="2"/>
>     <param name="DatePattern" value="'.'yyyy-MM-dd-a"/>
>     <layout class="org.apache.log4j.PatternLayout">
>       <param name="ConversionPattern" value="%p %m%n"/>
>     </layout>
>   </appender>
>
>   <!-- A time/date based rolling appender -->
> <appender name="DAILY-ROLL" 
> class="org.jboss.logging.appender.DailyRollingFileAppender">
> <param name="File" value="${log4j.log.dir}/xmlop-logs.log"/>
> <param name="Append" value="true"/>
> <param name="Threshold" value="DEBUG"/>
>
> <!-- Rollover at midnight each day -->
> <param name="DatePattern" value="'.'yyyy-MM-dd"/>
>
> <!-- Rollover at the top of each hour
> <param name="DatePattern" value="'.'yyyy-MM-dd-HH"/>
> -->
>
> <layout class="org.apache.log4j.PatternLayout">
> <!-- The default pattern: Date Priority [Category] Message\n <param 
> name="ConversionPattern" value="%d %-5p [%c] %m%n"/>
> -->
>
> <!-- The full pattern: Date MS Priority [Category] (Thread:NDC) 
> Message\n
> -->
> <param name="ConversionPattern" value="%d %-5r %-5p [%c] (%t:%x) 
> %m%n"/>
>
> </layout>
> </appender>
>
>
>
>   <root>
>     <!-- The following level element is not necessary since the -->
>     <!-- level of the root level is set to DEBUG by default.    -->
>     <level value ="INFO"/>
>     <appender-ref ref="ROLLING" />
>   </root>
>
> </log4j:configuration>
>
>
>
> I then have a Service Factory(configured as a Struts PlugIn) to which 
> I
ask
> any service I need: in the case of the logger I created the following
> method:
>
> /**
> * Returns an instance of the commons-logging Log logger
> * @return An instance of the commons logger
> */
> public Log getLoggerService(Object client) {
>
> String prefix = 
> getActionServlet().getServletContext().getRealPath("/");
> //The Logger Configuration Location is passed as a PlugIn property in 
> the struts-config.xml file String file = getLoggerConfigLocation();
>
>
> // since we have not yet set up our log4j environment,
> // we will use System.err for some basic information 
> System.out.println("Using properties file: " + prefix + file);
>
>
> // Set system property to set the destination dir for log files
> System.setProperty("log4j.log.dir", prefix);
>
> if(file== null || file.length() == 0){
> // || !(new File(file)).isFile()){
>
> System.err.println(
> "ERROR: Cannot read the configuration file. " +
> "Please check the path of the config init param in
> web.xml");
> }
> else {
> DOMConfigurator.configure(prefix+file);
> }
>
> return LogFactory.getLog(client.getClass());
> }
>
> Hope it will help
>
> > -----Original Message-----
> > From: ashokd [mailto:ashokd@visualsoft-tech.com]
> > Sent: Thursday, March 07, 2002 6:45 AM
> > To: Struts Users Mailing List
> > Subject: Commons Logging Configuration
> >
> >
> > Hi,
> >
> >     I have a question regarding configuration of  Commons Logging 
> > (for Log4j). Where I need to place this configuration property file. 
> > Their is any user guide to configure commons Logging.
> >
> > Thanks & Regards,
> > Ashok.D
> >
> >
>

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