log4j2

Spring application without web.xml log4j configuration

谁都会走 提交于 2020-02-22 07:51:06
问题 I have a Spring + Jersey web application that I'm migrating from a web.xml to annotation base configuration. I'm implementing WebApplicationInitializer and everything works except log4j, because I have a custom file name. In the web.xml I had <context-param> <param-name>log4jConfiguration</param-name> <param-value>/WEB-INF/custom-name-log4j.xml</param-value> </context-param> This worked. Now, I tried to do the same in Java: container.setInitParameter("log4jConfiguration", "/WEB-INF/custom

Log4J 2 not writing into file

偶尔善良 提交于 2020-02-08 04:14:25
问题 I am trying to implement some logging using log4j 2. The console output is ok, but when I try to write some logs into file I cannot manage it. My pom.xml : <dependencies> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-api</artifactId> <version>2.8</version> </dependency> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-core</artifactId> <version>2.8</version> </dependency> </dependencies> My log4j2.xml : <?xml version="1.0" encoding="UTF-8

Log4j2 in spring boot is not using the pattern in the XML file

我只是一个虾纸丫 提交于 2020-02-07 04:05:46
问题 I have a spring boot project, this is how I use the logger: import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; class MyController{ private static final Logger log = LogManager.getLogger(MyController.class); public void do(){ log.error("test"); } } and src/main/resources/log4j2.xml <?xml version="1.0" encoding="UTF-8"?> <Configuration status="INFO"> <Appenders> <Console name="console" target="SYSTEM_OUT"> <PatternLayout pattern="-- %msg%n --" /> </Console> <

Log4j2 in spring boot is not using the pattern in the XML file

前提是你 提交于 2020-02-07 04:05:07
问题 I have a spring boot project, this is how I use the logger: import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; class MyController{ private static final Logger log = LogManager.getLogger(MyController.class); public void do(){ log.error("test"); } } and src/main/resources/log4j2.xml <?xml version="1.0" encoding="UTF-8"?> <Configuration status="INFO"> <Appenders> <Console name="console" target="SYSTEM_OUT"> <PatternLayout pattern="-- %msg%n --" /> </Console> <

log4j2 Default rollover strategy not deleting logs

这一生的挚爱 提交于 2020-02-05 03:53:09
问题 I have log4j2 with a default rollover strategy set up like this - <RollingFile name="RollingFile" fileName="cc" filePattern="logs/${baseFileName}-%d{yyyy-MM-dd}.log.gz"> <PatternLayout> <pattern>%d{dd/MMM/yyyy HH:mm:ss,SSS}- %c{1}: %m%n</pattern> </PatternLayout> <Policies> <TimeBasedTriggeringPolicy interval="1" modulate="true" /> </Policies> <DefaultRolloverStrategy> <Delete basePath="logs/"> <IfFileName glob="logs/${baseFileName}-*.log" /> <IfLastModified age="2d" /> </Delete> <

slf4j in library seems to ignore my log4j2 configuration

牧云@^-^@ 提交于 2020-02-05 03:49:09
问题 We use Log4j2 in our java-ee application. We use a library, where logging is programmed against SLF4J. In this library is a class, which logs a lot of stuff I do not want -> so I want to set LogLevel of this Logger to OFF. My log4j2.xml looks like this: <?xml version="1.0" encoding="UTF-8"?> <Configuration status="trace" shutdownHook="disable"> <Appenders> <Console name="ConsoleAppender" target="SYSTEM_OUT" ignoreExceptions="false" > <PatternLayout pattern="%d{ISO8601} %d{HH:mm:ss.SSS} [%t] %

How to remove appender from logger in log4j2 programmatically?

匆匆过客 提交于 2020-02-03 04:34:46
问题 Is there any way I can remove appender from a logger in log4j2 programmatically ? The website says "Log4j 2 API does not expose methods to add, modify or remove appenders and filters or manipulate the configuration in any way" : https://logging.apache.org/log4j/2.x/manual/configuration.html But i would really appreciate if someone can suggest an indirect way to achieve this. Thanks. 回答1: There is a method LoggerConfig#removeAppender(String name) which will remove specific appender and

Apache Log4j2 package specific logging using log4j2.xml

随声附和 提交于 2020-02-03 03:57:08
问题 I am using log4j2. But the problem that I am facing is that it logs all logs. I want to ... log from specific package to a specific file & other package to another file. I am using log4j2.xml for configuration. Please can someone help? log4j2.xml <?xml version="1.0" encoding="UTF-8"?> <Loggers> <Root level="DEBUG" additivity="false"> <AppenderRef level="DEBUG" ref="CONSOLE" /> <AppenderRef level="DEBUG" ref="fileAppender" /> </Root> <Logger name="com.pkg.test.logging.method" level="DEBUG"

Log4j2 Kafka appender does not work with Spark Streaming Kafka Consumer

笑着哭i 提交于 2020-02-02 17:39:08
问题 When I use log4j2 kafka appender with my spark streaming code, it throws below error when spark.sql task is executed. Caused by: org.apache.kafka.common.KafkaException: org.apache.kafka.common.serialization.ByteArraySerializer is not an instance of org.apache.kafka.common.serialization.Serializer at org.apache.kafka.common.config.AbstractConfig.getConfiguredInstance(AbstractConfig.java:372) The spark streaming code is written in scala. My build.gradle.kts has below dependencies. I am using

Log4j2配置与自定义

无人久伴 提交于 2020-02-01 01:52:14
新需求要在log4j上做些自定义的东西,所以补了log4j2这一块的东西 配置 先看下log4j2的传统配置 <?xml version="1.0" encoding="UTF-8"?> < Configuration status = " WARN " > < properties > < property name = " log_path " > C:/ </ property > < property name = " file_name " > file.log </ property > < property name = " root_level " > error </ property > </ properties > < Appenders > <!--console :控制台输出的配置--> < Console name = " Console " target = " SYSTEM_OUT " > < PatternLayout pattern = " %d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n " /> </ Console > <!--File :同步输出日志到本地文件 append:是否追加写--> < File name = " log " fileName = " $