Log Implementation in spring boot

Asked

Viewed 437 times

0

I implemented the LOG in my Spring Boot application but it generates entire files of several days would you like to partition per day as ? To make the configuration I am using in my Properties the following code:

logging.path=/home/app/logs/
logging.file=app-api.log

and in the log call I use this way :

private static final Logger LOGGER = LoggerFactory.getLogger(ProductController.class);

@GetMapping(path = "/list-all")
    public List<Product> listAllProduct(){
        try {
            return roductRepository.findAll();
        } catch (Exception e) {
            LOGGER.error("Erro ao efetuar a busca");
            e.printStackTrace();
            return null;
        }
    }

1 answer

0


You can use Logback and the following config snippet on logback.xml:

<appender name="TIME_BASED_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>/home/app/logs/app-api.log</file>
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">        
        <!-- daily rollover -->
        <fileNamePattern>/home/app/logs/app-api-%d{yyyy-MM-dd-HH-mm}.log</fileNamePattern>

    </rollingPolicy>

    ...

</appender>
  • OK I will use thank you very much

Browser other questions tagged

You are not signed in. Login or sign up in order to post.