1

application i work will be created as jar file and run it through command line. there is no application servers involved. when i run the jar file below info from logback is printed on console. how do i suppress all logging from logback packages

13:46:30,534 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.groovy]
13:46:30,534 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback-test.xml]
13:46:30,534 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource [logback.xml] at [file:/Users/util/target/classes/logback.xml]
13:46:30,588 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - debug attribute not set
13:46:35,598 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender]
13:46:35,605 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [stdout]
13:46:35,621 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
13:46:35,629 |-WARN in ch.qos.logback.classic.encoder.PatternLayoutEncoder@326de728 - [outputPatternAsPresentationHeader] property is deprecated. Please use [outputPatternAsHeader] option instead.
13:46:35,661 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting additivity of logger [org.springframework] to false
13:46:35,661 |-INFO in ch.qos.logback.classic.joran.action.LevelAction - org.springframework level set to ERROR
13:46:35,661 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [stdout] to Logger[org.springframework]
13:46:35,661 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [ch.qos.logback] to OFF
13:46:35,661 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting additivity of logger [ch.qos.logback] to false
13:46:35,665 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@24:27 - no applicable action for [priority], current ElementPath  is [[configuration][root][priority]]
13:46:35,666 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [stdout] to Logger[ROOT]
13:46:35,666 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration.
13:46:35,666 |-INFO in ch.qos.logback.classic.joran.JoranConfigurator@25618e91 - Registering current configuration as safe fallback point

logback.xml

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

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

    <logger name="org.springframework" additivity="false">
        <level value="error"/>
        <appender-ref ref="stdout"/>
    </logger>

    <logger name="ch.qos.logback" level="OFF" additivity="false" />

    <root>
        <priority value="warn"/>
        <appender-ref ref="stdout"/>
    </root>

</configuration>

tried all options as well as discussion at thread Suppress all Logback output to console?.

nothing helped me, any pointers would be helpful. i am on logback version 1.0.13 and slf4j 1.7.5

Community
  • 1
  • 1
prred
  • 131
  • 1
  • 8

1 Answers1

5

First, the right way.

Fix the WARN/ERROR problems.

Here's the relevant logback docs. The status messages collected during logback initialization are printed to console if there are any ERROR or WARN level problems during init. So a good way to get rid of the console output is to fix the ERROR and WARN messages you are getting.

You can have a look at the source code of StaticLoggerBinder.

 if(!StatusUtil.contextHasStatusListener(defaultLoggerContext)) {
   StatusPrinter.printInCaseOfErrorsOrWarnings(defaultLoggerContext);
 }

It is not going through your registered logger because these are status messages generated before logback is initialised. It's a catch-22, you would need a properly configured logback context to log error messages about how it failed to start.

You can change what is done with these console messages but it might be your only insight into why logging isn't working.

One thing to fix in your config is to change the root to

<root level="WARN">
    <appender-ref ref="stdout"/>
</root>

There is an error message telling you that priority is not a valid element

13:46:35,665 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@24:27 - no applicable action for [priority], current ElementPath  is [[configuration][root][priority]]

Modify or suppress status message logging

Set a statusListener in your logback.xml

<configuration>
    <statusListener class="ch.qos.logback.core.status.OnConsoleStatusListener" />  
</configuration>

The options provided by logback are:

  • NopStatusListener : do nothing
  • OnConsoleStatusListener : log all status messages to stdout
  • OnErrorConsoleStatusListener : log all status messages to stderr
  • StatusListenerAsList : collect statuses in a list for you to access later
roby
  • 3,103
  • 1
  • 16
  • 14
  • Thanks roby for info, i have fixed warn and error messages as per your suggestion and kept statuslistener as NopStatusListener. now i don't see any logging info from logback – prred Dec 22 '16 at 13:01