[logback-user] Logback configuration is coming as null

Debraj Manna subharaj.manna at gmail.com
Fri Jan 12 20:03:42 CET 2018


Correct restapilayer.logback.xml

<?xml version="1.0" encoding="UTF-8"?><configuration debug="true">

    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <layout class="ch.qos.logback.classic.PatternLayout">
            <encoder>
                %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n
            </encoder>
        </layout>
    </appender>

    <root level="DEBUG">
        <appender-ref ref="STDOUT" />
    </root>
</configuration>


Logs

18:58:45,418 |-INFO in ch.qos.logback.classic.LoggerContext[default] -
Found resource [/home/ubuntu/build-target/restapilayer/restapilayer.logback.xml]
at [file:/home/ubuntu/build-target/restapilayer/restapilayer.logback.xml]18:58:45,608
|-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to
instantiate appender of type
[ch.qos.logback.core.ConsoleAppender]18:58:45,611 |-INFO in
ch.qos.logback.core.joran.action.AppenderAction - Naming appender as
[CONSOLE]18:58:45,617 |-INFO in
ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming
default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for
[encoder] property18:58:45,645 |-INFO in
ch.qos.logback.classic.joran.action.RootLoggerAction - Setting level
of ROOT logger to DEBUG18:58:45,645 |-INFO in
ch.qos.logback.core.joran.action.AppenderRefAction - Attaching
appender named [CONSOLE] to Logger[ROOT]18:58:45,646 |-INFO in
ch.qos.logback.classic.joran.action.ConfigurationAction - End of
configuration.18:58:45,646 |-INFO in
ch.qos.logback.classic.joran.JoranConfigurator at 614ddd49 - Registering
current configuration as safe fallback point
INFO [2018-01-12 18:58:45]
c.v.c.u.CommonUtils:[c.v.c.u.CommonUtils:addDefaultExceptionHandler:1876]
- [main][CommonUtils.java:1876] - adding uncaught exception handler
hook...
log4j: Default initialization of overridden by
log4j.defaultInitOverrideproperty.
log4j:WARN No appenders could be found for logger (org.jboss.logging).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig
for more info.
INFO [2018-01-12 18:58:47] o.e.j.u.log:[?:?:?] - [main] - Logging
initialized @2260ms


Can someone let me know why my logback config is not getting picked?

On Fri, Jan 12, 2018 at 10:30 PM, Debraj Manna <subharaj.manna at gmail.com>
wrote:

> I am using logback 1.2.3. I am passing the logback configuration as
> -Dlogback.configurationFile=$SERVICE_PATH/restapilayer.logback.xml
>
> My restapilayer.logback.xml looks like below
>
> <?xml version="1.0" encoding="UTF-8"?><configuration>
>
>     <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
>         <layout class="ch.qos.logback.classic.PatternLayout">
>             <Pattern>
>                 %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n
>             </Pattern>
>         </layout>
>     </appender>
>
>     <root level="DEBUG">
>         <appender-ref ref="STDOUT" />
>     </root>
> </configuration>
>
> In my logs also I am seeing the configuration file being loaded.
>
> 16:25:32,564 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource [/home/ubuntu/build-target/restapilayer/restapilayer.logback.xml] at [file:/home/ubuntu/build-target/restapilayer/restapilayer.logback.xml]16:25:32,705 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - debug attribute not set16:25:32,706 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender]16:25:32,716 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [STDOUT]16:25:32,798 |-WARN in ch.qos.logback.core.ConsoleAppender[STDOUT] - This appender no longer admits a layout as a sub-component, set an encoder instead.16:25:32,798 |-WARN in ch.qos.logback.core.ConsoleAppender[STDOUT] - To ensure compatibility, wrapping your layout in LayoutWrappingEncoder.16:25:32,798 |-WARN in ch.qos.logback.core.ConsoleAppender[STDOUT] - See also http://logback.qos.ch/codes.html#layoutInsteadOfEncoder for details16:25:32,799 |-INFO in ch.qos.logback.classic.joran.action.RootLoggerAction - Setting level of ROOT logger to DEBUG16:25:32,799 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [STDOUT] to Logger[ROOT]16:25:32,800 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration.16:25:32,801 |-INFO in ch.qos.logback.classic.joran.JoranConfigurator at 76707e36 - Registering current configuration as safe fallback point
> 2018-01-12 16:25:32 [main] INFO  com.vnera.common.utils.CommonUtils - adding uncaught exception handler hook...
> log4j: Default initialization of overridden by log4j.defaultInitOverrideproperty.
> log4j:WARN No appenders could be found for logger (org.jboss.logging).
> log4j:WARN Please initialize the log4j system properly.
> log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
> INFO [2018-01-12 16:25:34] o.e.j.u.log:[?:?:?] - [main] - Logging initialized @1909ms
>
> Then while trying to log I am seeing the logback configuration as null and
> it seems logback is running with default config
>
> INFO [2018-01-12 16:25:34] c.v.r.c.v.r.VneraBackendService:[?:?:?] - [main] - Logback used _null_ as the configuration file_
>
> I am using the below code to get the logback config
>
> logger.debug("Testing Debug logging");LoggerContext loggerContext = ((ch.qos.logback.classic.Logger)logger).getLoggerContext();
> URL mainURL = ConfigurationWatchListUtil.getMainWatchURL(loggerContext);System.out.println(mainURL);// or even
> logger.info("Logback used '{}' as the configuration file.", mainURL);
>
> Can someone let me know what is going wrong? How can I debug this issue?
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.qos.ch/pipermail/logback-user/attachments/20180113/43ff7b3c/attachment-0001.html>


More information about the logback-user mailing list