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 Sarvananda <na...@satyam.com> on 2007/07/26 12:52:27 UTC

level based logging into seperate files

Dear all,

I have a simple question and I have no solution. Did a lot of google and
tried too many things. I am not going where I want to. My only requirement
is : I need to be able to use a logger object and append different levels of
logs into different files (ofcourse the logs should have the classname, time
and the error)(like Warn messages go to warn_log error messages go to
error_log) .  I am completely stuck with this simple thing... may be I just
have too much on my mind.

I would appreciate if someone could help me with this.

Thanks in advance for your time

Regards,


-- 
View this message in context: http://www.nabble.com/level-based-logging-into-seperate-files-tf4150902.html#a11808248
Sent from the Log4j - Users mailing list archive at Nabble.com.


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


Re: level based logging into seperate files

Posted by Sarvananda <na...@gmail.com>.
no problem
the complete code is at
http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=1&t=018267
check the last post. 

cheers


thanks for your reply sarvananda, please send your code and small
configuration details file if possible.
thanks,
Srinivas.A
email:srinivas.arakala@gmail.com

Sarvananda wrote:
> 
> 
> 
> Srinivas.A wrote:
>> 
>> Hi sarvananda,
>> am also facing same problem. if you got solution let me.I able to log
>> dubug logs and above int one file, error and above into another file.But
>> i unable to log only debug logs in to one file and only error logs into
>> anotherfile.I would really appreciate if one help with this.you can mail
>> me to srinivas.arakala@gmail.com .
>> 
>> Hi, 
>> I Didnt really find a solution to this issue, cos this involved using
>> filters in log4j and the only way I could use them was with a
>> configuration file built on XML. 
>> I made a seperate way and implemented the same code myself. Some may call
>> it reinventing the wheel, but there are times when you dont have time to
>> understand a lot of things but have just about time enough to make your
>> own way. Let me know if you want my code, I will have no problem giving
>> it to you. 
>> It will make entries in a file, and after it reaches a specific size, it
>> will make another file and rename it with current time stamp. I had used
>> log4j AND my solution, so I could write atleast into two different files.
>> 
>> cheers...
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/level-based-logging-into-seperate-files-tf4150902.html#a13231644
Sent from the Log4j - Users mailing list archive at Nabble.com.


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


Re: level based logging into seperate files

Posted by "Srinivas.A" <sr...@gmail.com>.
thanks for your reply sarvananda, please send your code and small
configuration details file if possible.
thanks,
Srinivas.A
email:srinivas.arakala@gmail.com



Srinivas.A wrote:
> 
> Hi sarvananda,
> am also facing same problem. if you got solution let me.I able to log
> dubug logs and above int one file, error and above into another file.But i
> unable to log only debug logs in to one file and only error logs into
> anotherfile.I would really appreciate if one help with this.you can mail
> me to srinivas.arakala@gmail.com .
> 
> Hi, 
> I Didnt really find a solution to this issue, cos this involved using
> filters in log4j and the only way I could use them was with a
> configuration file built on XML. 
> I made a seperate way and implemented the same code myself. Some may call
> it reinventing the wheel, but there are times when you dont have time to
> understand a lot of things but have just about time enough to make your
> own way. Let me know if you want my code, I will have no problem giving it
> to you. 
> It will make entries in a file, and after it reaches a specific size, it
> will make another file and rename it with current time stamp. I had used
> log4j AND my solution, so I could write atleast into two different files.
> 
> cheers...
> 

-- 
View this message in context: http://www.nabble.com/level-based-logging-into-seperate-files-tf4150902.html#a13231566
Sent from the Log4j - Users mailing list archive at Nabble.com.


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


Re: level based logging into seperate files

Posted by Sarvananda <na...@gmail.com>.


Hi sarvananda,
am also facing same problem. if you got solution let me.I able to log dubug
logs and above int one file, error and above into another file.But i unable
to log only debug logs in to one file and only error logs into anotherfile.I
would really appreciate if one help with this.you can mail me to
srinivas.arakala@gmail.com .

Hi, 
I Didnt really find a solution to this issue, cos this involved using
filters in log4j and the only way I could use them was with a configuration
file built on XML. 
I made a seperate way and implemented the same code myself. Some may call it
reinventing the wheel, but there are times when you dont have time to
understand a lot of things but have just about time enough to make your own
way. Let me know if you want my code, I will have no problem giving it to
you. 
It will make entries in a file, and after it reaches a specific size, it
will make another file and rename it with current time stamp. I had used
log4j AND my solution, so I could write atleast into two different files.

