You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Brian McGovern <bm...@imediainc.com> on 2005/02/22 14:24:08 UTC

RE:[RESOLVED] log4j.properties not found in tomcat

Thanks for the repliess.  My issue was that I needed to set a system wide environment variable called log4j.configuration and set its value to "log4j.properties", the name of my config file for log4j.  This was in the log4j documentation but I guess i skimmed over that part.  Log4j is a application completely separate from web container, hence the need for a system wide var.  Definately liking log4j more and more.  

My file was located in my /webapps/myappuri/WEB-INF/classes/  So the answer turns out that log4j looks for a system env var log4j.configuration and looks in your webapps class path for it.  

Additionally I set up tomcat to use my log4j file as well by makin a file called commons-logging.properties in /webapps/myappuri/WEB-INF/classes/ whos only line was:

org.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4JLogger

Note that commons-logging.jar needs to be in your /webapps/myappuri/WEB-INF/lib/ dir for this to work.

Thanks
-B



-----Original Message-----
From: Jacob Kjome [mailto:hoju@visi.com]
Sent: Tuesday, February 22, 2005 12:30 AM
To: Tomcat Users List
Subject: Re: log4j.properties not found in tomcat



You have to understand that any relative path is going to be resolved 
relative to the location where the JVM started.  If you started Tomcat via 
the service rather than the batch files, then the VM would be run, by 
default, from C:\winnt\System32.  So, when you supplied 
"-Dlog4j.configuration=log4j.properties", you got exactly what should be 
expected if log4j.properties were located in c:\winnt\System32.  Same goes 
for relatively defined paths to log files defined for FileAppenders in 
log4j.properties.

BTW, can you post your error?   FileNotFoundExceptions aren't thrown when 
Log4j can't find its config file.  You'd get a simple error saying as 
much.  The FileNotFoundExceptions are usually thrown when you specify a 
file for a FileAppender in a directory that doesn't exist.  Log4j makes no 
attempt to create directories if they don't exist already.  This is the 
correct and safe thing to do.  It is your responsibility to make sure the 
directory exists before Log4j attempts to use it.


Jake

At 11:09 PM 2/21/2005 -0500, you wrote:
 >Where do you put  log4j.properties currently?
 >-Michael Greer
 >
 >On Feb 21, 2005, at 5:02 PM, Brian McGovern wrote:
 >
 >> I have a wierd problem.  Tomcat on W2k barks FileNotFound Exceptions
 >> for the log4j.properties file when i execute a servlet that
 >> instantiates log4j.  Strangely enough the actual file that i create
 >> and log to with log4j.properties file logs out just fine even though
 >> stdout.log said that it couldn't find my log4j.properties file.
 >>
 >> Only time i don't get an error is when i put log4j.properites in my
 >> winnt/system32 directory.  But this doesnt make sense to me.  I supply
 >> -Dlog4j.configuration=log4j.properties to Java at startup and still
 >> get the same error.  I also tried the FULL path to my log4j.properties
 >> in the -D option.
 >>
 >> Instantiated like this across my app.
 >>
 >> private static final Logger zLogger =
 >> Logger.getLogger(MyClassName.class);
 >>
 >> Can anyone tell me where I went wrong.
 >>
 >> thanks
 >
 >
 >---------------------------------------------------------------------
 >To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
 >For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
 >
 >  


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


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


RE:[RESOLVED] log4j.properties not found in tomcat

Posted by Jacob Kjome <ho...@visi.com>.
Quoting Brian McGovern <bm...@imediainc.com>:

> Thanks for the repliess.  My issue was that I needed to set a system wide
> environment variable called log4j.configuration and set its value to
> "log4j.properties", the name of my config file for log4j.  This was in the
> log4j documentation but I guess i skimmed over that part.  Log4j is a
> application completely separate from web container, hence the need for a
> system wide var.  Definately liking log4j more and more.
>
> My file was located in my /webapps/myappuri/WEB-INF/classes/  So the answer
> turns out that log4j looks for a system env var log4j.configuration and looks
> in your webapps class path for it.
>

