My log4j2.xml is exactly the same as the one I've written for another similar server - which works perfectly well. The only differences are the file/server names and paths. Log4j1 worked fine too, it's just log4j2 that's causing problems. I'm starting to think I might have missed something in the linux config at this point. Things I've tried:
- Including log4j2.xml in the root directory of the project
- Including log4j2.xml in the
main.resourcesfolder of my project - Using
-Dlog4j.configurationFile="PATH"when running the jar (via systemd) - Verified the folder/log file are owned by the server user and server group
- Verified that the server has
rwpermissions for the file/folder - Verified that the server user is a member of the correct group
Also, when I run systemctl status -l on the server, the resulting output shows the log data as I expect to see it in the firmwareserver.log file.
My other server uses the log4j2.xml file from main.resources in the project without any issues.
EDIT: I should add, I'm developing this in eclipse on a windows machine, and when I run it there the log file saves as expected, even using the linux path it still works.
EDIT 2: I found the following error when I ran the jar file directly instead of as a systemd service:
2016-03-11 14:06:39,601 ERROR Unable to locate appender RollingFile for logger
Here's my Log4j2.xml:
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="DEBUG" monitorInterval="30">
<Properties>
<Property name="windows-log-path">C:/log4j/</Property>
<Property name="linux-log-path">/var/log/wsfirmwareserver</Property>
</Properties>
<Appenders>
<RollingFile name="RollingFile" fileName="${linux-log-path}/firmwareserver.log"
filePattern="${linux-log-path}/$${date:yyyy-MM}/firmwareserver-%d{yyyy-MM-dd}-%i.log">
<PatternLayout>
<pattern>%d{dd/MMM/yyyy HH:mm:ss,SSS}{GMT+1} [%-5p] [%t] - %c{1}: %m%n</pattern>
</PatternLayout>
<SizeBasedTriggeringPolicy size="5MB" />
<DefaultRolloverStrategy max="30" />
</RollingFile>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] - %m%n" />
</Console>
<SMTP name="SMTPAppender"
smtpProtocol="smtps"
smtpPort="465"
subject="LOC SERVER:Error"
to="[email protected], [email protected]"
from="[email protected]"
smtpHost="smtp.gmail.com"
smtpUsername="[email protected]"
smtpPassword="thepassword"
bufferSize="512">
<PatternLayout>
<pattern>%d{dd/MMM/yyyy HH:mm:ss,SSS}{GMT+1} [%-5p] [%t] - %c{1}: %m%n</pattern>
</PatternLayout>
</SMTP>
</Appenders>
<Loggers>
<Logger name="root" level="info" additivity="false">
<appender-ref ref="RollingFile" level="info" />
</Logger>
<Root level="debug" additivity="false">
<AppenderRef ref="Console" level="debug"/>
<AppenderRef ref="RollingFile" level="debug"/>
<AppenderRef ref="SMTPAppender" level="error"/>
</Root>
</Loggers>
</Configuration>
Anybody got any suggestions? Ideally I'd like to have the config file located in the same folder as the server jar, but at this point I just want it to log to the file properly.
/var/log/wsfirmwareserver? Which version of log4j are you using? If you create the timestamped directory,/var/log/wsfirmwareserver/2016-03for example, beforehand and don't trust log4j to create it, does this change anything? - user2845360log4j 2,2via maven, withlog4j-apiandlog4j-core. I haven't created the time-stamped directory, I didn't have to do that with the other server. I created thefirmwareserver.logfile though, as I had issues in the past when that wasn't created beforehand. I haven't checked the permissions all the way along the path, my other servers are fine, I never had to do that for them, and they are the same path except for the folder name at the end. But I'll take a look at which groups the various servers belong to. - mal