cheers...
-- 
View this message in context: http://www.nabble.com/level-based-logging-into-seperate-files-tf4150902.html#a13231174
Sent from the Log4j - Users mailing list archive at Nabble.com.


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


Re: level based logging into seperate files

Posted by "Srinivas.A" <sr...@gmail.com>.
Hi sarvananda,
am also facing same problem. if you got solution let me.I able to log dubug
logs and above int one file, error and above into another file.But i unable
to log only debug logs in to one file and only error logs into anotherfile.I
would really appreciate if one help with this.you can mail me to
srinivas.arakala@gmail.com .

thanks,
Srinivas.A
emailid:srinivas.arakala@gmail.com


Sarvananda wrote:
> 
> right. 
> with the fair amount of noob knowledge I have in Log4j, I ll do some
> google and R&D and post how I did this. Mean while if someone feels they
> could give me some other pointers regarding this issue... Id be grateful
> 
> thanks,
> 
> 
> James Stauffer wrote:
>> 
>> Just create one appender per level and use a LevelFilter to get only
>> the correct level.  You may find that doing something slightly
>> different is more useful.  Have each appender have a certain level and
>> above so that DebugAppender has all messages, InfoAppender has
>> everything but DEBUG, etc.  I find that when I look through the DEBUG
>> logs I want to see all higher logs also.
>> 
>> On 7/26/07, Sarvananda <na...@satyam.com> wrote:
>>>
>>> Dear all,
>>>
>>> I have a simple question and I have no solution. Did a lot of google and
>>> tried too many things. I am not going where I want to. My only
>>> requirement
>>> is : I need to be able to use a logger object and append different
>>> levels of
>>> logs into different files (ofcourse the logs should have the classname,
>>> time
>>> and the error)(like Warn messages go to warn_log error messages go to
>>> error_log) .  I am completely stuck with this simple thing... may be I
>>> just
>>> have too much on my mind.
>>>
>>> I would appreciate if someone could help me with this.
>>>
>>> Thanks in advance for your time
>>>
>>> Regards,
>>>
>>>
>>> --
>>> View this message in context:
>>> http://www.nabble.com/level-based-logging-into-seperate-files-tf4150902.html#a11808248
>>> Sent from the Log4j - Users mailing list archive at Nabble.com.
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
>>> For additional commands, e-mail: log4j-user-help@logging.apache.org
>>>
>>>
>> 
>> 
>> -- 
>> James Stauffer        http://www.geocities.com/stauffer_james/
>> Are you good? Take the test at http://www.livingwaters.com/good/
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
>> For additional commands, e-mail: log4j-user-help@logging.apache.org
>> 
>> 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/level-based-logging-into-seperate-files-tf4150902.html#a13230508
Sent from the Log4j - Users mailing list archive at Nabble.com.


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


Re: level based logging into seperate files

Posted by Sarvananda <na...@gmail.com>.
right. 
with the fair amount of noob knowledge I have in Log4j, I ll do some google
and R&D and post how I did this. Mean while if someone feels they could give
me some other pointers regarding this issue... Id be grateful

thanks,


James Stauffer wrote:
> 
> Just create one appender per level and use a LevelFilter to get only
> the correct level.  You may find that doing something slightly
> different is more useful.  Have each appender have a certain level and
> above so that DebugAppender has all messages, InfoAppender has
> everything but DEBUG, etc.  I find that when I look through the DEBUG
> logs I want to see all higher logs also.
> 
> On 7/26/07, Sarvananda <na...@satyam.com> wrote:
>>
>> Dear all,
>>
>> I have a simple question and I have no solution. Did a lot of google and
>> tried too many things. I am not going where I want to. My only
>> requirement
>> is : I need to be able to use a logger object and append different levels
>> of
>> logs into different files (ofcourse the logs should have the classname,
>> time
>> and the error)(like Warn messages go to warn_log error messages go to
>> error_log) .  I am completely stuck with this simple thing... may be I
>> just
>> have too much on my mind.
>>
>> I would appreciate if someone could help me with this.
>>
>> Thanks in advance for your time
>>
>> Regards,
>>
>>
>> --
>> View this message in context:
>> http://www.nabble.com/level-based-logging-into-seperate-files-tf4150902.html#a11808248
>> Sent from the Log4j - Users mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
>> For additional commands, e-mail: log4j-user-help@logging.apache.org
>>
>>
> 
> 
> -- 
> James Stauffer        http://www.geocities.com/stauffer_james/
> Are you good? Take the test at http://www.livingwaters.com/good/
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/level-based-logging-into-seperate-files-tf4150902.html#a11833767
Sent from the Log4j - Users mailing list archive at Nabble.com.


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


