添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

try modifying your log4j2-test.xml file to match the following:

<?xml version="1.0" encoding="utf-8"?>
<configuration name="${sys:log_file}" status="warn"
    strict="true">
    <properties>
        <property name="rolling_log_file_name"
            value="${sys:log_file}" />
        <property name="app_log_folder"
            value="${rolling_log_file_name}" />
        <property name="app_log_base_directory"
            value="${sys:dtep.logs.home}${sys:file.separator}${app_log_folder}" />
        <property name="console_log_pattern"
            value="%date{yyyy-mm-dd hh:mm:ss.sss} %highlight{%5level} %style{%5processid}{normal, blue} --- [%15thread] %style{%logger{1.}}{normal, cyan} : %message%n%throwable%n" />
        <property name="file_log_pattern"
            value="%date{yyyy-mm-dd hh:mm:ss.sss} %5level %5processid --- [%15thread] %logger{1.} : %message%n%throwable%n" />
    </properties>
    <appenders>
        <appender type="console" name="console" target="system_out">
            <layout type="patternlayout" pattern="${console_log_pattern}" />
        </appender>
        <appender type="rollingfile" name="rollingfile"
            filename="${app_log_base_directory}${sys:file.separator}${rolling_log_file_name}.log"
            filepattern="${app_log_base_directory}${sys:file.separator}$${date:yyyy}${sys:file.separator}$${date:mmm}${sys:file.separator}${rolling_log_file_name}_%d{yyyy-mm-dd}_%i.log">
            <layout type="patternlayout" pattern="${file_log_pattern}" />
            <policies>
                <policy type="timebasedtriggeringpolicy" />
                <policy type="sizebasedtriggeringpolicy" size="1kb" />
            </policies>
            <strategy type="defaultrolloverstrategy" fileindex="nomax">
                <delete basepath="${app_log_base_directory}" maxdepth="5"
                    testmode="false">
                    <iffilename
                        glob="**${sys:file.separator}${rolling_log_file_name}_*.log">
                        <iflastmodified age="1m">
                            <ifany>
                                <ifaccumulatedfilesize exceeds="3 kb" />
                                <ifaccumulatedfilecount exceeds="3" />
                            </ifany>
                        </iflastmodified>
                    </iffilename>
                </delete>
            </strategy>
        </appender>
    </appenders>
    <loggers>
        <root level="trace">
            <appenderref ref="console">
                <filters>
                    <filter type="thresholdfilter" level="info" onmatch="accept"
                        onmismatch="deny" />
                </filters>
            </appenderref>
            <appenderref ref="rollingfile">
                <filters>
                    <filter type="thresholdfilter" level="info" onmatch="accept"
                        onmismatch="deny" />
                </filters>
            </appenderref>
        </root>
        <asynclogger name="org.springframework" level="info"
            additivity="false">
            <appenderref ref="console" />
            <appenderref ref="rollingfile" />
        </asynclogger>
        <asynclogger name="org.hibernate" level="info"
            additivity="false">
            <appenderref ref="console" />
            <appenderref ref="rollingfile" />
        </asynclogger>
    </loggers>
</configuration>
                                            

i faced this problem while upgrading to log4j 2.17.1 (due to those vulnerabilities). on my project i need to keep springboot 1.5.

i solved it just by placing the log4j2.xml file into the "resources" folder and not at the root folder as it was before. yes, it doesn't make sense. it doesn't need to be a complex xml, as mine is very simple, and doesn't need to have any property related to 'xwex'.

although on internet people say log4j 2.8+ and spring 1.5 are incompatible, it doesn't seem to be the cause of this specific problem.

i discovered it after trying a lot of possibilities, fighting with dependencies and finally getting hopeless and trying everything haha.

springboot1 default log4j.xml use pattern: %xwex is not supported by 2.8+, but we can override the pattern by set environment variable log_exception_conversion_word like: %throwable

