Re: Single war file - multiple hosts - can't get log4j to log to different files

2011-11-25 Thread Christopher Schultz
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Pid,

On 11/23/11 3:42 PM, Pid wrote:
> You could just run separate instances of Tomcat.  It would be less 
> hassle & easier to manage.
> 
> Separate CATALINA_HOME & CATALINA_BASE, so you can use the same
> core code & just create some separate instances.

That may be the path of least resistance for this case, but I would
favor the flexibility of being able to deploy the webapp in different
ways. The code isn't that complicated to make that work, so it would
be my recommendation.

- -chris
-BEGIN PGP SIGNATURE-
Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk7PtlgACgkQ9CaO5/Lv0PAHGgCdE45KNjodmfkFxJ+EN59O4763
HMkAn0/ktesy+2KWJYnK9RpVOh+kvgnu
=iF/d
-END PGP SIGNATURE-

-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Re: Single war file - multiple hosts - can't get log4j to log to different files

2011-11-23 Thread Pid
On 22/11/2011 22:35, Christopher Schultz wrote:
> Chris,
> 
> On 11/22/11 2:28 PM, chris derham wrote:
>> Java running on windows 2008 r2 against tomcat 7.0.19 java version
>> "1.6.0_24"
> 
> Thanks!
> 
>> I have a single war file, and would like to host multiple demo
>> sites of our app. So ideally users access demo1.company.com and
>> demo2.company.com. Completely isolated, but all running the same
>> war. Please correct me where ever my logic is wrong, but I figured
>> that I would
> 
>> 1) have a tomcat instance, containing config directory. This would
>> have catalina/demo1.company.com/ROOT.xml containing pertinent jndi
>> config.
> 
> Sounds good.
> 
>> 2) in server.xml add this
> 
>> > unpackWARs="false" autoDeploy="false"> > className="org.apache.catalina.valves.AccessLogValve" 
>> directory="logs" prefix="demo_access_log." suffix=".log" 
>> pattern="%h %l %u %t "%r" %s %b" resolveHosts="false"/> 
>> 
> 
> Well, that will give you an access log for the whole host. If that's
> what you want, that's what you got. If you want the webapps to have
> separate access logs, you'll have to configure the  in ROOT.xml
> (and whatever other webapps you deploy). Maybe something like
> "ROOT-access" as the "prefix" value.
> 
>> When I start the app, it works and the app works. However all
>> context's apps log to the same log file. What I want to know how to
>> make the different contexts under different hosts log to different
>> file. Our log4j file contains
> 
>> > class="org.apache.log4j.rolling.RollingFileAppender"> > name="Threshold" value="INFO" /> > value="${catalina.base}/logs/demo.log" />
> 
> So, this is a different issue. Above, you had an access log, which
> logs the hosts and URLs that they request, etc.
> 
> It appears that log4j is an application log, like for INFO and DEBUG
> and stuff like that, right?
> 
> Well, the obvious solution is to change the value of the "File"
> parameter in your log4j configuration. Try using something like
> "ROOT-demo.log" and a different value in the config file for the other
> copies that you deploy. Of course, that means that you can't actually
> use the same WAR file, or you need to figure out some way to load the
> log4j configuration file from another location.
> 
> If you write your own ServletContextListener to load the log4j
> configuration (that's what we do over here... it also shuts-down log4j
> when the webapp undeploys), then you ought to be able to use the JNDI
> context to find the location of a configuration file on a per-context
> basis. For instance, you could put your config files somewhere like
> /etc/mywebapp/ROOT.xml and /etc/mywebapp/non-root.xml and just change
> the name of the log file name.
> 
>  (which does stuff like log the
> 
>> I have searched around, and found some references to JNDI context
>> selectors for log4j, but I believe that this is to allow log4j
>> separation - not directly related to what I am trying to do.
> 
> I'm afraid I don't know a thing about JNDI context selectors and
> log4j. Sorry.
> 
>> I have tried to add a suitable web.xml environment entry, and then
>> add it to the log file name, e.g. 
>> ${catalina.base}/logs/${tomcatInstancePrefix}demo.log. Then in
>> ROOT.xml for each host I add
> 
>> > type="java.lang.String" override="false"/>
> 
>> and in web.xml I add
> 
>>  
>> tomcatInstancePrefix
> 
> 
> java.lang.String
>> 
> 
>> but that didn't work
> 
> Yeah, that doesn't work because it doesn't set a system property,
> which is what log4j requires for that kind of replacement.

You could just run separate instances of Tomcat.  It would be less
hassle & easier to manage.

Separate CATALINA_HOME & CATALINA_BASE, so you can use the same core
code & just create some separate instances.


p


-- 

[key:62590808]



signature.asc
Description: OpenPGP digital signature


Re: Single war file - multiple hosts - can't get log4j to log to different files

2011-11-23 Thread Pid
On 23/11/2011 13:06, chris derham wrote:
> I just wanted to see everything
> in a single place - from what I have read this can't be done

Correct.  It could be done, but the apps would need to look outside of
their local host.


p



-- 

[key:62590808]



signature.asc
Description: OpenPGP digital signature


Re: Single war file - multiple hosts - can't get log4j to log to different files

2011-11-23 Thread Christopher Schultz
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Chris,

On 11/23/11 8:06 AM, chris derham wrote:
>>> We thought this would allow us to monitor all contexts with a 
>>> single probe install, but it only seems to show a single
>>> localhost context. I assume that the hosts are separated, and
>>> that the context="priviliged" setting can allow a web app to
>>> access other webapps in the same context, but not across
>>> hosts.
>> 
>> So... what setting is that?
>> 
> I meant the crossContext="true" setting. I have searched around,
> and can see that both tomcat's manager and probe are not able to
> monitor virtual hosts other than the one that they reside in. So I
> will just have to deploy manager and/or probe for each virtual
> host. I just wanted to see everything in a single place - from what
> I have read this can't be done

If you are lazy/memory conscious/can tolerate the setup, you could put
all webapps under a single virtual host (the default, most likely)
with aliases (if you even require them) and that would solve the
management problem.

>> 1. Move your .war files from out of the webapps directory (and
>> subdirs) 2. Update the paths in ROOT.xml and probe.xml to point
>> to the new location 3. Remove the "local" and "demos"
>> directories
>> 
> Thanks for the pointer. What I ended up doing was moving all wars
> to /notWebapps. Then I unpacked them, and set the
> relevant context.xml's docbase to point to the exploded directory.
> Seems to work well now

Seems like a reasonable course of action. "notWebapps". I like that. :)