Re: level based logging into seperate files

Posted by James Stauffer <st...@gmail.com>.
Just create one appender per level and use a LevelFilter to get only
the correct level.  You may find that doing something slightly
different is more useful.  Have each appender have a certain level and
above so that DebugAppender has all messages, InfoAppender has
everything but DEBUG, etc.  I find that when I look through the DEBUG
logs I want to see all higher logs also.

On 7/26/07, Sarvananda <na...@satyam.com> wrote:
>
> Dear all,
>
> I have a simple question and I have no solution. Did a lot of google and
> tried too many things. I am not going where I want to. My only requirement
> is : I need to be able to use a logger object and append different levels of
> logs into different files (ofcourse the logs should have the classname, time
> and the error)(like Warn messages go to warn_log error messages go to
> error_log) .  I am completely stuck with this simple thing... may be I just
> have too much on my mind.
>
> I would appreciate if someone could help me with this.
>
> Thanks in advance for your time
>
> Regards,
>
>
> --
> View this message in context: http://www.nabble.com/level-based-logging-into-seperate-files-tf4150902.html#a11808248
> Sent from the Log4j - Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>


-- 
James Stauffer        http://www.geocities.com/stauffer_james/
Are you good? Take the test at http://www.livingwaters.com/good/

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


Re: level based logging into seperate files

Posted by Sarvananda <na...@gmail.com>.
Thanks a ton James. I will try and use this and build on this.

thanks again
-- 
View this message in context: http://www.nabble.com/level-based-logging-into-seperate-files-tf4150902.html#a11961817
Sent from the Log4j - Users mailing list archive at Nabble.com.


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


Re: level based logging into seperate files

Posted by James Stauffer <st...@gmail.com>.
Here are appenders for DEBUG, INFO, WARN, and ERROR:

  <appender name="DebugApp" class="org.apache.log4j.DailyRollingFileAppender">
    <param name="File" value="${catalina.base}/logs/Debug.txt" />
    <param name="DatePattern" value="'.'yyyy-MM-dd-HH" />
    <layout class="org.apache.log4j.PatternLayout">
      <param name="ConversionPattern" value="%p %d{mm:ss.SSS}    %c
      %m%n"  />
    </layout>
  </appender>

  <appender name="OutputApp" class="org.apache.log4j.DailyRollingFileAppender">
    <param name="Threshold" value="info"/>
    <param name="File" value="${catalina.base}/logs/Output.txt" />
    <param name="DatePattern" value="'.'yyyy-MM-dd-HH" />
    <layout class="org.apache.log4j.PatternLayout">
      <param name="ConversionPattern" value="%p %d{mm:ss.SSS}    %c
      %m%n"  />
    </layout>
  </appender>

  <appender name="WarnApp" class="org.apache.log4j.DailyRollingFileAppender">
    <param name="Threshold" value="warn"/>
    <param name="File" value="${catalina.base}/logs/Warn.txt" />
    <param name="DatePattern" value="'.'yyyy-MM-dd-HH" />
    <layout class="org.apache.log4j.PatternLayout">
      <param name="ConversionPattern" value="%p %d{mm:ss.SSS} %c on
%t: %m%n"  />
    </layout>
  </appender>

  <appender name="ErrorApp" class="sps.log.log4j.DateFormatFileAppender">
    <param name="Threshold" value="error"/>
    <param name="File"
value="'${catalina.base}/logs/'MMM-dd-EEE'/'HH-mm-ss-S'.log'" />
    <param name="Separate" value="true" />
    <layout class="org.apache.log4j.PatternLayout">
      <param name="ConversionPattern"
        value="%p %d{mm:s.SSS}%n   Location   : %C %M%n   Thread     :
