Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xml inclusion does not work #63

Open
DemS98 opened this issue May 6, 2022 · 0 comments
Open

xml inclusion does not work #63

DemS98 opened this issue May 6, 2022 · 0 comments

Comments

@DemS98
Copy link

DemS98 commented May 6, 2022

In a Quarkus test project, I've defined a logback.xml inside src/main/resources with this inclusion

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <include resource="logger.xml" />

</configuration>

logger.xml is a file inside an external dependency, that contains the loggers definition

<?xml version="1.0" encoding="UTF-8"?>
<included>

    <conversionRule conversionWord="iso8601nano"
                    converterClass="com.dems98.test.log.converter.Iso8601NanoConverter" />

    <appender name="STDOUT"
              class="ch.qos.logback.core.ConsoleAppender">
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
            <level>INFO</level>
        </filter>
        <encoder>
            <pattern>%d{yyyy-MM-dd'T'HH:mm:ss.SSSZ} [%t] %-5level %logger{36} - %.-100000msg%n</pattern>
        </encoder>
    </appender>

    <if condition='"${LOG_DESTINATION:-FILE}".equals("FILE")'>
        <then>
            <appender name="ROLLING_FILE_SPRING_BOOT"
                      class="ch.qos.logback.core.rolling.RollingFileAppender">
                <file>/var/log/server/${NAME}.log</file>
                <rollingPolicy
                        class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
                    <fileNamePattern>/var/log/%d{yyyy-MM-dd_HH, UTC}.${NAME}.server-log.%i.zip</fileNamePattern>
                    <maxFileSize>100MB</maxFileSize>
                    <maxHistory>3</maxHistory>
                    <totalSizeCap>300MB</totalSizeCap>
                </rollingPolicy>
                <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
                    <level>INFO</level>
                </filter>
                <encoder>
                    <pattern>%d{yyyy-MM-dd'T'HH:mm:ss.SSSZ} [%t] %-5level %logger{36} - %.-100000msg%n</pattern>
                </encoder>
            </appender>
        </then>
    </if>

    <if condition='"${LOG_DESTINATION:-FILE}".equals("CONSOLE")'>
        <then>
            <appender name="ROLLING_FILE_APP"
                      class="ch.qos.logback.core.ConsoleAppender">
                <encoder class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
                    <providers>
                        <pattern>
                            <omitEmptyFields>true</omitEmptyFields>
                            <pattern>
                                {
                                        "timestamp": "%iso8601nano{UTC}",
                                        "correlation-id": "%mdc{correlation-id}",
                                        "message": "%.-100000msg%replace(%n%.-100000ex){'^\\s+$$',''}",
                                        "level": "%level",
                                        "version": "${VERSION}",
                                        "class": "%logger",
                                        "thread": "%t"
                                }
                            </pattern>
                        </pattern>
                    </providers>
                </encoder>
            </appender>
        </then>
        <else>
            <appender name="ROLLING_FILE_APP"
                      class="ch.qos.logback.core.rolling.RollingFileAppender">
                <file>/var/log/${NAME}.log</file>
                <rollingPolicy
                        class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
                    <fileNamePattern>/var/log/%d{yyyy-MM-dd_HH, UTC}.${NAME}.log.%i.zip</fileNamePattern>
                    <maxFileSize>100MB</maxFileSize>
                    <maxHistory>3</maxHistory>
                    <totalSizeCap>300MB</totalSizeCap>
                </rollingPolicy>
                <encoder class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
                    <providers>
                        <pattern>
                            <omitEmptyFields>true</omitEmptyFields>
                            <pattern>
                                {
                                        "timestamp": "%iso8601nano{UTC}",
                                        "correlation-id": "%mdc{correlation-id}",
                                        "message": "%.-100000msg%replace(%n%.-100000ex){'^\\s+$$',''}",
                                        "level": "%level",
                                        "version": "${VERSION}",
                                        "class": "%logger",
                                        "thread": "%t"
                                }
                            </pattern>
                        </pattern>
                    </providers>
                </encoder>
            </appender>
        </else>
    </if>

    <logger name="com.test" level="${LOG_LEVEL:-INFO}" additivity="false">
        <appender-ref ref="ROLLING_FILE_APP" />
    </logger>

    <root level="DEBUG">
        <appender-ref ref="STDOUT" />
        <if condition='"${LOG_DESTINATION:-FILE}".equals("FILE")'>
            <then>
                <appender-ref ref="ROLLING_FILE_SPRING_BOOT" />
            </then>
        </if>
    </root>
</included>

This configuration gives me this warning

WARN in ch.qos.logback.core.joran.util.ConfigurationWatchListUtil@4b06f969 - Null ConfigurationWatchList. Cannot add jar:file:///C:/Users/dems98/.m2/repository/com/dems98/1.8/test.jar!/logger.xml

and logs are not produced.

But, if I remove the inclusion and move the logger.xml content inside logback.xml, everything works!

So I believe there's a bug with the xml inclusions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant