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

Empty | Null Pattern Layout #16598

Open
kesrishubham2510 opened this issue Oct 24, 2024 · 0 comments
Open

Empty | Null Pattern Layout #16598

kesrishubham2510 opened this issue Oct 24, 2024 · 0 comments

Comments

@kesrishubham2510
Copy link

We decided to move from centOS to ubuntu 22.04 for our jenkins server. We have a common-framework dependency which we use 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, this uses common-framework dependency. We successfully built the common-framework and service A, but while deploying to kubernetes we got 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".

Sample 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 piece of configuration works on the local machine (windows/11) and when the image is built using the jenkins-server running on the centOS.

I tried the following configuration (keeping a single <pattern> inside the <providers>) as well, and with below configuration only timestamp is getting logged.

<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>
                            {
                            "host":"${HOSTNAME}",
                            "env":"${PROFILE}",
                            "logLevel": "%level",
                            "jsessionId":"%X{JSESSIONID}"
                            }
                        </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>
                            {
                            "host":"${HOSTNAME}",
                            "env":"${PROFILE}",
                            "logLevel": "%logger{0}",
                            }
                        </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>

Sample logs

{"@timestamp":"2024-10-23T05:18:17.776-05:00"}
{"@timestamp":"2024-10-23T05:18:17.786-05:00"}



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