You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by kondal rao <na...@gmail.com> on 2009/02/26 09:33:43 UTC

Problem while loading the log4j.xml in to the classpath

Hi,

      I am using the log4j for logging in my webapplication.I am keeping the
log4j.xml file outside of my web application(generally we will keep under
WEB-INF/classes).My problem is my application is not loading  the
log4j.xml.I am using the following code while my context is initializing to
load the log4j.xml in to my class path.
System.setProperty("log4j.configuration",
"C:/samplel/log4j.xml"); System.setProperty("log4j.configuratorClass",
"com.foo.DOMConfigurator"); But it is not working.I am using tomcat5.0.


Any Ideas Please.



-- 
    Regards
    Kondalarao Navuluri

Multiple ErrorHandlers

Posted by Chandresh Turakhia <ch...@bhartitelesoft.com>.
Dear all :

How do u configure "Multiple Error Handlers" ..
I write to SocketAppender ( NewSocketappender ) but if it fails I want it to go to multiple Files based on loggers.
This code does not give error while loading but does not write to fallback_* files as backup.

I understand log4j schema requires only one error handler ; how do make a change in log4j.xml

Thanks in advance
Chand


<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">

<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">


  <appender name="A1"  class="org.apache.log4j.net.NewSocketAppender">

          <errorHandler class="org.apache.log4j.varia.FallbackErrorHandler">
                 <root-ref/>
                         <appender-ref ref="FALLBACK"/>
          </errorHandler>

          <errorHandler class="org.apache.log4j.varia.FallbackErrorHandler">
                 <logger-ref ref="com.mmoney.utilities.Database"/>
                         <appender-ref ref="fallback_database"/>
          </errorHandler>

          <errorHandler class="org.apache.log4j.varia.FallbackErrorHandler">
                 <logger-ref ref="com.mmoney.common.ChannelGatewayLogs"/>
                         <appender-ref ref="fallback_ChannelGatewayLogs"/>
          </errorHandler>

          <errorHandler class="org.apache.log4j.varia.FallbackErrorHandler">
                 <logger-ref ref="com.mmoney.common.BalanceLog"/>
                         <appender-ref ref="fallback_BalanceLog"/>
          </errorHandler>

          <errorHandler class="org.apache.log4j.varia.FallbackErrorHandler">
                <logger-ref ref="com.mmoney.sms.ConnectURL"/>
                         <appender-ref ref="fallback_ConnectURL"/>
        </errorHandler>

        <param name="remoteHost"    value="localhost" />
        <param name="port"          value="8011" />

   </appender>

        <appender name="fallback_database"      class="org.apache.log4j.FileAppender">
                <param name="File" value="fallback-db.log" />
                <layout class="org.apache.log4j.PatternLayout">
                <param name="ConversionPattern"
                        value="[%d{dd/MM/yy hh:mm:ss:sss z}] %5p %c{2}: %m%n" />
                </layout>
        </appender>


        <appender name="fallback_ChannelGatewayLogs"    class="org.apache.log4j.FileAppender">
                <param name="File" value="fallback_cg.log" />
                <layout class="org.apache.log4j.PatternLayout">
                <param name="ConversionPattern"
                        value="[%d{dd/MM/yy hh:mm:ss:sss z}] %5p %c{2}: %m%n" />
                </layout>
        </appender>

        <appender name="fallback_BalanceLog"    class="org.apache.log4j.FileAppender">
                <param name="File" value="fallback_bl.log" />
                <layout class="org.apache.log4j.PatternLayout">
                <param name="ConversionPattern"
                        value="[%d{dd/MM/yy hh:mm:ss:sss z}] %5p %c{2}: %m%n" />
                </layout>
        </appender>

        <appender name="fallback_ConnectURL"    class="org.apache.log4j.FileAppender">
                <param name="File" value="fallback_cu.log" />
                <layout class="org.apache.log4j.PatternLayout">
                <param name="ConversionPattern"
                        value="[%d{dd/MM/yy hh:mm:ss:sss z}] %5p %c{2}: %m%n" />
                </layout>
        </appender>

        <appender name="FALLBACK"       class="org.apache.log4j.FileAppender">
                <param name="File" value="fallback.log" />
                <layout class="org.apache.log4j.PatternLayout">
                <param name="ConversionPattern"
                        value="[%d{dd/MM/yy hh:mm:ss:sss z}] %5p %c{2}: %m%n" />
                </layout>
        </appender>


  <logger name="com.mmoney.utilities.Database" >
      <level value="ERROR"/>
  </logger>

  <logger name="com.mmoney.common.ChannelGatewayLogs" >
      <level value="INFO"/>
  </logger>

  <logger name="com.mmoney.common.BalanceLog" >
      <level value="INFO"/>
  </logger>

  <logger name="com.mmoney.sms.ConnectURL" >
      <level value="INFO"/>
  </logger>



  <root>
        <level value="debug"/>
    <appender-ref ref="A1" />
  </root>
</log4j:configuration>

This e-mail and all material transmitted with it are for the use of the intended recipient(s) ONLY and contains confidential and/or privileged information. If you are not the intended recipient, please contact the sender by reply e-mail and destroy all copies and the original message. Any unauthorized review, use, disclosure, dissemination, forwarding, printing or copying of this email or any action taken pursuant to the contents of the present e-mail is strictly prohibited and is unlawful.
The recipient acknowledges that Bharti Telesoft Limited or its management or directors, are unable to exercise control or ensure the integrity over /of the contents of the information contained in e-mail. Any views expressed herein are those of the individual sender only and no binding nature of the contents shall be implied or assumed unless the sender does so expressly with due authority of Bharti Telesoft Limited. E-mail and any contents transmitted with it are prone to viruses and related defects despite all efforts to avoid such by Bharti Telesoft Limited.

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


Re: Problem while loading the log4j.xml in to the classpath

Posted by Jacob Kjome <ho...@visi.com>.
You're spawning a new JVM instance from your code running under Tomcat?  
That's, well...., odd.  In any case, try adding -Dlog4j.debug=true to see what 
is going on.

Jake


On Fri, 27 Feb 2009 09:59:47 +0530
  kondal rao <na...@gmail.com> wrote:
> Hi Jake,
>              I am not using any custom DOMConfigurator class.I am running
> my code on the tomcat so I am using code level to set this command line
> variable.I am using this code in my Listener class .
> String cmd="java -Dlog4j.configuration=file:///C:/kondal/log4j.xml
> in.co.netsol.niab.portal.actions.MyContextListener";
>            //String cmd="cmd.exe /c set";
>            Runtime runtime = Runtime.getRuntime();
>            Process process = null;
>            System.out.println("command is "+cmd);
>            process = runtime.exec(cmd);
> 
> Even if I set that variable in environment Variables manually then also it
> is not working.I will try with Custom DOMConfigurator .
> 
> Thanks
> kondal
> 
> On Thu, Feb 26, 2009 at 10:59 PM, Jacob Kjome <ho...@visi.com> wrote:
> 
>> On Thu, 26 Feb 2009 21:00:48 +0530
>>  kondal rao <na...@gmail.com> wrote:
>>
>>> Thanks for your reply.I am using sample only.just a spelling mistake.
>>>
>>> I tried this (file:///C:/samplel/log4j.xml) but it is not working.Any
>>> ideas
>>> please.
>>>
>>
>> You just made the same spelling mistake again.
>>
>> Also, one critical thing I forgot to mention is that you really need to set
>> this as a -D parameter on your java command line.  Trying to set it via code
>> is pointless because auto-configuration will have already run in the
>> LogManager static block.  So...
>>
>> java -Dlog4j.configuration=file:///C:/sample/log4j.xml MyMainClass
>>
>>
>> BTW, do you use a custom DOMConfigurator; "com.foo.DOMConfigurator"?   I'm
>> guessing you don't actually use a custom DOMConfigurator.  If not, I don't
>> think you have to set the log4j.configuratorClass property.  I think the
>> auto-configuration code will look at the suffix (.xml -vs- .properties) to
>> determine the configurator type.  Haven't looked at that code for a long
>> time, so I'm not 100% sure about this.  Testing will bear this out.  Try it
>> without setting the log4j.configuratorClass property.  If configuration
>> loads fine, you'll know it's not needed.
>>
>>
>> Jake
>>
>>
>>
>>>
>>>
>>> Thanks
>>> kondal
>>>
>>> On Thu, Feb 26, 2009 at 8:42 PM, Jacob Kjome <ho...@visi.com> wrote:
>>>
>>>  On Thu, 26 Feb 2009 14:03:43 +0530
>>>>  kondal rao <na...@gmail.com> wrote:
>>>>
>>>>  Hi,
>>>>>
>>>>>    I am using the log4j for logging in my webapplication.I am keeping
>>>>> the
>>>>> log4j.xml file outside of my web application(generally we will keep
>>>>> under
>>>>> WEB-INF/classes).My problem is my application is not loading  the
>>>>> log4j.xml.I am using the following code while my context is initializing
>>>>> to
>>>>> load the log4j.xml in to my class path.
>>>>> System.setProperty("log4j.configuration",
>>>>> "C:/samplel/log4j.xml"); System.setProperty("log4j.configuratorClass",
>>>>> "com.foo.DOMConfigurator"); But it is not working.I am using tomcat5.0.
>>>>>
>>>>>
>>>> Try using a valid URL to your config file...
>>>>
>>>> file:///C:/samplel/log4j.xml
>>>>
>>>> BTW, is your directory really named "samplel"?  Or is it supposed to be
>>>> "sample"?
>>>>
>>>>
>>>> Jake
>>>>
>>>>
>>>>
>>>>> Any Ideas Please.
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>>  Regards
>>>>>  Kondalarao Navuluri
>>>>>
>>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
>>>> For additional commands, e-mail: log4j-user-help@logging.apache.org
>>>>
>>>>
>>>>
>>>
>>> --
>>>   Regards
>>>   Kondalarao Navuluri
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
>> For additional commands, e-mail: log4j-user-help@logging.apache.org
>>
>>
> 
> 
> -- 
>    Regards
>    Kondalarao Navuluri


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


Re: Problem while loading the log4j.xml in to the classpath

Posted by kondal rao <na...@gmail.com>.
Hi Jake,
              I am not using any custom DOMConfigurator class.I am running
my code on the tomcat so I am using code level to set this command line
variable.I am using this code in my Listener class .
String cmd="java -Dlog4j.configuration=file:///C:/kondal/log4j.xml
in.co.netsol.niab.portal.actions.MyContextListener";
            //String cmd="cmd.exe /c set";
            Runtime runtime = Runtime.getRuntime();
            Process process = null;
            System.out.println("command is "+cmd);
            process = runtime.exec(cmd);

Even if I set that variable in environment Variables manually then also it
is not working.I will try with Custom DOMConfigurator .

Thanks
kondal

On Thu, Feb 26, 2009 at 10:59 PM, Jacob Kjome <ho...@visi.com> wrote:

> On Thu, 26 Feb 2009 21:00:48 +0530
>  kondal rao <na...@gmail.com> wrote:
>
>> Thanks for your reply.I am using sample only.just a spelling mistake.
>>
>> I tried this (file:///C:/samplel/log4j.xml) but it is not working.Any
>> ideas
>> please.
>>
>
> You just made the same spelling mistake again.
>
> Also, one critical thing I forgot to mention is that you really need to set
> this as a -D parameter on your java command line.  Trying to set it via code
> is pointless because auto-configuration will have already run in the
> LogManager static block.  So...
>
> java -Dlog4j.configuration=file:///C:/sample/log4j.xml MyMainClass
>
>
> BTW, do you use a custom DOMConfigurator; "com.foo.DOMConfigurator"?   I'm
> guessing you don't actually use a custom DOMConfigurator.  If not, I don't
> think you have to set the log4j.configuratorClass property.  I think the
> auto-configuration code will look at the suffix (.xml -vs- .properties) to
> determine the configurator type.  Haven't looked at that code for a long
> time, so I'm not 100% sure about this.  Testing will bear this out.  Try it
> without setting the log4j.configuratorClass property.  If configuration
> loads fine, you'll know it's not needed.
>
>
> Jake
>
>
>
>>
>>
>> Thanks
>> kondal
>>
>> On Thu, Feb 26, 2009 at 8:42 PM, Jacob Kjome <ho...@visi.com> wrote:
>>
>>  On Thu, 26 Feb 2009 14:03:43 +0530
>>>  kondal rao <na...@gmail.com> wrote:
>>>
>>>  Hi,
>>>>
>>>>    I am using the log4j for logging in my webapplication.I am keeping
>>>> the
>>>> log4j.xml file outside of my web application(generally we will keep
>>>> under
>>>> WEB-INF/classes).My problem is my application is not loading  the
>>>> log4j.xml.I am using the following code while my context is initializing
>>>> to
>>>> load the log4j.xml in to my class path.
>>>> System.setProperty("log4j.configuration",
>>>> "C:/samplel/log4j.xml"); System.setProperty("log4j.configuratorClass",
>>>> "com.foo.DOMConfigurator"); But it is not working.I am using tomcat5.0.
>>>>
>>>>
>>> Try using a valid URL to your config file...
>>>
>>> file:///C:/samplel/log4j.xml
>>>
>>> BTW, is your directory really named "samplel"?  Or is it supposed to be
>>> "sample"?
>>>
>>>
>>> Jake
>>>
>>>
>>>
>>>> Any Ideas Please.
>>>>
>>>>
>>>>
>>>> --
>>>>  Regards
>>>>  Kondalarao Navuluri
>>>>
>>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
>>> For additional commands, e-mail: log4j-user-help@logging.apache.org
>>>
>>>
>>>
>>
>> --
>>   Regards
>>   Kondalarao Navuluri
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>


-- 
    Regards
    Kondalarao Navuluri

Re: Problem while loading the log4j.xml in to the classpath

Posted by Jacob Kjome <ho...@visi.com>.
On Thu, 26 Feb 2009 21:00:48 +0530
  kondal rao <na...@gmail.com> wrote:
> Thanks for your reply.I am using sample only.just a spelling mistake.
> 
> I tried this (file:///C:/samplel/log4j.xml) but it is not working.Any ideas
> please.

You just made the same spelling mistake again.

Also, one critical thing I forgot to mention is that you really need to set 
this as a -D parameter on your java command line.  Trying to set it via code 
is pointless because auto-configuration will have already run in the 
LogManager static block.  So...

java -Dlog4j.configuration=file:///C:/sample/log4j.xml MyMainClass


BTW, do you use a custom DOMConfigurator; "com.foo.DOMConfigurator"?   I'm 
guessing you don't actually use a custom DOMConfigurator.  If not, I don't 
think you have to set the log4j.configuratorClass property.  I think the 
auto-configuration code will look at the suffix (.xml -vs- .properties) to 
determine the configurator type.  Haven't looked at that code for a long time, 
so I'm not 100% sure about this.  Testing will bear this out.  Try it without 
setting the log4j.configuratorClass property.  If configuration loads fine, 
you'll know it's not needed.


Jake

> 
> 
> 
> Thanks
> kondal
> 
> On Thu, Feb 26, 2009 at 8:42 PM, Jacob Kjome <ho...@visi.com> wrote:
> 
>> On Thu, 26 Feb 2009 14:03:43 +0530
>>  kondal rao <na...@gmail.com> wrote:
>>
>>> Hi,
>>>
>>>     I am using the log4j for logging in my webapplication.I am keeping the
>>> log4j.xml file outside of my web application(generally we will keep under
>>> WEB-INF/classes).My problem is my application is not loading  the
>>> log4j.xml.I am using the following code while my context is initializing
>>> to
>>> load the log4j.xml in to my class path.
>>> System.setProperty("log4j.configuration",
>>> "C:/samplel/log4j.xml"); System.setProperty("log4j.configuratorClass",
>>> "com.foo.DOMConfigurator"); But it is not working.I am using tomcat5.0.
>>>
>>
>> Try using a valid URL to your config file...
>>
>> file:///C:/samplel/log4j.xml
>>
>> BTW, is your directory really named "samplel"?  Or is it supposed to be
>> "sample"?
>>
>>
>> Jake
>>
>>
>>>
>>> Any Ideas Please.
>>>
>>>
>>>
>>> --
>>>   Regards
>>>   Kondalarao Navuluri
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
>> For additional commands, e-mail: log4j-user-help@logging.apache.org
>>
>>
> 
> 
> -- 
>    Regards
>    Kondalarao Navuluri


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


Re: Problem while loading the log4j.xml in to the classpath

Posted by kondal rao <na...@gmail.com>.
Thanks for your reply.I am using sample only.just a spelling mistake.

I tried this (file:///C:/samplel/log4j.xml) but it is not working.Any ideas
please.



Thanks
kondal

On Thu, Feb 26, 2009 at 8:42 PM, Jacob Kjome <ho...@visi.com> wrote:

> On Thu, 26 Feb 2009 14:03:43 +0530
>  kondal rao <na...@gmail.com> wrote:
>
>> Hi,
>>
>>     I am using the log4j for logging in my webapplication.I am keeping the
>> log4j.xml file outside of my web application(generally we will keep under
>> WEB-INF/classes).My problem is my application is not loading  the
>> log4j.xml.I am using the following code while my context is initializing
>> to
>> load the log4j.xml in to my class path.
>> System.setProperty("log4j.configuration",
>> "C:/samplel/log4j.xml"); System.setProperty("log4j.configuratorClass",
>> "com.foo.DOMConfigurator"); But it is not working.I am using tomcat5.0.
>>
>
> Try using a valid URL to your config file...
>
> file:///C:/samplel/log4j.xml
>
> BTW, is your directory really named "samplel"?  Or is it supposed to be
> "sample"?
>
>
> Jake
>
>
>>
>> Any Ideas Please.
>>
>>
>>
>> --
>>   Regards
>>   Kondalarao Navuluri
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>


-- 
    Regards
    Kondalarao Navuluri

Re: Problem while loading the log4j.xml in to the classpath

Posted by Jacob Kjome <ho...@visi.com>.
On Thu, 26 Feb 2009 14:03:43 +0530
  kondal rao <na...@gmail.com> wrote:
> Hi,
> 
>      I am using the log4j for logging in my webapplication.I am keeping the
> log4j.xml file outside of my web application(generally we will keep under
> WEB-INF/classes).My problem is my application is not loading  the
> log4j.xml.I am using the following code while my context is initializing to
> load the log4j.xml in to my class path.
> System.setProperty("log4j.configuration",
> "C:/samplel/log4j.xml"); System.setProperty("log4j.configuratorClass",
> "com.foo.DOMConfigurator"); But it is not working.I am using tomcat5.0.

Try using a valid URL to your config file...

file:///C:/samplel/log4j.xml

BTW, is your directory really named "samplel"?  Or is it supposed to be 
"sample"?


Jake

> 
> 
> Any Ideas Please.
> 
> 
> 
> -- 
>    Regards
>    Kondalarao Navuluri


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