At 12:40 PM 8/25/2005, Konrad Billewicz wrote:
> I had to tweak the code a bit but now it works like a charm. Thanks for
getting me on the right track. You made my
> day. I'll post my solution below for others. This block sits in a servlet.

I tried to run this code but it's not working in my case. I'm getting the same
error as when I tried to do it on my own.

java.io.FileNotFoundException: WEB-INF\logs\exceptions.log

Unless I am missing something obvious, the above error message line
clearly indicates that REL_PATH was set to null or maybe the empty
string.

Java code is exactly as yours and my properties file:

# REL_PATH=C:\\workspace\\msz\\web\\
log4j.logger.pl.akonet.framework.Servlet=DEBUG, EXCEPTIONS
log4j.appender.EXCEPTIONS=org.apache.log4j.DailyRollingFileAppender
log4j.appender.EXCEPTIONS.DatePattern='.'yyyy-MM-dd'.log'
log4j.appender.EXCEPTIONS.File=${REL_PATH}WEB-INF\\logs\\exceptions.log
log4j.appender.EXCEPTIONS.layout=org.apache.log4j.PatternLayout
log4j.appender.EXCEPTIONS.layout.ConversionPattern=%d{HH:mm:ss dd-MM-yyyy} %-5p
@ %C{1}:%M:%L - %m%n

When I uncomment first line everything works fine. I checked in debuger that
REL_PATH key is present in props when invoking PropertyConfigurator.
configure(props). What is going on?

Interesting. The fact that REL_PATH is set in the props object does
not mean that the corresponding value is not null.

Quoting Jacob's message dated 2005-08-24 (on this thread):


   Just as long as you realize that context.getRealPath() may return null
   in the case where the webapp is run directly from the .war file rather
   than being unpacked to a directory by the servlet container.  The
   servlet spec allows for this behavior so you are depending on
   container-specific, and probably even configuration-specific,
   container behavior.

   Ultimately, you should probably define a path outside the webapp for
   storing log files.  But as far as referencing a property in the config
   file for a path determined at run-time, this is a good example for
   everyone to see.  Thanks for posting it.


The javadocs [1] for the ServletContext.getRealPath method read:

  Returns a String containing the real path for a given virtual
  path. For example, the path "/index.html" returns the absolute file
  path on the server's filesystem would be served by a request for
  "http://host/contextPath/index.html";, where contextPath is the context
  path of this ServletContext..

  The real path returned will be in a form appropriate to the computer
  and operating system on which the servlet container is running,
  including the proper path separators. This method returns null if the
  servlet container cannot translate the virtual path to a real path for
  any reason (such as when the content is being made available from a
  .war archive).

So, are you deploying your application as a .war file?

[1] http://tinyurl.com/8w33s


Best regards,
Konrad Billewicz

--
Ceki Gülcü

  The complete log4j manual: http://www.qos.ch/log4j/



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to