17

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?

Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820
Morten
  • 420
  • 3
  • 10
  • [this](http://stackoverflow.com/questions/8383867/text-length-limit-in-logback-logging) might help. – Youssef NAIT Mar 01 '16 at 13:22
  • I found that post, but the solution in this example is to use a cxf class and i use the Play Framework. I found this post: http://stackoverflow.com/questions/32704470/can-a-logback-message-field-be-truncated-trimmed-to-n-characters So I will try that as soon as possible to if it is possible to truncate the messages also. – Morten Mar 01 '16 at 14:10

1 Answers1

21

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.

Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820
Morten
  • 420
  • 3
  • 10