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. webapps/mywebapp/WEB-INF/classes/logging.properties handlers = com.outerrim.catalina.logger.FileHandler com.outerrim.catalina.logger.FileHandler.directory = ${catalina.base}/logs com.outerrim.catalina.logger.FileHandler.prefix = mywebapp. webapps/my2ndwebapp/WEB-INF/classes/logging.properties handlers = com.outerrim.catalina.logger.FileHandler com.outerrim.catalina.logger.FileHandler.directory = ${catalina.base}/logs com.outerrim.catalina.logger.FileHandler.prefix = my2ndwebapp.
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.
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. http://markmail.org/message/6tvf3qiw32die2oc 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'. http://tomcat.apache.org/tomcat-7.0-doc/api/org/apache/catalina/util/ContextName.html#method_summary http://tomcat.apache.org/tomcat-7.0-doc/config/context.html#Naming Another solution for this step can be a Listener, like shown in above mentioned thread.
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).
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.
Thank you Mark! That's excellent news.
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.
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: https://tomcat.apache.org/tomcat-8.0-doc/logging.html