Logback logger logging twice

后端 未结 3 470
忘掉有多难
忘掉有多难 2021-01-19 01:00

I would like to use slf4j+logback for two purposes in my application - log and audit.

For logging, I log the normal way:

static final Logger logger = L         


        
3条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-19 01:57

    Solutions:

    1. Add additivity="false" to the "AUDIT_LOGGER", as described in one of the answers above, to not inherit the appenders from the root logger.

    2. Remove the appender element from the "AUDIT_LOGGER". This will cause the "AUDIT_LOGGER" to inherit the appenders from the root logger.

    3. Be careful including other config files, which can also cause duplicate logging. In my case, I had to remove base.xml include block, which defines a root logger and appenders.

    
    

    NOTE: I would suggest defining the appenders outside of your loggers an referring to them by the appender-ref element. This way you can have multiple loggers referring to the same appender. See logback docs.

    
      
        %d{HH:mm:ss.SSS}|%msg%n
      
    
    
    
      
    
    
    
    

提交回复
热议问题