%t%n   Category   : %c%n   Run        : %X{run}%n   entry      :
%X{entry}%n   entryParams: %X{entryParams}%n   Client     :
%X{client}%n   SNAL #     : %X{SNAL_Log}%n   Username   :
%X{username}%n   Occured At : %X{occuredAt}%n   docId      :
%X{docId}%n   senderId   : %X{senderId}%n   receiverId :
%X{receiverId}%n   formId     : %X{formId}%n   evisionDocId:
%X{evisionDocId}%n   engineKey  : %X{engineKey}%n   appKey1    :
%X{appKey1}%n   Query      : %X{SQL-Query} %X{SQL-Values}%n   Nested
Context: %x%n%m%n*******%n"
        />
    </layout>
  </appender>

On 7/31/07, Sarvananda <na...@gmail.com> wrote:
>
>
>
> James Stauffer wrote:
> >
> > I have created one appender per level but each appender gets logs of
> > the given level and above.  Do you want to see an example of that?
> >
>
> Yes pleae. Id be grateful for that.
>
> thanks
>
> --
> View this message in context: http://www.nabble.com/level-based-logging-into-seperate-files-tf4150902.html#a11929271
> Sent from the Log4j - Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>


-- 
James Stauffer        http://www.geocities.com/stauffer_james/
Are you good? Take the test at http://www.livingwaters.com/good/

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


Re: level based logging into seperate files

Posted by Sarvananda <na...@gmail.com>.


James Stauffer wrote:
> 
> I have created one appender per level but each appender gets logs of
> the given level and above.  Do you want to see an example of that?
> 

Yes pleae. Id be grateful for that.

thanks

-- 
View this message in context: http://www.nabble.com/level-based-logging-into-seperate-files-tf4150902.html#a11929271
Sent from the Log4j - Users mailing list archive at Nabble.com.


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


Re: level based logging into seperate files

Posted by James Stauffer <st...@gmail.com>.
I have created one appender per level but each appender gets logs of
the given level and above.  Do you want to see an example of that?

On 7/31/07, Sarvananda <na...@gmail.com> wrote:
>
> Thank you so much for your reply James.
>
>
> James Stauffer wrote:
> >
> > Are you using an un-modified log4j.jar? Open your log4j.jar and verify
> > that org.apache.log4j.PatternLayout exists in it.
> >
>
> Yes it does. I am using version 1.2.14.
> Logging as such works fine (makes me believe that the PatternLayout is
> workin from the properties file)
> if I use a simple properties file and append all levels into one single
> file. Of course,thats not what I want. Since filters are the only way I can
> append into different files, and filters are possible only with an xml file.
> I am using the above, and having problems
> Have you or has anyone tried to do this (seperate levels of logs into
> seperate log files)? If yes please let me know the approach/code for this.
>
> --
> View this message in context: http://www.nabble.com/level-based-logging-into-seperate-files-tf4150902.html#a11918863
> Sent from the Log4j - Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>


-- 
James Stauffer        http://www.geocities.com/stauffer_james/
Are you good? Take the test at http://www.livingwaters.com/good/

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


Re: level based logging into seperate files

Posted by Sarvananda <na...@gmail.com>.
Thank you so much for your reply James.


James Stauffer wrote:
> 
> Are you using an un-modified log4j.jar? Open your log4j.jar and verify
> that org.apache.log4j.PatternLayout exists in it.
> 

Yes it does. I am using version 1.2.14.
Logging as such works fine (makes me believe that the PatternLayout is
workin from the properties file)
if I use a simple properties file and append all levels into one single
file. Of course,thats not what I want. Since filters are the only way I can
append into different files, and filters are possible only with an xml file.
I am using the above, and having problems  
Have you or has anyone tried to do this (seperate levels of logs into
seperate log files)? If yes please let me know the approach/code for this. 

-- 
View this message in context: http://www.nabble.com/level-based-logging-into-seperate-files-tf4150902.html#a11918863
Sent from the Log4j - Users mailing list archive at Nabble.com.


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


Re: level based logging into seperate files

Posted by James Stauffer <st...@gmail.com>.
Are you using an un-modified log4j.jar? Open your log4j.jar and verify
that org.apache.log4j.PatternLayout exists in it.

On 7/30/07, Sarvananda <na...@gmail.com> wrote:
>
> Since after a lot of readin, I figrured that filters can only be used in an
> XML filem I made an XMl file and a java class to test it. Alas, I am still
> getting errors :
> ---------- java ----------
> log4j:ERROR Could not create the Layout. Reported error follows.
> java.lang.ClassNotFoundException: org.apache.log4j.PatternLayout
>         at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
>         at java.security.AccessController.doPrivileged(Native Method)
>         at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
>         at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
>         at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
>         at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
>         at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
>         at java.lang.Class.forName0(Native Method)
>         at java.lang.Class.forName(Class.java:164)
>         at org.apache.log4j.helpers.Loader.loadClass(Loader.java:178)
>         at
> org.apache.log4j.xml.DOMConfigurator.parseLayout(DOMConfigurator.java:455)
>         at