>>> The only idea I have left if nobody can see an obvious flaw in
>>> our logic is to write some custom code to initialise log4j. We
>>> would just need to pick up the context, or a jndi variable and
>>> then prefix the log file name with this. Guess it can't be that
>>> hard - just figured that somebody would have hit this before.
>> 
>> I think that's your best bet.
>> 
> Yes it was surprisingly easy. We created a subclass of springs 
> Log4jConfigListener, and then prefix the file parameter of any
> file appenders. We set the web.xml value to blank, which is
> ignored, and then when required we can override it in context.xml.
> Thanks for the pointer

You might want to put a comment in the web.xml where you have no value
explaining where the value is *really* located. You'll save some
sysasmin several hours of screaming in the future.

>> I'm not sure that using JMX is going to make your life any
>> easier.
> 
> I thought that via some internal to tomcat mechanism, I would be
> able to detect which context I was in, and thus be able to use that
> to drive the prefix for the log file, rather than having to have a
> specific web.xml setting that each context overrides.

You should be able to detect the context name during startup.
Actually, you can get the path from ServletContext.getContextPath. So,
if you have a ServletContextListener, you can do this:

event.getServletContext().getContextPath()

Of course, that gets you a string that you might need to massage (like
changing "" into "ROOT", removing slashes, etc.).

