Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error using Logback Marker in FileAppender

I have started exploring Logback option for our application. One of the requirement is to create a separate log file for log entries that have a specific "Marker".

Below is the logback.xml file that i am using and the error I am getting. The examples on the logback website shows the usage of SMTPAppender but I would like to use FileAppender instead. Is this possible? If not, what other option do i have?

<property name="USER_HOME" value="c:/temp" />

<appender name="AUDIT_FILE" class="ch.qos.logback.core.FileAppender">        
    <evaluator class="ch.qos.logback.classic.boolex.OnMarkerEvaluator">
        <marker>APPEND_SYSLOG</marker>
    </evaluator>
    <file>${USER_HOME}/mw_syslog.log</file>        
    <encoder>
        <pattern>%date %level [%thread] %logger{10} [%file:%line] %msg%n</pattern>
    </encoder>
</appender>

<root level="debug">
    <appender-ref ref="AUDIT_FILE" />
</root>


    12:07:01,515 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource [logback.xml] at [file:/C:/JavaProjects/LogbackWeb/target/LogbackWeb-1.0-SNAPSHOT/WEB-INF/classes/logback.xml]
    12:07:02,013 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - debug attribute not set
    12:07:02,134 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.FileAppender]
    12:07:02,176 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [AUDIT_FILE]
    12:07:02,286 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@43:76 - no applicable action for [evaluator], current pattern is [[configuration][appender][evaluator]]
    12:07:02,286 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@44:21 - no applicable action for [marker], current pattern is [[configuration][appender][evaluator][marker]]
    12:07:02,310 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
    12:07:02,828 |-INFO in ch.qos.logback.core.FileAppender[AUDIT_FILE] - File property is set to [c:/temp/mw_syslog.log]
    12:07:02,836 |-INFO in ch.qos.logback.classic.joran.action.RootLoggerAction - Setting level of ROOT logger to DEBUG
    12:07:02,836 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [AUDIT_FILE] to Logger[ROOT]
    12:07:02,842 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration.
    12:07:02,855 |-INFO in ch.qos.logback.classic.joran.JoranConfigurator@3ad1a015 - Registering current configuration as safe fallback point
like image 324
user1082762 Avatar asked Jan 08 '13 06:01

user1082762


People also ask

How do I change the Logback configuration file?

Setting the location of the configuration file via a system property. You may specify the location of the default configuration file with a system property named "logback. configurationFile" . The value of this property can be a URL, a resource on the class path or a path to a file external to the application.

What are Appenders in Logback?

Appenders are named entities. This ensures that they can be referenced by name, a quality confirmed to be instrumental in configuration scripts. The Appender interface extends the FilterAttachable interface. It follows that one or more filters can be attached to an appender instance.

Where should the Logback XML be?

In a Spring Boot application, you can put the Logback. xml file in the resources folder. If your Logback. xml file is outside the classpath, you need to point to its location using the Logback.


1 Answers

In SMTPAppender the evaluator is used for triggering. In FileAppender, you need to encapsulate the evaluator within a filter, an evaluator filter to be precise. Here is an example:

<property name="USER_HOME" value="c:/temp" />

<appender name="AUDIT_FILE" class="ch.qos.logback.core.FileAppender">        
    <!-- the filter element -->
    <filter class="ch.qos.logback.core.filter.EvaluatorFilter">   
      <evaluator class="ch.qos.logback.classic.boolex.OnMarkerEvaluator">
        <marker>APPEND_SYSLOG</marker>
      </evaluator>
     <onMismatch>DENY</onMismatch>
     <onMatch>NEUTRAL</onMatch>
   </filter>
    <file>${USER_HOME}/mw_syslog.log</file>        
    <encoder>
        <pattern>%date %level [%thread] %logger{10} [%file:%line] %msg%n</pattern>
    </encoder>
</appender>

<root level="debug">
    <appender-ref ref="AUDIT_FILE" />
</root>
like image 168
Ceki Avatar answered Oct 13 '22 16:10

Ceki