-- 
James Stauffer        http://www.geocities.com/stauffer_james/
Are you good? Take the test at http://www.livingwaters.com/good/

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


Re: level based logging into seperate files

Posted by Sarvananda <na...@gmail.com>.
Dont know why, but the params got missed in the previous post. 
********************
heres the XML configuration:
*********************
<?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 ">
          
    </layout>
  </appender>

  <appender name="DEBUG" class="org.apache.log4j.RollingFileAppender ">
     
     
     
     
    <layout class="org.apache.log4j.PatternLayout ">
          
    </layout>
  </appender>

  <appender name="INFO" class="org.apache.log4j.RollingFileAppender ">
     
     
     
     
    <layout class="org.apache.log4j.PatternLayout ">
          
    </layout>
    <filter class="org.apache.log4j.varia.LevelRangeFilter ">
      
    </filter>
  </appender>

  <appender name="WARN" class="org.apache.log4j.RollingFileAppender ">
     
     
     
     
    <layout class="org.apache.log4j.PatternLayout ">
          
    </layout>
    <filter class="org.apache.log4j.varia.LevelRangeFilter ">
      
    </filter>
  </appender>

  <appender name="ERROR" class="org.apache.log4j.RollingFileAppender ">
     
     
     
     
    <layout class="org.apache.log4j.PatternLayout ">
          
    </layout>
    <filter class="org.apache.log4j.varia.LevelRangeFilter ">
      
    </filter>
  </appender>

  <root>
    <priority value="debug"/>
    <appender-ref ref="STDOUT"/>
      <appender-ref ref="DEBUG"/>
    <appender-ref ref="INFO"/>
    <appender-ref ref="WARN"/>
    <appender-ref ref="ERROR"/>
  </root>

</log4j:configuration>
*******************

Could some body please tell what wrong am I doing here ?

thanks in advance for your time spent



-- 
View this message in context: http://www.nabble.com/level-based-logging-into-seperate-files-tf4150902.html#a11860074
Sent from the Log4j - Users mailing list archive at Nabble.com.


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


Re: level based logging into seperate files

Posted by Sarvananda <na...@gmail.com>.
Dont know why, but the params got missed in the previous post. 
********************
heres the XML configuration:
*********************
<?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 ">
          
    </layout>
  </appender>

  <appender name="DEBUG" class="org.apache.log4j.RollingFileAppender ">
     < param name="File" value="C:\\logs\\app-debug.log" />
     < param name="Append" value="true" />
     < param name="MaxFileSize" value="500KB" />
     < param name="MaxBackupIndex" value="2" />
    <layout class="org.apache.log4j.PatternLayout ">
          
    </layout>
  </appender>

  <appender name="INFO" class="org.apache.log4j.RollingFileAppender ">
     < param name="File" value="C:\\logs\\app-info.log" />
     < param name="Append" value="true" />
     < param name="MaxFileSize" value="500KB" />
     < param name="MaxBackupIndex" value="2" />
    <layout class="org.apache.log4j.PatternLayout ">
          < param name="ConversionPattern" value="%c %d{ISO8601} -- %p --
%m%n" />
    </layout>
    <filter class="org.apache.log4j.varia.LevelRangeFilter ">
      < param name="LevelMin" value="INFO" />
    </filter>
  </appender>

  <appender name="WARN" class="org.apache.log4j.RollingFileAppender ">
     < param name="File" value="C:\\logs\\app-warn.log" />
      < param name="Append" value="true" />
     < param name="MaxFileSize" value="500KB" />
     < param name="MaxBackupIndex" value="2" />
    <layout class="org.apache.log4j.PatternLayout ">
          < param name="ConversionPattern" value="%c %d{ISO8601} -- %p --
