2

I have a relatively simple log4j configuration in Tomcat 8.0 on Windows

<Configuration>
    <Appenders>
        <File name="FileLog" fileName="${env:CATALINA_BASE}/logs/pidashboard.log">
            <PatternLayout pattern="%d %-5p [%t] %C{2} (%F:%L) - %m%n"/>
        </File>
    </Appenders>
    <Loggers>
        <Root level="debug">
            <AppenderRef ref="FileLog"/>
        </Root>
    </Loggers>
</Configuration>

on my development machine, filename resolves and the log is created appropriately. On my deployment machine, I get an error saying it can't create the file named - literally - ${env:CATALINA_BASE}/logs/pidashboard.log, if I change the line to the hardcoded path to which CATALINA_BASE resolves, the log gets created correctly.

These are fairly vanilla installations of Tomcat, so I'm unsure what's causing the difference. My development machine is running Windows 10 and my production machine is running Windows Server 2008, but I wouldn't expect that to impact this specific scenario.

Jim O'Neil
  • 23,344
  • 7
  • 42
  • 67

1 Answers1

0

If you are using Tomcat's Windows Service to launch Tomcat, then the environment variable CATALINA_BASE will not be set, so it wont be available. Try using the system property catalina.base instead of the environment variable CATALINA_BASE.

Christopher Schultz
  • 20,221
  • 9
  • 60
  • 77
  • that didn't seem to work.... I got a log file name in the literal directory ${catalina.base}, so doesn't seem like the resolution of the properties is working as a service? I'm using a relative directory now which puts the log in the right place for deployment (as a service), but creates a log/pidataboard.log in the bin directory of my dev machine. That's good enough for now, but surely there must be a way for this to work in both situations? – Jim O'Neil Jul 10 '15 at 17:14
  • So you tried `${catalina.base}` inside log4j.xml? Hmm. I've never used log4j's XML configuration, but I know this works for the `.properties`-file configuration. This is apparently [supposed to work](http://stackoverflow.com/questions/2810926/how-to-give-dynamic-file-name-in-the-appender-in-log4j-xml). – Christopher Schultz Jul 13 '15 at 17:17