Harmeet Singh Taara
Harmeet Singh Taara

Reputation: 6611

Logback: logger functions not print msg in console.

I am new with logging, and using logback for my project. I create the logger configuration file logback.xml at put at the class path in maven project this is at resource root folder. Following is my configuration file:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<contextName>It-Support</contextName>

<timestamp key="timeFormat" datePattern="yyyyMMdd'T'HHmmss" timeReference="contextBirth" />

<property resource="properties/logback-variables.properties" />

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
    <encoder>
         <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{5} - %msg%n</pattern>
    </encoder>
</appender>

<appender name="ROLLING" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>${file.record}/log.log</file>
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
        <fileNamePattern>log-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
        <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
            <maxFileSize>5MB</maxFileSize>
        </timeBasedFileNamingAndTriggeringPolicy>
        <maxHistory>6</maxHistory>
    </rollingPolicy>
    <encoder>
        <pattern>%d{HH:mm:ss} %contextName [%thread] %-5level %logger{36} - %msg%n</pattern>
    </encoder>
</appender>

<root level="DEBUG">
    <appernder-ref ref="STDOUT" />
    <!-- <appernder-ref ref="ROLLING" /> -->
</root>
</configuration>

In my java code, i am using logger.info, logger,error etc methods for print the information on console, but when the code is run, logger not able to print the information at eclipse console. My java code as below:

private Logger logger = LoggerFactory.getLogger(MachineController.class);
public String machinesList(Model model) {
    logger.info("call machinesList controller GET");
    ---------------------
}

When i start the tomcat, the server print below logs:

SEVERE: The web application [/it-support] created a ThreadLocal with key of type [com.microsoft.sqlserver.jdbc.ActivityCorrelator$1] (value [com.microsoft.sqlserver.jdbc.ActivityCorrelator$1@31924c14]) and a value of type [com.microsoft.sqlserver.jdbc.ActivityId] (value [b1d32454-45c4-4684-9339-b12835b563d2-0]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
15:13:00,945 |-INFO in ch.qos.logback.classic.LoggerContext[It-Support] - Could NOT find resource [logback.groovy]
15:13:00,946 |-INFO in ch.qos.logback.classic.LoggerContext[It-Support] - Could NOT find resource [logback-test.xml]
15:13:00,946 |-INFO in ch.qos.logback.classic.LoggerContext[It-Support] - Found resource [logback.xml] at [jar:file:/D:/tommy8/webapps/it-support-web/WEB-INF/lib/it-support-common-0.0.1-SNAPSHOT.jar!/logback.xml]
15:13:01,004 |-INFO in ch.qos.logback.core.joran.spi.ConfigurationWatchList@20b42477 - URL [jar:file:/D:/tommy8/webapps/it-support-web/WEB-INF/lib/it-support-common-0.0.1-SNAPSHOT.jar!/logback.xml] is not of type file
15:13:01,078 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - debug attribute not set
15:13:01,101 |-INFO in ch.qos.logback.classic.joran.action.ContextNameAction - Setting logger context name as [It-Support]
15:13:01,101 |-INFO in ch.qos.logback.core.joran.action.TimestampAction - Using context birth as time reference.
15:13:01,107 |-INFO in ch.qos.logback.core.joran.action.TimestampAction - Adding property to the context with key="timeFormat" and value="20150204T151300" to the LOCAL scope
15:13:01,111 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender]
15:13:01,119 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [STDOUT]
15:13:01,165 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
15:13:01,285 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.rolling.RollingFileAppender]
15:13:01,291 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [ROLLING]
15:13:01,361 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy - No compression will be used
15:13:01,365 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy - Will  use the pattern log-%d{yyyy-MM-dd}.%i.log for the active file
15:13:01,371 |-INFO in ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP@28345639 - The date pattern is 'yyyy-MM-dd' from file name pattern 'log-%d{yyyy-MM-dd}.%i.log'.
15:13:01,371 |-INFO in ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP@28345639 - Roll-over at midnight.
15:13:01,372 |-INFO in ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP@28345639 - Setting initial period to Thu Jan 08 20:09:57 IST 2015
15:13:01,375 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
15:13:01,381 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[ROLLING] - Active log file name: logs/log.log
15:13:01,381 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[ROLLING] - File property is set to [logs/log.log]
15:13:01,384 |-INFO in ch.qos.logback.classic.joran.action.RootLoggerAction - Setting level of ROOT logger to DEBUG
15:13:01,394 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@30:33 - no applicable action for [appernder-ref], current ElementPath  is [[configuration][root][appernder-ref]]
15:13:01,394 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration.
15:13:01,397 |-INFO in ch.qos.logback.classic.joran.JoranConfigurator@63f55760 - Registering current configuration as safe fallback point

Upvotes: 0

Views: 1889

Answers (1)

sheltem
sheltem

Reputation: 3825

It's "appender-ref", not "appernder-ref".

That is why your appender is not registered with the root-logger:

15:13:01,394 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@30:33 - no applicable action for [appernder-ref], current ElementPath  is [[configuration][root][appernder-ref]]

Upvotes: 1

Related Questions