Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Limit message size in logback

I have a play-application that uses logback. Some of the messages logged by one of the libraries are very large and fills my log with unnecessary statements.

What I want to do is log all messages but limit them on a certain size (e.q. 300 characters). Is there any way to do this?

like image 360
Morten Avatar asked Feb 29 '16 21:02

Morten


Video Answer


1 Answers

The format modifiers in the link did the trick. To truncate the message you can do it using %.-n where n is the maximum length:

    <encoder>
        <pattern>%d{dd-MM-yyyy HH:mm:ss.SSS} %-5level %logger{36} - %.-512msg%n</pattern>
    </encoder>

This modifier will truncate messages larger than 512 characters and put no padding on the left.

like image 69
Morten Avatar answered Sep 18 '22 12:09

Morten