%m%n" />
    </layout>
    <filter class="org.apache.log4j.varia.LevelRangeFilter ">
      < param name="LevelMin" value="WARN" />
    </filter>
  </appender>

  <appender name="ERROR" class="org.apache.log4j.RollingFileAppender ">
     < param name="File" value="C:\\logs\\app-error.log" />
     < param name="Append" value="true" />
     < param name="MaxFileSize" value="500KB" />
     < param name="MaxBackupIndex" value="2" />
    <layout class="org.apache.log4j.PatternLayout ">
          < param name="ConversionPattern" value="%c %d{ISO8601} -- %p --
%m%n" />
    </layout>
    <filter class="org.apache.log4j.varia.LevelRangeFilter ">
      < param name="LevelMin" value="ERROR" />
    </filter>
  </appender>

  <root>
    <priority value="debug"/>
    <appender-ref ref="STDOUT"/>
      <appender-ref ref="DEBUG"/>
    <appender-ref ref="INFO"/>
    <appender-ref ref="WARN"/>
    <appender-ref ref="ERROR"/>
  </root>

</log4j:configuration>
*******************

Could some body please tell what wrong am I doing here ?

thanks in advance for your time spent



-- 
View this message in context: http://www.nabble.com/level-based-logging-into-seperate-files-tf4150902.html#a11860074
Sent from the Log4j - Users mailing list archive at Nabble.com.


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


Re: level based logging into seperate files

Posted by Sarvananda <na...@gmail.com>.
Dont know why, but the params got missed in the previous post. 
********************
heres the XML configuration:
*********************
<?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 ">
          
    </layout>
  </appender>

  <appender name="DEBUG" class="org.apache.log4j.RollingFileAppender ">
     < param name="File" value="C:\\logs\\app-debug.log" />
     < param name="Append" value="true" />
     < param name="MaxFileSize" value="500KB" />
     < param name="MaxBackupIndex" value="2" />
    <layout class="org.apache.log4j.PatternLayout ">
          
    </layout>
  </appender>

  <appender name="INFO" class="org.apache.log4j.RollingFileAppender ">
     
     
     
     
    <layout class="org.apache.log4j.PatternLayout ">
          
    </layout>
    <filter class="org.apache.log4j.varia.LevelRangeFilter ">
      
    </filter>
  </appender>

  <appender name="WARN" class="org.apache.log4j.RollingFileAppender ">
     
     
     
     
    <layout class="org.apache.log4j.PatternLayout ">
          
    </layout>
    <filter class="org.apache.log4j.varia.LevelRangeFilter ">
      
    </filter>
  </appender>

  <appender name="ERROR" class="org.apache.log4j.RollingFileAppender ">
     
     
     
     
    <layout class="org.apache.log4j.PatternLayout ">
          
    </layout>
    <filter class="org.apache.log4j.varia.LevelRangeFilter ">
      
    </filter>
  </appender>

  <root>
    <priority value="debug"/>
    <appender-ref ref="STDOUT"/>
      <appender-ref ref="DEBUG"/>
    <appender-ref ref="INFO"/>
    <appender-ref ref="WARN"/>
    <appender-ref ref="ERROR"/>
  </root>

</log4j:configuration>
*******************

Could some body please tell what wrong am I doing here ?

thanks in advance for your time spent



-- 
View this message in context: http://www.nabble.com/level-based-logging-into-seperate-files-tf4150902.html#a11860074
Sent from the Log4j - Users mailing list archive at Nabble.com.


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


Re: level based logging into seperate files

Posted by Sarvananda <na...@gmail.com>.
Since after a lot of readin, I figrured that filters can only be used in an
XML filem I made an XMl file and a java class to test it. Alas, I am still
getting errors :
---------- java ----------
log4j:ERROR Could not create the Layout. Reported error follows.
java.lang.ClassNotFoundException: org.apache.log4j.PatternLayout 
	at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
	at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Class.java:164)
	at org.apache.log4j.helpers.Loader.loadClass(Loader.java:178)
	at
org.apache.log4j.xml.DOMConfigurator.parseLayout(DOMConfigurator.java:455)
	at
org.apache.log4j.xml.DOMConfigurator.parseAppender(DOMConfigurator.java:196)
	at
org.apache.log4j.xml.DOMConfigurator.findAppenderByName(DOMConfigurator.java:150)
	at
org.apache.log4j.xml.DOMConfigurator.findAppenderByReference(DOMConfigurator.java:163)
	at
org.apache.log4j.xml.DOMConfigurator.parseChildrenOfLoggerElement(DOMConfigurator.java:425)
	at org.apache.log4j.xml.DOMConfigurator.parseRoot(DOMConfigurator.java:394)
	at org.apache.log4j.xml.DOMConfigurator.parse(DOMConfigurator.java:829)
	at
