How to configure logback-access.xml using Spring

My application.yml:

server: tomcat: accesslog: enabled: true basedir: my-tomcat 

We are using spring boot 1.4.3.RELEASE, and I would like to configure logback-access.xml (in the src / main / resources section) with the following contents:

 <?xml version="1.0" encoding="UTF-8"?> <configuration> <!-- always a good activate OnConsoleStatusListener --> <statusListener class="ch.qos.logback.core.status.OnConsoleStatusListener" /> <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> <encoder> <pattern>%h %l %u %user %date "%r" %s %b</pattern> </encoder> </appender> <appender-ref ref="STDOUT" /> </configuration> 

I can see the access_log.2017-01-03.log file in the my-tomcat folder with the correct access logs, but marking on my coincidence it seems that the logback-access.xml configuration file is not being read.

Any idea?

Eric

+5
source share
1 answer

Am I mistaken or is this not supported initially by Spring Boot?

Source: https://github.com/spring-projects/spring-boot/issues/2609 :

Hey, I'm trying to access the + tomcat log working from spring boot. Has anyone been able to get this finished program? Or is there any necessary plumbing to configure?

...

 As a workaround, you can copy the access xml from the class path to the filesystem and run it there as part of your configuration class Files.copy(this.getClass().getResourceAsStream("/logback-access.xml"),Paths.get("log-access.xml"),StandardCopyOption.REPLACE_EXISTING); logbackValve.setFilename("log-access.xml"); 

Decision

Use spring-boot-ext-logback-access :

Just adding a dependency should do this:

 <dependency> <groupId>net.rakugakibox.spring.boot</groupId> <artifactId>logback-access-spring-boot-starter</artifactId> <version>2.7.0</version> </dependency> 

Edit - another solution for magazine 1.1.6 +

In the spring boot issues mentioned above , someone posted this:

Since logback 1.1.6 does not require any workarounds to load the log access configuration file as a resource. Link: http://jira.qos.ch/browse/LOGBACK-1069

All you have to do is: logbackValve.setFilename("log-access.xml");

+3
source

Source: https://habr.com/ru/post/1262235/


All Articles