java - Logging is not working. Logs are not written into file - Stack Overflow

I have an application with below log4j2.xml file embedded within the project. Logging is working fine i

I have an application with below log4j2.xml file embedded within the project. Logging is working fine in my local setup and also in this particular Linux server ( CPE OS Name: cpe:/o:redhat:enterprise_linux:7.9:GA:server ). However when we testing in this particular Linux server (CPE OS Name: cpe:/o:redhat:enterprise_linux:9::baseos) logs are not getting written in mentioned path. I have doublechecked with the permission issue & folder creation and I don't see any issue in that.

Log4j2.xml

<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
        <Properties>
                <Property name="base_log">/com/logs/testing/</Property>
                <Property name="testing_utility_log">${base_log}/testing_utility.log</Property>
        </Properties>
        <Appenders>
                <RollingFile name="testing_utility" fileName="${testing_utility_log}" filePattern="${testing_utility_log}_%d{dd-MM-yyyy}" ignoreExceptions="false">
                        <PatternLayout>
                                <Pattern>%d{HH:mm:ss,SSS}[%t] %-5p(%F:%L) - %m%n</Pattern>
                        </PatternLayout>
                        <TimeBasedTriggeringPolicy/>
                </RollingFile>
        </Appenders>
        <Loggers>
                <Root level="INFO">
                        <AppenderRef ref="testing_utility"/>
                </Root>
        </Loggers>
</Configuration>

and below dependency jars in the classpath.

commons-codec-1.16.1.jar
commons-io-2.15.1.jar
commons-lang3-3.12.0.jar
log4j-api-2.17.2.jar
log4j-core-2.17.2.jar
log4j-jul-2.17.2.jar
log4j-slf4j-impl-2.17.2.jar
slf4j-api-1.7.31.jar

In the code , I have this below logging related details

import .apache.logging.log4j.LogManager;
import .apache.logging.log4j.Logger;

private static final Logger LOGGER = LogManager.getLogger(Testing.class);
LOGGER.info("[Starting Testing for {} ] ", fileName);

**/// Local log trace**

09:52:33,349[main] INFO (Testing.java:39) - [Starting Testing for TEST45678 ] 

I have an application with below log4j2.xml file embedded within the project. Logging is working fine in my local setup and also in this particular Linux server ( CPE OS Name: cpe:/o:redhat:enterprise_linux:7.9:GA:server ). However when we testing in this particular Linux server (CPE OS Name: cpe:/o:redhat:enterprise_linux:9::baseos) logs are not getting written in mentioned path. I have doublechecked with the permission issue & folder creation and I don't see any issue in that.

Log4j2.xml

<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
        <Properties>
                <Property name="base_log">/com/logs/testing/</Property>
                <Property name="testing_utility_log">${base_log}/testing_utility.log</Property>
        </Properties>
        <Appenders>
                <RollingFile name="testing_utility" fileName="${testing_utility_log}" filePattern="${testing_utility_log}_%d{dd-MM-yyyy}" ignoreExceptions="false">
                        <PatternLayout>
                                <Pattern>%d{HH:mm:ss,SSS}[%t] %-5p(%F:%L) - %m%n</Pattern>
                        </PatternLayout>
                        <TimeBasedTriggeringPolicy/>
                </RollingFile>
        </Appenders>
        <Loggers>
                <Root level="INFO">
                        <AppenderRef ref="testing_utility"/>
                </Root>
        </Loggers>
</Configuration>

and below dependency jars in the classpath.

commons-codec-1.16.1.jar
commons-io-2.15.1.jar
commons-lang3-3.12.0.jar
log4j-api-2.17.2.jar
log4j-core-2.17.2.jar
log4j-jul-2.17.2.jar
log4j-slf4j-impl-2.17.2.jar
slf4j-api-1.7.31.jar

In the code , I have this below logging related details

import .apache.logging.log4j.LogManager;
import .apache.logging.log4j.Logger;

private static final Logger LOGGER = LogManager.getLogger(Testing.class);
LOGGER.info("[Starting Testing for {} ] ", fileName);

**/// Local log trace**

09:52:33,349[main] INFO (Testing.java:39) - [Starting Testing for TEST45678 ] 

Share Improve this question edited Mar 3 at 6:35 Chennai Cheetah asked Mar 3 at 6:06 Chennai CheetahChennai Cheetah 3631 silver badge15 bronze badges 3
  • @life888888 the tooltip for the Add a comment link states: Avoid answering questions in comments. This comment looks like an answer to me, so I'm curious why you don't post an answer? – Abra Commented Mar 3 at 6:43
  • @life888888 . I tried this approach. Still facing same issue. logs are not getting written – Chennai Cheetah Commented Mar 3 at 8:17
  • Can you run your application with -Dlog4j2.debug? The diagnostic output will be on stderr. – Piotr P. Karwasz Commented Mar 3 at 14:48
Add a comment  | 

2 Answers 2

Reset to default 1

Have you checked whether SELinux is affecting log writing? In RHEL 9, the Enforcing mode is enabled by default, which may restrict access to files even if standard permissions are set correctly. To verify if SELinux is causing the issue, you can temporarily disable it with:

sudo setenforce 0

This command temporarily switches SELinux to Permissive mode, where security checks are still performed but do not block operations and are only logged.

It is working now. I removed log4j2.xml from the project and instead added log4j2ponent.properties and pointed log4j2.xml path value in it.

log4j2ponent.properties

log4j.configurationFile=/com/logs/test/log4j2.xml

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745107903a4611668.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信