org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:712)
	at
org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:618)
	at
org.apache.log4j.helpers.OptionConverter.selectAndConfigure(OptionConverter.java:470)
	at org.apache.log4j.LogManager.<clinit>(LogManager.java:122)
	at org.apache.log4j.Logger.getLogger(Logger.java:117)
	at XMLSample.<clinit>(XMLSample.java:6)
log4j:ERROR Could not create an Appender. Reported error follows.
java.lang.ClassNotFoundException: org.apache.log4j.RollingFileAppender 
	at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
	at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Class.java:164)
	at org.apache.log4j.helpers.Loader.loadClass(Loader.java:178)
	at
org.apache.log4j.xml.DOMConfigurator.parseAppender(DOMConfigurator.java:174)
	at
org.apache.log4j.xml.DOMConfigurator.findAppenderByName(DOMConfigurator.java:150)
	at
org.apache.log4j.xml.DOMConfigurator.findAppenderByReference(DOMConfigurator.java:163)
	at
org.apache.log4j.xml.DOMConfigurator.parseChildrenOfLoggerElement(DOMConfigurator.java:425)
	at org.apache.log4j.xml.DOMConfigurator.parseRoot(DOMConfigurator.java:394)
	at org.apache.log4j.xml.DOMConfigurator.parse(DOMConfigurator.java:829)
	at
org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:712)
	at
org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:618)
	at
org.apache.log4j.helpers.OptionConverter.selectAndConfigure(OptionConverter.java:470)
	at org.apache.log4j.LogManager.<clinit>(LogManager.java:122)
	at org.apache.log4j.Logger.getLogger(Logger.java:117)
	at XMLSample.<clinit>(XMLSample.java:6)
log4j:ERROR Could not parse url [file:/D:/sampja/xmllog/log4j.xml].
java.lang.NullPointerException
	at java.util.Hashtable.put(Hashtable.java:396)
	at
org.apache.log4j.xml.DOMConfigurator.findAppenderByName(DOMConfigurator.java:151)
	at
org.apache.log4j.xml.DOMConfigurator.findAppenderByReference(DOMConfigurator.java:163)
	at
org.apache.log4j.xml.DOMConfigurator.parseChildrenOfLoggerElement(DOMConfigurator.java:425)
	at org.apache.log4j.xml.DOMConfigurator.parseRoot(DOMConfigurator.java:394)
	at org.apache.log4j.xml.DOMConfigurator.parse(DOMConfigurator.java:829)
	at
org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:712)
	at
org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:618)
	at
org.apache.log4j.helpers.OptionConverter.selectAndConfigure(OptionConverter.java:470)
	at org.apache.log4j.LogManager.<clinit>(LogManager.java:122)
	at org.apache.log4j.Logger.getLogger(Logger.java:117)
	at XMLSample.<clinit>(XMLSample.java:6)
log4j:ERROR Could not create the Layout. Reported error follows.
java.lang.ClassNotFoundException: org.apache.log4j.PatternLayout 
	at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
	at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Class.java:164)
	at org.apache.log4j.helpers.Loader.loadClass(Loader.java:178)
	at
org.apache.log4j.xml.DOMConfigurator.parseLayout(DOMConfigurator.java:455)
	at
org.apache.log4j.xml.DOMConfigurator.parseAppender(DOMConfigurator.java:196)
	at
org.apache.log4j.xml.DOMConfigurator.findAppenderByName(DOMConfigurator.java:150)
	at
org.apache.log4j.xml.DOMConfigurator.findAppenderByReference(DOMConfigurator.java:163)
	at
org.apache.log4j.xml.DOMConfigurator.parseChildrenOfLoggerElement(DOMConfigurator.java:425)
	at org.apache.log4j.xml.DOMConfigurator.parseRoot(DOMConfigurator.java:394)
	at org.apache.log4j.xml.DOMConfigurator.parse(DOMConfigurator.java:829)
	at
org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:712)
	at
org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:604)
	at org.apache.log4j.xml.DOMConfigurator.configure(DOMConfigurator.java:733)
	at XMLSample.main(XMLSample.java:9)
log4j:ERROR Could not create an Appender. Reported error follows.
java.lang.ClassNotFoundException: org.apache.log4j.RollingFileAppender 
	at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
	at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Class.java:164)
	at org.apache.log4j.helpers.Loader.loadClass(Loader.java:178)
	at