@springbootapplication
public class application {
    public static void main(string[] args) {
        system.setproperty("log_exception_conversion_word", "%throwable");
        springapplication.run(application.class, args);
                                            

i think that existing answers are correct but incomplete.

you get that error if both the following conditions occur:

  • you are using an old version of spring-boot with a recent version of log4j2 (not ideal but possible; you are upgrading log4j2 due to "log4shell" vulnerability, right?)
  • you are using the default logging config file provided by spring-boot (it is /org/springframework/boot/logging/log4j2/log4j2.xml in spring-boot-x.x.x.release.jar). this is the real problem.
  • the default config file exists to allow a quick setup of new applications. unfortunately it is not compatible with log4j 2.8+.

    probably you want to use your own configuration and, perhaps, you have already prepared your config file but the application hasn't found it.

    possible solutions:

  • upgrade spring-boot or downgrade log4j2 (downgrading is not recommended, of course).

  • if you really want to use the default cfg (really?), set this environment variable: log_exception_conversion_word=%throwable as suggested by tsingke

  • ensure that your own log4j2.xml or, even better, log4j2-spring.xml is in the classpath or in a path pointed out by the logging.config environment variable (see custom log configuration).

    i have used solution #3.

    side note: if you upgrade log4j but continue using spring-boot 1.x you suffer from other vulnerabilities, so it should be just the first step, even if your boss (or your customer) only cares about log4shell!

    there is an issue reported that says spring boot 1.5 is not compatible with log4j 2.8. https://github.com/spring-projects/spring-boot/issues/9172

    i was getting errors like yours with spring boot 1.5 and log4j 2.8.2, and the errors away when i switched to log4j 2.7

    Related Query

  • Log4j2 - Unrecognized conversion specifier [xwEx] starting at position 160 in conversion pattern
  • About log4j2 memory leak when I raise an exception at spring boot starting
  • Spring-Boot project log4j to log4j2 conversion Issue
  • Spring boot 2.1.x app with log4j2 only dependency starting twice it seems
  • Log4j2 not logging when starting spring as linux service
  • How can I configure the heap size when starting a Spring Boot application with embedded Tomcat?
  • Why do I get Gson builder error when starting a Spring Boot application?
  • How to prevent embedded netty server from starting with spring-boot-starter-webflux?
  • Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled
  • Spring Boot: run liquibase migrations without starting app
  • Spring Profiles, different Log4j2 configs
  • Upgraded spring boot from 2.1.9 to 2.2.0 , now getting exception while starting
  • How to set up Spring Boot and log4j2 properly?
  • Spring boot stops after starting
  • spring boot rabbitmq MappingJackson2MessageConverter custom object conversion
  • Spring Boot 2 fails starting due to Hystrix?
  • Maven error occurred in starting fork, check output in log
  • Log4j2 including library name in stacktrace
  • RMI TCP connection error when starting Spring Boot application
  • Spring-boot error starting tomcat context. Error creating bean with name 'servletEndpointRegistrar'
  • Starting Spring Application by merging yml files
  • Error starting spring boot "An attempt was made to call a method that does not exist"
  • Spring boot Log4j2 version 2.15.0 EMPTY_BYTE_ARRAY error in wildfly server
  • How to make Log4j2 configurable by environment using Spring Boot 1.3.6.RELEASE
  • Spring boot application shutdown immediate after starting
  • Add MDC variables in JsonLayout - log4j2
  • Spring boot stops after starting on server
  • Spring-boot : how to execute multiple test classes by just starting the service once using rest-assured
  • Spring Starting throws an exception
  • Logback conversion rule parametrizing
  • More Query from same tag

  • java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory Spring boot 1.5.2 maven
  • Generate test-jar of unit testing project and use in other maven projects
  • Use logback config file not on classpath for spring boot application
  • Using Spring Boot, QueryDSL, and Springfox Swagger together - Guava version mismatch
  • TransientObjectException when saving a Map attribute in Spring Boot
  • Spring Boot ClassNotfoundException EmbeddedServletContainerCustomizer
  • Spring boot application I can not get data from oracle database it returns [] in postman
  • Run a docker image with java and python
  • Spring RestTemplate netflix loadblancer not configuring httpClient header Host
  • downloading large file throws OutOfMemoryError in production env
  • Spring/Spring Boot conversion - how to make a chain on Converters?
  • EntityManager createQuery with single column throws type error
  • GemFire Cache expiration or eviction at a particular time of the day
  • Parse Timestamp in Java
  • Hibernate cache levels 1 and 2
  • Running Tasks in different thread in Spring Webflux Annotated controller
  • In my Swagger2 documentation of Spring Boot I get Timestamp fields documentation as a JSON object
  • SpringBoot: Providing Values from shell script to Externalization of Property Files in Spring Boot
  • Prevent response in controller
  • Ways to handle error in CompletableFuture in Java
  • Not able to build a jar in google Cloud Build
  • Spring Cloud Data Flow Scaling with Apache Kafka
  • How to read variable or concatenate one property in @Value annotation of spring boot
  • Spring Cloud Config dual bootstrap files behavior
  • Spring boot profile based WAR using maven
  • cannot load/fetch mapped collection in hibernate criteria request
  • How to change the database name dynamically in MyBatis XML file?
  • How to handle 401 unauthorized error in Springboot app
  • Tomcat7 rewrites my context.xml when extracting war file
  • Current timeStamp is not getting automatically saved into the table with jpa
  •