Logback Groovy Configuration is slow

I was using the Logback Groovy config and now I found out that this is the reason for the very slow startup. The application HelloWorld

takes about one second. I didn't notice slowdowns earlier in the context of a webserver, but now that I often need to run fairly simple tools this is not acceptable.

Q1: I still can't believe it as my config file is small and one second is huge, so can anyone confirm this?

I can imagine to easily rewrite everything but one part in XML. The problematic part is my own filter and two of its methods, for example

public class MyLogbackFilter extends Filter<ILoggingEvent> {
    public MyLogbackFilter accept(String prefix, Level level) {...}
    public MyLogbackFilter accept(String prefix, Level level) {...}
   ...
}

      

configured via something like

filter = new MyLogbackFilter()
    .accept("com.example.pck1.Class1", TRACE)
    .accept("com.example.pck1.Class2", TRACE)
    .deny("com.example.pck1", TRACE)
    .accept("", WARNING)
    .deny("", INFO);

      

Rules are evaluated from top to bottom, for example, everything from com.example.pck1.Class1

level TRACE

or higher is accepted, regardless of what is specified later.

Q2: Can I somehow make a log by reading the config file like

A com.example.pck1.Class1 TRACE
A com.example.pck1.Class2 TRACE
D com.example.pck1 TRACE
A * WARNING
D * INFO

      

and pass it to my class? Then the interpretation is peanuts.

+3


source to share


1 answer


Regards, I never know what you can do nders by class, BUT you can just add xml config file to your project and log libraries try to find xml in classpath (usually in maven you put xml in resource file) ...

The file can be as follows:



<?xml version="1.0" encoding="UTF-8"?>
  <configuration>
    <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
      <file>/usr/java/logs/floresTrace.log</file>
        <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
          <fileNamePattern>/path/to/file/myfile.%i.log.zip</fileNamePattern>
          <minIndex>1</minIndex>
          <maxIndex>3</maxIndex>
        </rollingPolicy>

        <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
          <maxFileSize>1MB</maxFileSize>
        </triggeringPolicy>
        <encoder>
          <pattern>%d{YYYY-MM-dd HH:mm:ss} %level [%thread] %logger{10} [%file:%line]   %msg%n</pattern>
       </encoder>
</appender>
<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>
<!-- you can, however add loggers by package here-->
<logger name="your.package.one" level="DEBUG"/>
<logger name="your.package.two" level="INFO"/>

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

      

So, as the comment says, you can add registrars by package. hope this helps.

0


source







All Articles