Bug 43682 - JULI: web-inf/classes/logging.properties to support ${context} tag
Summary: JULI: web-inf/classes/logging.properties to support ${context} tag
Alias: None
Product: Tomcat 6
Classification: Unclassified
Component: Catalina (show other bugs)
Version: 6.0.14
Hardware: Other other
: P2 enhancement with 1 vote (vote)
Target Milestone: default
Assignee: Tomcat Developers Mailing List
Depends on:
Reported: 2007-10-23 07:03 UTC by Mailmur
Modified: 2017-01-18 22:05 UTC (History)
0 users


Note You need to log in before you can comment on or make changes to this bug.
Description Mailmur 2007-10-23 07:03:49 UTC
It would be a good to have "${context}" placeholder variable in JULI
logging.properties file. We could use it in a ".prefix" attribute to dynamically
use webapp's name as a file prefix.

Then if we have a web application, that can be installed 1...n copies to a same
Tomcat, we could use it out-of-the-box and each having separate log files.

  com.outerrim.catalina.logger.FileHandler.prefix = ${context}.

As it stands today, we must duplicate the webappname in a logging properties.

  handlers = com.outerrim.catalina.logger.FileHandler
  com.outerrim.catalina.logger.FileHandler.directory = ${catalina.base}/logs
  com.outerrim.catalina.logger.FileHandler.prefix = mywebapp.

  handlers = com.outerrim.catalina.logger.FileHandler
  com.outerrim.catalina.logger.FileHandler.directory = ${catalina.base}/logs  
  com.outerrim.catalina.logger.FileHandler.prefix = my2ndwebapp.
Comment 1 Jesse Barnum 2014-01-09 19:44:37 UTC
I need this feature as well. In my use case, I don't know what my users are going to name the application, and they could install multiple copies of the application with different names, so hard-coding the application name multiple times isn't a workaround.
Comment 2 Konstantin Kolinko 2014-01-09 20:11:11 UTC
I think a possible way to go is in two steps:

1. Allow ${jndi:...} properties in WEB-INF/classes/logging.properties file.

E.g. LogBack has similar feature. See 2013-03 thread "Register static JNDI env entry dynamically" on users@ for an example.

2. Allow ${catalina.context.xxx} substitutions in context.xml files, so that one could use it in an <Environment> element to configure a value for JNDI.

An open question to me is what kinds of '.xxx' are needed, to get something usable from a context name. Something like '.baseName', '.displayName', '.name', '.path', '.version'.


Another solution for this step can be a Listener, like shown in above mentioned thread.
Comment 3 Michael Osipov 2014-01-10 21:30:49 UTC
For what it's worth, I have writted a Listener for exactly that problem. It works flawlessly with Logback or anything else which is capable of using JNDI. See: http://mo-tomcat-ext.sourceforge.net/user-guide.html#LogbackContextNameListener

I did not write anything for JULI because that system is a dead end (imho).
Comment 4 Mark Thomas 2014-10-07 12:36:52 UTC
This has been fixed in 8.0.x for 8.0.15 onwards.

I do not intend to propose it for backport to 7.0.x or 6.0.x.
Comment 5 Jesse Barnum 2014-10-07 15:51:27 UTC
Thank you Mark! That's excellent news.
Comment 6 Jesse Barnum 2017-01-18 20:35:02 UTC
Mark, can you outline the expected behavior, or point to the relevant section of the docs?

In my context 'HelloWorld', I tried adding this to my logging.properties file:

1catalina.org.apache.juli.FileHandler.prefix = ${context}.

I expected that to create a log file named 'HelloWorld.2017-01-18.log'

What it actually created was a file named '${context}.2017-01-18.log'

Clearly, I'm misunderstanding how this should work. I am running version 8.5.11.
Comment 7 Jesse Barnum 2017-01-18 22:05:48 UTC
I found the correct substitution variables to use in the changelog:

Add support for referring to the current context, host and service name in per Context logging.properties files by using the properties ${classloader.webappName}, ${classloader.hostName} and ${classloader.serviceName}. (markt)

I can't find these variable names anywhere in the logging documentation, it would be great to add these to the docs, for example here: