Question

I want to populate "dir" in accesslogvalve from a value from setenv.bat. Ex:

<Valve
className="org.apache.catalina.valves.AccessLogValve"
directory="${my.logs.dir}"
prefix="access_log"
fileDateFormat="yyyy-MM-dd.HH"
suffix=".log"
pattern="%t %H cookie:%{SESSIONID}c request:%{SESSIONID}r  %m %U %s %q %r"/>

I have specified "my.logs.dir" in setenv.bat

set my.logs.dir=C:\xyz\abc

When I start the tomcat, I see a folder ${my.logs.dir} under tomcat installation. The issue is that ${my.logs.dir} was not replaced by env variable when tomcat startsup. If I give hard coded value like dir="C:\xyz\abc", it works fine.

Could anyone guide me to replace ${my.logs.dir} with a value from environment at server startup time?

Thanks

Was it helpful?

Solution

I don't think environment variables are available by default in Tomcat configuration files. System properties, however, are. So if you add your variable as a system property instead of an environment variable, it should work.

If you for some reason absolutely have to use environment variables, the Tomcat documentation has a reference to Property replacements in it's section about System Properties that can be set to customize Tomcat behaviour:

org.apache.tomcat.util.digester. PROPERTY_SOURCE

Set this to a fully qualified name of a class that implements org.apache.tomcat.util.IntrospectionUtils.PropertySource. Required to have a public constructor with no arguments.

Use this to add a property source, that will be invoked when ${parameter} denoted parameters are found in the XML files that Tomcat parses.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top