Re: How to externalize a webapp's logging.properties?
Konstantin, Thanks very much for the tips. VirtualWebappLoader worked perfectly. For the record, here's what worked for me: META-INF/context.xml: Put logging.properties in $TOMCAT_HOME/virtualcp/my-webapp/logging.properties. Works like a charm. Thanks again! Dan On Tue, Oct 11, 2011 at 9:08 AM, Konstantin Kolinko wrote: > 2011/10/11 Dan Checkoway : > > So... > > > > 1. Is it currently possible to do what I'm trying to do? Per-webapp > logging > > control without using WEB-INF/classes/logging.properties? I could really > > use a working example if this is doable. > > No it is not possible. > > What Pid wrote about the manager webapp is about applications that use > log methods in Servlet API. It does not concern those that use proper > logging libraries. > > > The suggestions that I have: > 1. Look at the org.apache.juli.ClassLoaderLogManager class. > > That is where configuration loading happens, and its > getProperty(String) method is what is actually used to access > individual values of those properties. > > It might be that it were possible to improve it. > > You can specify a different LogManager implementation when Tomcat starts. > > 2. It might be that VirtualWebappLoader class (in o.a.c.loader > package, see its Javadoc) could be used to add an external folder to > webapp classpath, so that logging.properties could be read from there. > > I have not tried it though. > > 3. The logging.properties file in the webapp can use any system > properties. Maybe you can use them to specify system-dependent values. > > Best regards, > Konstantin Kolinko > > - > To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org > For additional commands, e-mail: users-h...@tomcat.apache.org > >
Re: How to externalize a webapp's logging.properties?
2011/10/11 Dan Checkoway : > So... > > 1. Is it currently possible to do what I'm trying to do? Per-webapp logging > control without using WEB-INF/classes/logging.properties? I could really > use a working example if this is doable. No it is not possible. What Pid wrote about the manager webapp is about applications that use log methods in Servlet API. It does not concern those that use proper logging libraries. The suggestions that I have: 1. Look at the org.apache.juli.ClassLoaderLogManager class. That is where configuration loading happens, and its getProperty(String) method is what is actually used to access individual values of those properties. It might be that it were possible to improve it. You can specify a different LogManager implementation when Tomcat starts. 2. It might be that VirtualWebappLoader class (in o.a.c.loader package, see its Javadoc) could be used to add an external folder to webapp classpath, so that logging.properties could be read from there. I have not tried it though. 3. The logging.properties file in the webapp can use any system properties. Maybe you can use them to specify system-dependent values. Best regards, Konstantin Kolinko - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
Re: How to externalize a webapp's logging.properties?
Pid, That's exactly what I tried: - handlers = 1catalina.org.apache.juli.FileHandler, 2localhost.org.apache.juli.FileHandler, 3manager.org.apache.juli.FileHandler, 4host-manager.org.apache.juli.FileHandler, 5my-webapp.org.apache.juli.FileHandler, java.util.logging.ConsoleHandler 5my-webapp.org.apache.juli.FileHandler.level = FINE 5my-webapp.org.apache.juli.FileHandler.directory = ${catalina.base}/logs 5my-webapp.org.apache.juli.FileHandler.prefix = my-webapp. org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/my-webapp].level = INFO org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/my-webapp].handlers = 5my-webapp.org.apache.juli.FileHandler - When I fire up tomcat, it does create my-webapp.2011-10-11.log, and it logs: Oct 11, 2011 8:47:20 AM org.apache.catalina.core.ApplicationContext log INFO: Initializing Spring FrameworkServlet 'dispatcher' ...but then the rest of my webapp's output from then on goes to catalina.out -- until tomcat shutdown, at which point this gets logged to my-webapp.2011-10-11.log: Oct 11, 2011 8:48:27 AM org.apache.catalina.core.ApplicationContext log INFO: Destroying Spring FrameworkServlet 'dispatcher' Oct 11, 2011 8:48:28 AM org.apache.catalina.core.ApplicationContext log INFO: Closing Spring root WebApplicationContext I'm confused as to why everything else is going to catalina.out...any advice? Thanks, Dan On Tue, Oct 11, 2011 at 8:36 AM, Pid wrote: > On 11/10/2011 07:28, Dan Checkoway wrote: > > Hello, > > > > I run several webapps under one instance of tomcat (7.0.21 currently, > fwiw), > > and each webapp uses JDK logging and needs to log to its own separate log > > file. I accomplish this by placing logging.properties in > WEB-INF/classes, > > and an example of how it's set up is: > > > > handlers = org.apache.juli.FileHandler > > > > org.apache.juli.FileHandler.level = FINE > > org.apache.juli.FileHandler.directory = ${catalina.base}/logs > > org.apache.juli.FileHandler.prefix = my-webapp. > > org.apache.juli.FileHandler.formatter = > > com.mycompany.logging.MyCustomFormatter > > > > ...all of my logging levels... > > You can configure the main logging.properties to output separate files > per application, as per: > > http://tomcat.apache.org/tomcat-6.0-doc/logging.html > > The Manager application is configured like this. > > > p > > > (and fwiw, my custom logging formatter lives in a jar that I place in > > $TOMCAT_HOME/endorsed) > > > > It works great. The challenge I face, however, is that I deploy my > webapps > > as .war files, and I'd like to be able to deploy the same exact .war file > to > > different environments...dev, test, staging, production. And I'd like to > be > > able to use different logging level config in each of those environments. > > As it stands right now, I'm sorta confined to that single instance of > > logging.properties that gets "built into" my webapp. I want to > > "externalize" this moving part if possible. > > > > I played around with omitting logging.properties from my webapp, and > instead > > using just $TOMCAT_HOME/conf/logging.properties, but (a) I wasn't able to > > get it to work the same as it's working right now, and (b) that funnels > me > > into "sharing" logging level config across my webapps (in other words, > > webapp 1 can't have a different logging level for package x.y.z than > webapp > > 2). Forget (b) for the time being, since I can live with shared logging > > levels across webapps. The main issue I'm having with this approach is > that > > I can't seem to get *all* of my logging to go to my webapp-specific log > > file. Some stuff still gets logged to catalina.out. > > > > So... > > > > 1. Is it currently possible to do what I'm trying to do? Per-webapp > logging > > control without using WEB-INF/classes/logging.properties? I could really > > use a working example if this is doable. > > > > 2. Is there any other hook I can take advantage of (i.e. a context > listener > > or something), by which my code can get invoked prior to JULI > initializing > > for my webapp, where I might be able to override the > > java.util.logging.config.file system property, or something like that? > > > > 3. If neither of those options is possible, how feasible would it be to > add > > a feature to tomcat, where you can configure a path to logging.properties > > (in theory classpath: or file: style) on a per-webapp basis? i.e. in > > conf/server.xml in the . > > > > Or if there's an easier way, shove me toward it... > > > > Thanks, > > Dan > > > > >
Re: How to externalize a webapp's logging.properties?
On 11/10/2011 07:28, Dan Checkoway wrote: > Hello, > > I run several webapps under one instance of tomcat (7.0.21 currently, fwiw), > and each webapp uses JDK logging and needs to log to its own separate log > file. I accomplish this by placing logging.properties in WEB-INF/classes, > and an example of how it's set up is: > > handlers = org.apache.juli.FileHandler > > org.apache.juli.FileHandler.level = FINE > org.apache.juli.FileHandler.directory = ${catalina.base}/logs > org.apache.juli.FileHandler.prefix = my-webapp. > org.apache.juli.FileHandler.formatter = > com.mycompany.logging.MyCustomFormatter > > ...all of my logging levels... You can configure the main logging.properties to output separate files per application, as per: http://tomcat.apache.org/tomcat-6.0-doc/logging.html The Manager application is configured like this. p > (and fwiw, my custom logging formatter lives in a jar that I place in > $TOMCAT_HOME/endorsed) > > It works great. The challenge I face, however, is that I deploy my webapps > as .war files, and I'd like to be able to deploy the same exact .war file to > different environments...dev, test, staging, production. And I'd like to be > able to use different logging level config in each of those environments. > As it stands right now, I'm sorta confined to that single instance of > logging.properties that gets "built into" my webapp. I want to > "externalize" this moving part if possible. > > I played around with omitting logging.properties from my webapp, and instead > using just $TOMCAT_HOME/conf/logging.properties, but (a) I wasn't able to > get it to work the same as it's working right now, and (b) that funnels me > into "sharing" logging level config across my webapps (in other words, > webapp 1 can't have a different logging level for package x.y.z than webapp > 2). Forget (b) for the time being, since I can live with shared logging > levels across webapps. The main issue I'm having with this approach is that > I can't seem to get *all* of my logging to go to my webapp-specific log > file. Some stuff still gets logged to catalina.out. > > So... > > 1. Is it currently possible to do what I'm trying to do? Per-webapp logging > control without using WEB-INF/classes/logging.properties? I could really > use a working example if this is doable. > > 2. Is there any other hook I can take advantage of (i.e. a context listener > or something), by which my code can get invoked prior to JULI initializing > for my webapp, where I might be able to override the > java.util.logging.config.file system property, or something like that? > > 3. If neither of those options is possible, how feasible would it be to add > a feature to tomcat, where you can configure a path to logging.properties > (in theory classpath: or file: style) on a per-webapp basis? i.e. in > conf/server.xml in the . > > Or if there's an easier way, shove me toward it... > > Thanks, > Dan > signature.asc Description: OpenPGP digital signature
How to externalize a webapp's logging.properties?
Hello, I run several webapps under one instance of tomcat (7.0.21 currently, fwiw), and each webapp uses JDK logging and needs to log to its own separate log file. I accomplish this by placing logging.properties in WEB-INF/classes, and an example of how it's set up is: handlers = org.apache.juli.FileHandler org.apache.juli.FileHandler.level = FINE org.apache.juli.FileHandler.directory = ${catalina.base}/logs org.apache.juli.FileHandler.prefix = my-webapp. org.apache.juli.FileHandler.formatter = com.mycompany.logging.MyCustomFormatter ...all of my logging levels... (and fwiw, my custom logging formatter lives in a jar that I place in $TOMCAT_HOME/endorsed) It works great. The challenge I face, however, is that I deploy my webapps as .war files, and I'd like to be able to deploy the same exact .war file to different environments...dev, test, staging, production. And I'd like to be able to use different logging level config in each of those environments. As it stands right now, I'm sorta confined to that single instance of logging.properties that gets "built into" my webapp. I want to "externalize" this moving part if possible. I played around with omitting logging.properties from my webapp, and instead using just $TOMCAT_HOME/conf/logging.properties, but (a) I wasn't able to get it to work the same as it's working right now, and (b) that funnels me into "sharing" logging level config across my webapps (in other words, webapp 1 can't have a different logging level for package x.y.z than webapp 2). Forget (b) for the time being, since I can live with shared logging levels across webapps. The main issue I'm having with this approach is that I can't seem to get *all* of my logging to go to my webapp-specific log file. Some stuff still gets logged to catalina.out. So... 1. Is it currently possible to do what I'm trying to do? Per-webapp logging control without using WEB-INF/classes/logging.properties? I could really use a working example if this is doable. 2. Is there any other hook I can take advantage of (i.e. a context listener or something), by which my code can get invoked prior to JULI initializing for my webapp, where I might be able to override the java.util.logging.config.file system property, or something like that? 3. If neither of those options is possible, how feasible would it be to add a feature to tomcat, where you can configure a path to logging.properties (in theory classpath: or file: style) on a per-webapp basis? i.e. in conf/server.xml in the . Or if there's an easier way, shove me toward it... Thanks, Dan