- -chris
-BEGIN PGP SIGNATURE-
Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk7NG1MACgkQ9CaO5/Lv0PCLdwCfQMZWqd0wDtwTXxiZgYyqtPTE
lowAn1tZMiEh1Qb4/NRpMeqKwXK18Glo
=wsFf
-END PGP SIGNATURE-

-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Re: Single war file - multiple hosts - can't get log4j to log to different files

2011-11-23 Thread chris derham
> > We thought this would allow us to monitor all contexts with a
> > single probe install, but it only seems to show a single localhost
> > context. I assume that the hosts are separated, and that the
> > context="priviliged" setting can allow a web app to access other
> > webapps in the same context, but not across hosts.
>
> So... what setting is that?
>
> I meant the crossContext="true" setting. I have searched around, and can
see that both tomcat's manager and probe are not able to monitor virtual
hosts other than the one that they reside in. So I will just have to deploy
manager and/or probe for each virtual host. I just wanted to see everything
in a single place - from what I have read this can't be done


> 1. Move your .war files from out of the webapps directory (and subdirs)
> 2. Update the paths in ROOT.xml and probe.xml to point to the new
>   location
> 3. Remove the "local" and "demos" directories
>
> Thanks for the pointer. What I ended up doing was moving all wars to
/notWebapps. Then I unpacked them, and set the relevant
context.xml's docbase to point to the exploded directory. Seems to work
well now

> The only idea I have left if nobody can see an obvious flaw in our
> > logic is to write some custom code to initialise log4j. We would
> > just need to pick up the context, or a jndi variable and then
> > prefix the log file name with this. Guess it can't be that hard -
> > just figured that somebody would have hit this before.
>
> I think that's your best bet.
>
> Yes it was surprisingly easy. We created a subclass of springs
Log4jConfigListener, and then prefix the file parameter of any file
appenders. We set the web.xml value to blank, which is ignored, and then
when required we can override it in context.xml. Thanks for the pointer

> I recall that Mark Thomas mentioned something in a recent response
> > about looking for some code in tomcat source where it allowed
> > different contexts to register with JMX using different ports. I
> > looked and can't find it - always hard to google for something if
> > you don't know the term. Can anyone provide a pointer to if there
> > is an existing variable containing a context id, or path, or name
> > or something unique that we could use to prefix the log file - or
> > is it just easier to setup our own context parameter?
>
> I'm not sure that using JMX is going to make your life any easier.
>

I thought that via some internal to tomcat mechanism, I would be able to
detect which context I was in, and thus be able to use that to drive the
prefix for the log file, rather than having to have a specific web.xml
setting that each context overrides.

Thanks for you quick and detailed reply

Chris


Re: Single war file - multiple hosts - can't get log4j to log to different files

2011-11-22 Thread Christopher Schultz
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Chris,

On 11/22/11 4:03 PM, chris derham wrote:
> So I wasn't 100% sure exactly what to do here. I setup a folder
> under webapps called demos. We put our app there, named ROOT.war.
> Then in another subfolder of webapps called local, we put
> probe.war.

So you'll end up with 4 contexts deployed:

/ -> webapps/demos/ROOT.war
/demos-> webapps/demos
/local-> webapps/local
/probe-> webapps/local/probe.war

> We thought this would allow us to monitor all contexts with a
> single probe install, but it only seems to show a single localhost
> context. I assume that the hosts are separated, and that the
> context="priviliged" setting can allow a web app to access other
> webapps in the same context, but not across hosts.

So... what setting is that?

> Does that explanation make sense, and does that remove your
> concern?

No, you should do this:

1. Move your .war files from out of the webapps directory (and subdirs)
2. Update the paths in ROOT.xml and probe.xml to point to the new
   location
3. Remove the "local" and "demos" directories

Or:
1. Remove the .xml files from conf/[hostname]/*.xml
2. Move your .war files from webapps/*/*.war to webapps/*.war
3. Remove the "local" and "demos" directories

While you have disabled auto-deploy, it would be surprising to see
webapps and directories stuck under the webapps/ tree that weren't
being auto-deployed. It's better to put them somewhere else. It also
makes Tomcat upgrades easier, since you won't have to move WAR files
or remember that you changed things from the default.

> The only idea I have left if nobody can see an obvious flaw in our
> logic is to write some custom code to initialise log4j. We would
> just need to pick up the context, or a jndi variable and then
> prefix the log file name with this. Guess it can't be that hard -
> just figured that somebody would have hit this before.

I think that's your best bet.

> I recall that Mark Thomas mentioned something in a recent response
> about looking for some code in tomcat source where it allowed
> different contexts to register with JMX using different ports. I
> looked and can't find it - always hard to google for something if
> you don't know the term. Can anyone provide a pointer to if there
> is an existing variable containing a context id, or path, or name
> or something unique that we could use to prefix the log file - or
> is it just easier to setup our own context parameter?

I'm not sure that using JMX is going to make your life any easier.

- -chris
-BEGIN PGP SIGNATURE-
Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk7MJcgACgkQ9CaO5/Lv0PDDpACdEJ+Kf/9pxVdpMLdeM0OxqIXB
72gAn1BhRTpS0Pd+yXeyDYefWN+Rkwdn
=i6Zk
-END PGP SIGNATURE-

-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Re: Single war file - multiple hosts - can't get log4j to log to different files

2011-11-22 Thread Christopher Schultz
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Chris,

On 11/22/11 2:28 PM, chris derham wrote:
> Java running on windows 2008 r2 against tomcat 7.0.19 java version
> "1.6.0_24"

Thanks!

> I have a single war file, and would like to host multiple demo
> sites of our app. So ideally users access demo1.company.com and
> demo2.company.com. Completely isolated, but all running the same
> war. Please correct me where ever my logic is wrong, but I figured
> that I would
> 
> 1) have a tomcat instance, containing config directory. This would
> have catalina/demo1.company.com/ROOT.xml containing pertinent jndi
> config.

Sounds good.

> 2) in server.xml add this
> 
>  unpackWARs="false" autoDeploy="false">  className="org.apache.catalina.valves.AccessLogValve" 
> directory="logs" prefix="demo_access_log." suffix=".log" 
> pattern="%h %l %u %t "%r" %s %b" resolveHosts="false"/> 
> 

Well, that will give you an access log for the whole host. If that's
what you want, that's what you got. If you want the webapps to have
separate access logs, you'll have to configure the  in ROOT.xml
(and whatever other webapps you deploy). Maybe something like
"ROOT-access" as the "prefix" value.

> When I start the app, it works and the app works. However all
> context's apps log to the same log file. What I want to know how to
> make the different contexts under different hosts log to different
> file. Our log4j file contains
> 
>  class="org.apache.log4j.rolling.RollingFileAppender">  name="Threshold" value="INFO" />  value="${catalina.base}/logs/demo.log" />

So, this is a different issue. Above, you had an access log, which
logs the hosts and URLs that they request, etc.

It appears that log4j is an application log, like for INFO and DEBUG
and stuff like that, right?

Well, the obvious solution is to change the value of the "File"
parameter in your log4j configuration. Try using something like
"ROOT-demo.log" and a different value in the config file for the other
copies that you deploy. Of course, that means that you can't actually
use the same WAR file, or you need to figure out some way to load the
log4j configuration file from another location.

If you write your own ServletContextListener to load the log4j
configuration (that's what we do over here... it also shuts-down log4j
when the webapp undeploys), then you ought to be able to use the JNDI
context to find the location of a configuration file on a per-context
basis. For instance, you could put your config files somewhere like
/etc/mywebapp/ROOT.xml and /etc/mywebapp/non-root.xml and just change
the name of the log file name.

 (which does stuff like log the

> I have searched around, and found some references to JNDI context
> selectors for log4j, but I believe that this is to allow log4j
> separation - not directly related to what I am trying to do.

I'm afraid I don't know a thing about JNDI context selectors and
log4j. Sorry.

> I have tried to add a suitable web.xml environment entry, and then
> add it to the log file name, e.g. 
> ${catalina.base}/logs/${tomcatInstancePrefix}demo.log. Then in
> ROOT.xml for each host I add
> 
>  type="java.lang.String" override="false"/>
> 
> and in web.xml I add
> 
>  
> tomcatInstancePrefix
>
> 
java.lang.String
> 
> 
> but that didn't work

Yeah, that doesn't work because it doesn't set a system property,
which is what log4j requires for that kind of replacement.

- -chris
-BEGIN PGP SIGNATURE-
Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk7MI7AACgkQ9CaO5/Lv0PAapACeIyObJIZFFiJI/rfeoSnjTZi8
oCQAnR37LDsCFGBO6N9ufRJL8vzYWill
=RcHC
-END PGP SIGNATURE-

-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Re: Single war file - multiple hosts - can't get log4j to log to different files

2011-11-22 Thread chris derham
> > unpackWARs="false" autoDeploy="false">
>
> The appBase I find a little concerning...  You don't have any apps
> directly place in webapps do you?
>
> So I wasn't 100% sure exactly what to do here. I setup a folder under
webapps called demos. We put our app there, named ROOT.war. Then in another
subfolder of webapps called local, we put probe.war. We thought this would
allow us to monitor all contexts with a single probe install, but it only
seems to show a single localhost context. I assume that the hosts are
separated, and that the context="priviliged" setting can allow a web app to
access other webapps in the same context, but not across hosts.

Does that explanation make sense, and does that remove your concern?

The only idea I have left if nobody can see an obvious flaw in our logic is
to write some custom code to initialise log4j. We would just need to pick
up the context, or a jndi variable and then prefix the log file name with
this. Guess it can't be that hard - just figured that somebody would have
hit this before.

I recall that Mark Thomas mentioned something in a recent response about
looking for some code in tomcat source where it allowed different contexts
to register with JMX using different ports. I looked and can't find it -
always hard to google for something if you don't know the term. Can anyone
provide a pointer to if there is an existing variable containing a context
id, or path, or name or something unique that we could use to prefix the
log file - or is it just easier to setup our own context parameter?

Thanks

Chris


Re: Single war file - multiple hosts - can't get log4j to log to different files

2011-11-22 Thread Pid
On 22/11/2011 19:28, chris derham wrote:
>unpackWARs="false" autoDeploy="false">

The appBase I find a little concerning...  You don't have any apps
directly place in webapps do you?


p


-- 

[key:62590808]



signature.asc
Description: OpenPGP digital signature


Single war file - multiple hosts - can't get log4j to log to different files

2011-11-22 Thread chris derham
All,

Java running on windows 2008 r2 against tomcat 7.0.19

java version "1.6.0_24"
Java(TM) SE Runtime Environment (build 1.6.0_24-b07)
Java HotSpot(TM) 64-Bit Server VM (build 19.1-b02, mixed mode)

I have a single war file, and would like to host multiple demo sites of our
app. So ideally users access demo1.company.com and demo2.company.com.
Completely isolated, but all running the same war. Please correct me where
ever my logic is wrong, but I figured that I would

1) have a tomcat instance, containing config directory. This would have
catalina/demo1.company.com/ROOT.xml containing pertinent jndi config.
2) in server.xml add this

  

  

When I start the app, it works and the app works. However all context's
apps log to the same log file. What I want to know how to make the
different contexts under different hosts log to different file. Our log4j
file contains













I have searched around, and found some references to JNDI context selectors
for log4j, but I believe that this is to allow log4j separation - not
directly related to what I am trying to do.

I have tried to add a suitable web.xml environment entry, and then add it
to the log file name, e.g.
${catalina.base}/logs/${tomcatInstancePrefix}demo.log. Then in ROOT.xml for
each host I add



and in web.xml I add


tomcatInstancePrefix
java.lang.String


but that didn't work

Has anyone else done this? I can't believe that we are unique. Perhaps I am
just ignorant of the correct term to search for. Any help greatly
appreciated

Thanks

Chris