You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Manfred Wolff <mw...@neusta.de> on 2003/03/09 12:29:27 UTC

[OT]Re: quick log4j question

Hi Dan.

The best you can do to place your property file in any directory that 
contains to the classpath (e.g. WEB-INF/classes ...) and load the file 
via the VM:

E.G. Tomcat in Catalina.bat

set CATALINA_OPTS=%CATALINA_OPTS% -Dlog4j.configuration=log4jxy.properties

(dont take log4j.properties, take another name)

Nothing more have to be done. At the first demand of a logger, log4j 
itsselft reads the propterty file.

e.g. common logger you have to put this line in your code:

private Log trace = Log4jFactory.getLog(this.getClass());

Manfred



Dan Allen wrote:
> I promise you I researched this, hence why you will find that this
> is an intelligible question.
> 
> If I make a log4j.properties file and I want to place it in the
> WEB-INF/classes/resources directory (in the spirit of Ted Husted) do
> I have to then create a custom servlet Log4jInit to load this
> properties file and define it in the web.xml file?  I found
> information on the custom servlet in the Log4j manual and it looks
> to be the same exact servlet that is used to initialize Torque in
> the stocktrack application in the Struts KickStart book.
> 
> In short, it would seem to me that if I move the file from 
> 
> WEB-INF/classes
> 
> to
> 
> WEB-INF/classes/resources
> 
> I have to make a custom servlet.  Is this an incorrect assumption
> and if not, how do I tell the web container where to find it (surely
> it doesn't go hunting throughout the whole classpath).
> 
> Dan
> 



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


Re: [OT]Re: quick log4j question

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Mon, 10 Mar 2003, Rick Reumann wrote:

> Date: Mon, 10 Mar 2003 12:21:41 -0500
> From: Rick Reumann <r...@reumann.net>
> Reply-To: Struts Users Mailing List <st...@jakarta.apache.org>
> To: Struts Users Mailing List <st...@jakarta.apache.org>
> Subject: Re: [OT]Re: quick log4j question
>
> On Mon, 10 Mar 2003 08:44:07 -0800 (PST)
> "Craig R. McClanahan" <cr...@apache.org> wrote:
>
> > The right place to put your properties files, then, is wherever the
> > software that is loading them will look for them :-).
>
> Sorry for my ignorance here but by software do you mean the servlet
> container? If so how do I know how it's configured to look for resources
> by default (probably a RTFM thing I'm guessing).
>

No, by "software" I mean whatever software is going to read that
particular properties file.  In the particular case of "log4j.properties",
the container does not care whether or not you are going to load this
resource or not -- you have to check the Log4J docs to see where it wants
the "log4j.properties" to be loaded from.

If it says "put the log4j.properties file in a directory that is on your
classpath", you can translate that to mean "/WEB-INF/classes", because (in
effect) that is the directory that the container puts on your "class path"
for you.  It's Log4J, not the container, that actually tries to load this
file.

> --
> Rick Reumann

Craig

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


Re: [OT]Re: quick log4j question

Posted by Rick Reumann <r...@reumann.net>.
On Mon, 10 Mar 2003 08:44:07 -0800 (PST)
"Craig R. McClanahan" <cr...@apache.org> wrote:
 
> The right place to put your properties files, then, is wherever the
> software that is loading them will look for them :-).

Sorry for my ignorance here but by software do you mean the servlet
container? If so how do I know how it's configured to look for resources
by default (probably a RTFM thing I'm guessing).

-- 
Rick Reumann

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


Re: [OT]Re: quick log4j question

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Mon, 10 Mar 2003, Manfred Wolff wrote:

> Date: Mon, 10 Mar 2003 09:06:38 +0100
> From: Manfred Wolff <mw...@neusta.de>
> Reply-To: Struts Users Mailing List <st...@jakarta.apache.org>,
>      mail@manfred-wolff.de
> To: Struts Users Mailing List <st...@jakarta.apache.org>
> Subject: Re: [OT]Re: quick log4j question
>
> No, Rick, I don't. I have said: Put it in ANY directory, that contains
> to the classpath. It is a good Idea to build a group of property-files
> e.g. in WEB-INF/classes/ressources or any other directory.
>

If you are using ClassLoader.getResource() to load resources from inside
the class path (which I imagine that Log4J is doing), there is a very
definite difference between putting the properties file in
"/WEB-INF/classes" and "/WEB-INF/classes/resources" -- one will be found
and one will not.

The reason for this is that resource file names have a path structure just
like Java class names in a package -- to retrieve the resource file
"/WEB-INF/classes/log4j.properties", one would say:

  ClassLoader cl = this.getClass().getClassLoader();
  InputStream is = cl.getResourceAsStream("log4j.properties");

but, if you want "/WEB-INF/classes/resources/log4j.properties", you would
say this instead:

  ClassLoader cl = this.getClass().getClassLoader();
  InputStream is = cl.getResourceAsStream("resources/log4j.properties");

The right place to put your properties files, then, is wherever the
software that is loading them will look for them :-).

> But I don't know why evrybody will have a configuration in web.xml and a
>   initialisation in the Actionsservlet. That is not need.
>
> Manfred
>

Craig


> Rick Reumann wrote:
> > On Sun, Mar 09,'03 (12:29 PM GMT+0100), Manfred wrote:
> >
> >
> >>The best you can do to place your property file in any directory that
> >>contains to the classpath (e.g. WEB-INF/classes ...) and load the file
> >
> >
> > So you are saying (in response to Dan's question) that it is best to
> > just keep the log4j.properties file in WEB-INF/classes and to not try
> > and move it to somewhere like WEB-INF/classes/resources ?
> >
> >
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>

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


Re: [OT]Re: quick log4j question

Posted by Manfred Wolff <mw...@neusta.de>.
No, Rick, I don't. I have said: Put it in ANY directory, that contains 
to the classpath. It is a good Idea to build a group of property-files 
e.g. in WEB-INF/classes/ressources or any other directory.

But I don't know why evrybody will have a configuration in web.xml and a 
  initialisation in the Actionsservlet. That is not need.

Manfred

Rick Reumann wrote:
> On Sun, Mar 09,'03 (12:29 PM GMT+0100), Manfred wrote: 
>   
> 
>>The best you can do to place your property file in any directory that 
>>contains to the classpath (e.g. WEB-INF/classes ...) and load the file
> 
> 
> So you are saying (in response to Dan's question) that it is best to
> just keep the log4j.properties file in WEB-INF/classes and to not try
> and move it to somewhere like WEB-INF/classes/resources ?
>  
> 



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


Re: [OT]Re: quick log4j question

Posted by Dan Allen <da...@mojavelinux.com>.
> > The best you can do to place your property file in any directory that 
> > contains to the classpath (e.g. WEB-INF/classes ...) and load the file
> 
> So you are saying (in response to Dan's question) that it is best to
> just keep the log4j.properties file in WEB-INF/classes and to not try
> and move it to somewhere like WEB-INF/classes/resources ?

The way I interpret this discussion is as follows.  If you move the
log4j.properties file from 

WEB-INF/classes

to

WEB-INF/classes/resources

you either have to

create a custom servlet which initializes the log4j.properties file in the
web.xml file, such as:

 <servlet>
     <servlet-name>log4j-init</servlet-name>
     <servlet-class>net.creativerge.util.Log4jInit</servlet-class>
     <init-param>
         <param-name>log4j-init-file</param-name>
         <param-value>WEB-INF/classes/resources/log4j.properties</param-value>
         <description>Initialization file location</description>
     </init-param>
     <load-on-startup>1</load-on-startup>
 </servlet>

OR

you have to modify the environment variable log4j.configuration in the CATALINA
startup script.

Dan

-- 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
Daniel Allen, <da...@mojavelinux.com>
http://www.mojavelinux.com/
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
Microsoft's Law of Software Engineering: 
Don't worry if it doesn't work right. 
If everything did, we'd be out of a job.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

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


Re: [OT]Re: quick log4j question

Posted by Rick Reumann <r...@reumann.net>.
On Sun, Mar 09,'03 (12:29 PM GMT+0100), Manfred wrote: 
  
> The best you can do to place your property file in any directory that 
> contains to the classpath (e.g. WEB-INF/classes ...) and load the file

So you are saying (in response to Dan's question) that it is best to
just keep the log4j.properties file in WEB-INF/classes and to not try
and move it to somewhere like WEB-INF/classes/resources ?
 

-- 
Rick

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