logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From orko <orko_...@yahoo.com>
Subject Re: log two different messages to two different files
Date Tue, 11 Dec 2007 02:29:38 GMT
I think you can use Logger.getLogger("longMsg."+this.getClass().getName()) and  then in the
configuration file you have to do following setup:


<appender name="LONG_MSG" class="org.apache.log4j.FileAppender">
  <param name="Threshold" value="TRACE"/>
  <param name="File" value="${user.dir}/login_info.log"/>
  <layout class="org.apache.log4j.PatternLayout">
    <param name="ConversionPattern" value="%d{dd MM yyyy HH:mm:ss} %p %C %nIn Zeile Nummer:
%L %m %n%n"/>
  </layout>
</appender>

<logger name="longMsg">
  <level value="trace"/>
  <appender-ref ref="LONG_MSG" />
</logger>
If it works for the long msg, you can do the same for short msg in the same file.
Thanks,
-OrkO

Beth Hechanova <bhechanova@imsconsultants.com> wrote: Hi,

 

I have the concept of a long error message and a short error message in
my application.  Long error messages get written to one file, and the
short messages get written to a different file.  Ideally in my
application everywhere that needs to log an error message can simply
call Logger.getLogger(this.getClass().getName()).error(longMessage,
shortMessage) and the configuration of log4j will send the longMessage
and shortMessage to the appropriate file.

 

I have two different appenders configured for writing to the two
different files in the appropriate format.  But I don't know how to get
the long error message written only to one of the log files, and the
short error message only written to a different log file.

 

Is there a way to configure the properties file to accomplish this?  

Or would I need to extend the behavior in log4j itself?  If so, where
would be the place to extend the behavior?

 

Thanks,

Beth



Mime
  • Unnamed multipart/alternative (inline, 8-Bit, 0 bytes)
View raw message