logfellow / logstash-logback-encoder

Logback JSON encoder and appenders
Apache License 2.0
2.44k stars 407 forks source link

Empty | Null Pattern Layout | Ubuntu 22.04 #1053

Closed aniketsharma0211 closed 1 week ago

aniketsharma0211 commented 2 weeks ago

We decided to move from centOS to Ubuntu 22.04 for our Jenkins server. We use a common-framework dependency to manage the common-configurations across all of our spring-boot micro-services. This common framework has the logback-configuration.xml which has the logging pattern configuration.

We have a micro-service A, which uses common-framework dependency. We successfully built the common framework and service A, but while deploying to Kubernetes we got the below exception,

java.lang.IllegalStateException: Logback configuration error detected:
ERROR in ch.qos.logback.classic.PatternLayout("") - Empty or null pattern.
ERROR in ch.qos.logback.classic.PatternLayout("") - Empty or null pattern.
at org.springframework.boot.logging.logback.LogbackLoggingSystem.loadConfiguration(LogbackLoggingSystem.java:179)
at org.springframework.boot.logging.AbstractLoggingSystem.initializeWithConventions(AbstractLoggingSystem.java:80)
at org.springframework.boot.logging.AbstractLoggingSystem.initialize(AbstractLoggingSystem.java:60)

In the environment we use this encoder class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder" to encode the log pattern into a JSON structure using this appender class="ch.qos.logback.core.ConsoleAppender".

Configuration -

<springProfile name="!LOCAL">
        <appender name="STDOUT-APPLOG" class="ch.qos.logback.core.ConsoleAppender">
            <encoder
                    class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
                <providers>
                    <timestamp>
                        <timeZone>${API_USER_TIMEZONE}</timeZone>
                    </timestamp>
                    <pattern>
                        <pattern>
                            {
                            "host":"${HOSTNAME}",
                            "env":"${PROFILE}",
                            "logLevel": "%level",
                            "jsessionId":"%X{JSESSIONID}"
                            }
                        </pattern>
                    </pattern>
                </providers>
            </encoder>
        </appender>
        <appender name="stdOutAsyncFile" class="ch.qos.logback.classic.AsyncAppender">
            <queueSize>10000</queueSize>
            <discardingThreshold>0</discardingThreshold>
            <appender-ref ref="STDOUT-APPLOG"/>
        </appender>
        <root level="ERROR">
            <appender-ref ref="stdOutAsyncFile"/>
        </root>
        <logger name="com.academy" level="${LOGGING_LEVEL_COM_ACADEMY}" additivity="false">
            <appender-ref ref="stdOutAsyncFile"/>
        </logger>
        <appender name="STDOUT-AUDIT" class="ch.qos.logback.core.ConsoleAppender">
            <encoder
                    class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
                <providers>
                    <timestamp>
                        <timeZone>${API_USER_TIMEZONE}</timeZone>
                    </timestamp>
                    <pattern>
                        <pattern>
                            {
                            "host":"${HOSTNAME}",
                            "env":"${PROFILE}",
                            "logLevel": "%logger{0}",
                            }
                        </pattern>
                    </pattern>
                </providers>
            </encoder>
        </appender>
        <appender name="stdOutAuditAsyncFile" class="ch.qos.logback.classic.AsyncAppender">
            <queueSize>20000</queueSize>
            <discardingThreshold>0</discardingThreshold>
            <appender-ref ref="STDOUT-AUDIT"/>
        </appender>
        <logger name="AUDIT" level="INFO" additivity="false">
            <appender-ref ref="stdOutAuditAsyncFile"/>
        </logger>
    </springProfile>

We are using version 1.2.11 for logback, version 4.9 for net.logstash.logback.

The same configuration works on the local machine (windows/11) and when the image is built using the Jenkins-server running on the centOS.