I have a java application running on windows machines.
Long story short, we have a convention for where we place log files per machine:
\\%COMPUTERNAME%\Logs\<AppNameHere>
So I configured my Java app to startup with -Dmachine.name=”%COMPUTERNAME%”, and then in my log4j.properties file I specify
log4j.appender.R.File = \\${machine.name}\Logs\MyVerySpecialApplicationName\log.log
But I’m not seeing that directory / file show up when I run my application (the first thing the app does is log a startup message).
So my guess is that log4j / java can’t process that windows specific UNC path.
Anyone else run into this issue and figure out a way around it?
I looked at Log4j’s source code. It appears to use
java.io.Fileto hold a reference to the filename you specify.Also, the Javadocs for
java.io.Filestate that UNC paths are supported for the constructor ofFile(which Log4J uses).So, on the surface, there’s no reason why your configuration won’t work; but — and that’s the important point to note — Java has a long history of problems with file I/O over SMB (which is pretty much what you’re trying to do).
My advice:
-Dlog4j.debug=true. The system property will make Log4J spit lots of debug information to help you track the problem.