简体   繁体   中英

how to remove xml file from one of the spring profiles

So I want to remove my log42.xml from one spring profile. How can I do this? I try to find some info in inte.net but it was no success. I know that I can map my xml to properties file, but I want to have xml file. This is my file main goal to have one profile for writing logs to Console other for File just for learning. This is my file code:

<?xml version="1.0" encoding="UTF-8"?>
<log4j:configuration xmlns:log4j='http://jakarta.apache.org/log4j/'
                     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                     xsi:schemaLocation="http://jakarta.apache.org/log4j/ http://jakarta.apache.org/log4j/ ">

    <Properties>
        <property name="FILE_PATTERN" value="%d{yyyy-MM-dd HH:mm:ss.SSS} [%-5level] %logger{0} %X{akkaSource} %msg%n"/>
        <property name="LOGS_BASE_DIRECTORY" value="logs"/>
        <property name="BASE_DIR" value="logs"/>
    </Properties>

    <Appenders>
        <Console name="CONSOLE" target="SYSTEM_OUT"/>

        <RollingFile name="SERVICE" fileName="logs/service.log"
                     filePattern="${LOGS_BASE_DIRECTORY}/archived/$${date:yyyy-MM}/service-%d{yyyy-MM-dd-HH-mm}-%i.log.gz">
            <PatternLayout>
                <Pattern>${FILE_PATTERN}</Pattern>
            </PatternLayout>

            <Policies>
                <SizeBasedTriggeringPolicy size="50 MB"/>
            </Policies>
        </RollingFile>

        <RollingFile name="CONTROLLER" fileName="logs/controller.log"
                     filePattern="${LOGS_BASE_DIRECTORY}/archived/$${date:yyyy-MM}/service-%d{yyyy-MM-dd-HH-mm}-%i.log.gz">
            <PatternLayout>
                <Pattern>${FILE_PATTERN}</Pattern>
            </PatternLayout>

            <Policies>
                <SizeBasedTriggeringPolicy size="50 MB"/>
            </Policies>

            <DefaultRolloverStrategy>
                <Delete basePath="${BASE_DIR}" maxDepth="2">
                    <IfLastModified age="3D"/>
                </Delete>
            </DefaultRolloverStrategy>
        </RollingFile>

        <RollingFile name="KAFKA" fileName="logs/kafka.log"
                     filePattern="${LOGS_BASE_DIRECTORY}/archived/$${date:yyyy-MM}/service-%d{yyyy-MM-dd-HH-mm}-%i.log.gz">
            <PatternLayout>
                <Pattern>${FILE_PATTERN}</Pattern>
            </PatternLayout>

            <Policies>
                <SizeBasedTriggeringPolicy size="50 MB"/>
            </Policies>

            <DefaultRolloverStrategy>
                <Delete basePath="${BASE_DIR}" maxDepth="2">
                    <IfLastModified age="3D"/>
                </Delete>
            </DefaultRolloverStrategy>
        </RollingFile>

        <RollingFile name="HIBERNATE" fileName="logs/hibernate.log"
                     filePattern="${LOGS_BASE_DIRECTORY}/archived/$${date:yyyy-MM}/service-%d{yyyy-MM-dd-HH-mm}-%i.log.gz">
            <PatternLayout>
                <Pattern>${FILE_PATTERN}</Pattern>
            </PatternLayout>

            <Policies>
                <SizeBasedTriggeringPolicy size="50 MB"/>
            </Policies>

            <DefaultRolloverStrategy>
                <Delete basePath="${BASE_DIR}" maxDepth="2">
                    <IfLastModified age="3D"/>
                </Delete>
            </DefaultRolloverStrategy>
        </RollingFile>
    </Appenders>

    <Loggers>
        <Logger name="ua.zhytariuk.planningsystem.controller" level="info">
            <appender-ref ref="CONTROLLER"/>
        </Logger>

        <Logger name="ua.zhytariuk.planningsystem.exception" level="error">
            <appender-ref ref="SERVICE"/>
        </Logger>


        <Logger name="ua.zhytariuk.planningsystem.aspect.ServiceLoggingAspect" level="trace">
            <appender-ref ref="SERVICE"/>
        </Logger>

        <Logger name="ua.zhytariuk.planningsystem.broker.kafka" level="debug">
            <appender-ref ref="KAFKA"/>
        </Logger>

        <Logger name="org.hibernate" level="debug">
            <appender-ref ref="HIBERNATE"/>
        </Logger>

        <root>
            <level value="debug"/>
        </root>
    </Loggers>

</log4j:configuration>

logging.config=classpath:log4j.xml

I write it from spring properties documentation. You can configure by logging.config property. You can only write property to application.properties file

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM