java – Log4j2 .xml file configuration on Linux

Good Morning

I am having trouble setting the path of my project log file on a Google Cloud Linux virtual machine (Ubuntu 18.04).

Initially I did tests with the Windows operating system and entered the path (C: logs), and it worked normally. However, if I try to replace a Linux path, it will not work (/ opt / tomcat). Below is the configuration I'm using.

Set up

                %d{yyy-MM-dd HH:mm:ss.SSS} (%t) %level %logger{36} - %msg%n
                %d{yyy-MM-dd HH:mm:ss.SSS} (%t) %level %logger{36} - %msg%n

This is the configuration I want to use for Linux. For Windows I have replaced that to:


java – No error was found in the log4j2 configuration file unless the log4j2.xml file is in two folders at the same time

I have a project structure like this:

project name
Web App

So there are two possible scenarios:

  1. log4j2.xml is in both resources and classes folder
  2. log4j2.xml is located only in resources
  3. log4j2.xml is located only in classes

In the first scenario the code

Logger logger = LogManager.getLogger (MyClass.class);
logger.debug ("debug log message"); ("Info log message");
logger.error ("error log message");

works well.

In the second scenario, it does not work in most cases, but sometimes it works and seems to copy the file classes Folder.

In the third scenario it sometimes works, sometimes it does not and deletes the file from classes,

With & # 39; work & # 39; I mean that the debug messages are printed out with & # 39; work & # 39; I mean that the error is printed No error was found in the log4j2 configuration file,

I thought it would search for the file in the folders of the project and use it as soon as it was found without any problems. But here it only seems to work if it's in both resources and classes Folder and I do not understand why.

log4j2 – How do I write an appender that handles only exceptions and yet logs all other logs normally through a root console appper

I have a situation where log.error ("message", exception); I'd like to have a logic to send the exception to an external tool while maintaining regular logging for the row to the root appender.

As an example, here is a code and the expected result:

To attempt {
} catch (exception ex) { ("abcd");
LOG.error ("failed to XYZ", ex);

Rough result:

2019-03-05 13:00:20 INFO Main: 75 - abcd
2019-03-05 13:00:20 ERROR Main: 76 - XYZ failed -
Exception: exception message

While this is being logged, I also want the exception to be sent over a different code path.

How can I do that? I'm a bit stuck, does anyone know good instructions?

logging – log4j2 in tomcat 8: Unexpected log rotation

I tried to fix a log rotation problem with log4j2 in a webapp that is running Apache Tomcat / 8.0.32 (Ubuntu) on Ubuntu 16.04.4 (See related stackoverflow question).
Tomcat keeps running OracleJRE 1.8.0_181,

I have migrated the complete Apache Tomcat installation from the Tomcat implementation java.utils.logging (Tomcat JULY) to log4j2: Integration of the Log4j App Server.

It works fine, but I have the problem that affected the webapp now on Tomcat as well. The log files appear to be rotated at midnight and gzip-packed, but no new log files are created. The log files are written below / var / log / tomcat /,

I'm assuming that this is more of a system process that turns the log files into a Tomcat error. The server uses systemdWith systemd-TMPFILES clean.timer activated and rsyslog.service activated and executed

does systemd-TMPFILES clean.timer does the log files spin or does another system process rotate the logs? If so, how can I exclude the directory / var / log / tomcat / from the log rotation of the process?