No, I'm pretty sure this is not the case.  log4j.configuration does not need to
be specified.  If it is, I believe it is assumed to be a file location.  If
relatively defined, it is resolved relative to the location that the JVM
started.  If not defined, Log4j looks in the classloader.  Actually, I haven't
checked, but it may fall back to the classloader if it can't find the log4j
config file in the location specified by the system property.  You'll have to
verify that.

> Additionally I set up tomcat to use my log4j file as well by makin a file
> called commons-logging.properties in /webapps/myappuri/WEB-INF/classes/ whos
> only line was:
>
> org.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4JLogger
>
> Note that commons-logging.jar needs to be in your
> /webapps/myappuri/WEB-INF/lib/ dir for this to work.


If you want Log4j to be a system-wide service, you should really add log4j.jar
and commons-logging.jar to CATALINA_HOME/common/lib and add log4j.properties to
CATALINA_HOME/common/classes.  There is no need for the
commons-logging.properties file in that case.  And it is kludgy to provide
server-level properties inside a webapp.  BTW, do you have log4j.jar in your
WEB-INF/lib?  If so, you are simply logging for your webapp alone, not
system-wide.

Jake

>
> Thanks
> -B
>
>
>
> -----Original Message-----
> From: Jacob Kjome [mailto:hoju@visi.com]
> Sent: Tuesday, February 22, 2005 12:30 AM
> To: Tomcat Users List
> Subject: Re: log4j.properties not found in tomcat
>
>
>
> You have to understand that any relative path is going to be resolved
> relative to the location where the JVM started.  If you started Tomcat via
> the service rather than the batch files, then the VM would be run, by
> default, from C:\winnt\System32.  So, when you supplied
> "-Dlog4j.configuration=log4j.properties", you got exactly what should be
> expected if log4j.properties were located in c:\winnt\System32.  Same goes
> for relatively defined paths to log files defined for FileAppenders in
> log4j.properties.
>
> BTW, can you post your error?   FileNotFoundExceptions aren't thrown when
> Log4j can't find its config file.  You'd get a simple error saying as
> much.  The FileNotFoundExceptions are usually thrown when you specify a
> file for a FileAppender in a directory that doesn't exist.  Log4j makes no
> attempt to create directories if they don't exist already.  This is the
> correct and safe thing to do.  It is your responsibility to make sure the
> directory exists before Log4j attempts to use it.
>
>
> Jake
>
> At 11:09 PM 2/21/2005 -0500, you wrote:
>  >Where do you put  log4j.properties currently?
>  >-Michael Greer
>  >
>  >On Feb 21, 2005, at 5:02 PM, Brian McGovern wrote:
>  >
>  >> I have a wierd problem.  Tomcat on W2k barks FileNotFound Exceptions
>  >> for the log4j.properties file when i execute a servlet that
>  >> instantiates log4j.  Strangely enough the actual file that i create
>  >> and log to with log4j.properties file logs out just fine even though
>  >> stdout.log said that it couldn't find my log4j.properties file.
>  >>
>  >> Only time i don't get an error is when i put log4j.properites in my
>  >> winnt/system32 directory.  But this doesnt make sense to me.  I supply
>  >> -Dlog4j.configuration=log4j.properties to Java at startup and still
>  >> get the same error.  I also tried the FULL path to my log4j.properties
>  >> in the -D option.
>  >>
>  >> Instantiated like this across my app.
>  >>
>  >> private static final Logger zLogger =
>  >> Logger.getLogger(MyClassName.class);
>  >>
>  >> Can anyone tell me where I went wrong.
>  >>
>  >> thanks
>  >
>  >
>  >---------------------------------------------------------------------
>  >To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
>  >For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>  >
>  >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>




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