org.apache.log4j.xml.DOMConfigurator.parseAppender(DOMConfigurator.java:174)
	at
org.apache.log4j.xml.DOMConfigurator.findAppenderByName(DOMConfigurator.java:150)
	at
org.apache.log4j.xml.DOMConfigurator.findAppenderByReference(DOMConfigurator.java:163)
	at
org.apache.log4j.xml.DOMConfigurator.parseChildrenOfLoggerElement(DOMConfigurator.java:425)
	at org.apache.log4j.xml.DOMConfigurator.parseRoot(DOMConfigurator.java:394)
	at org.apache.log4j.xml.DOMConfigurator.parse(DOMConfigurator.java:829)
	at
org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:712)
	at
org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:604)
	at org.apache.log4j.xml.DOMConfigurator.configure(DOMConfigurator.java:733)
	at XMLSample.main(XMLSample.java:9)
log4j:ERROR Could not parse file [log4j.xml].
java.lang.NullPointerException
	at java.util.Hashtable.put(Hashtable.java:396)
	at
org.apache.log4j.xml.DOMConfigurator.findAppenderByName(DOMConfigurator.java:151)
	at
org.apache.log4j.xml.DOMConfigurator.findAppenderByReference(DOMConfigurator.java:163)
	at
org.apache.log4j.xml.DOMConfigurator.parseChildrenOfLoggerElement(DOMConfigurator.java:425)
	at org.apache.log4j.xml.DOMConfigurator.parseRoot(DOMConfigurator.java:394)
	at org.apache.log4j.xml.DOMConfigurator.parse(DOMConfigurator.java:829)
	at
org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:712)
	at
org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:604)
	at org.apache.log4j.xml.DOMConfigurator.configure(DOMConfigurator.java:733)
	at XMLSample.main(XMLSample.java:9)
log4j:ERROR No layout set for the appender named [STDOUT].

Output completed (2 sec consumed) - Normal Termination
********************************************************
Heres my java file :
*********************
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
import org.apache.log4j.xml.DOMConfigurator;

public class XMLSample {   
	static Logger logger = Logger.getLogger(XMLSample.class);   
	public static void main(String args[]) {      
//		PropertyConfigurator.configure("plainlog4jconfig.xml");     
xmllog4jconfig2
		DOMConfigurator.configure("log4j.xml");

		logger.debug("Here is some DEBUG");      
		logger.info("Here is some INFO");      
		logger.warn("Here is some WARN");      
		logger.error("Here is some ERROR");   		
		logger.fatal("Here is some FATAL");   
		}
	}    
********************
heres the XML configuration:
*********************
<?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 ">
          
    </layout>
  </appender>

  <appender name="DEBUG" class="org.apache.log4j.RollingFileAppender ">
     
     
     
     
    <layout class="org.apache.log4j.PatternLayout ">
          
    </layout>
  </appender>

  <appender name="INFO" class="org.apache.log4j.RollingFileAppender ">
     
     
     
     
    <layout class="org.apache.log4j.PatternLayout ">
          
    </layout>
    <filter class="org.apache.log4j.varia.LevelRangeFilter ">
      
    </filter>
  </appender>

  <appender name="WARN" class="org.apache.log4j.RollingFileAppender ">
     
     
     
     
    <layout class="org.apache.log4j.PatternLayout ">
          
    </layout>
    <filter class="org.apache.log4j.varia.LevelRangeFilter ">
      
    </filter>
  </appender>

  <appender name="ERROR" class="org.apache.log4j.RollingFileAppender ">
     
     
     
     
    <layout class="org.apache.log4j.PatternLayout ">
          
    </layout>
    <filter class="org.apache.log4j.varia.LevelRangeFilter ">
      
    </filter>
  </appender>

  <root>
    <priority value="debug"/>
    <appender-ref ref="STDOUT"/>
      <appender-ref ref="DEBUG"/>
    <appender-ref ref="INFO"/>
    <appender-ref ref="WARN"/>
    <appender-ref ref="ERROR"/>
  </root>

</log4j:configuration>
*******************

Could some body please tell what wrong am I doing here ?

thanks in advance for your time spent

-- 
View this message in context: http://www.nabble.com/level-based-logging-into-seperate-files-tf4150902.html#a11859926
Sent from the Log4j - Users mailing list archive at Nabble.com.


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