Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to shorten thread name in logback logs?

You can shorten the name of the logger using %logger{x} syntax where x controls shortening procedure. Is there any way to shorten the name of the thread the same way?

like image 782
Vladislav Rastrusny Avatar asked May 07 '11 21:05

Vladislav Rastrusny


People also ask

What is logger name in Logback xml?

Logback Architecture A Logger is a context for log messages. This is the class that applications interact with to create log messages. Appenders place log messages in their final destinations. A Logger can have more than one Appender.

How do I print the thread ID in Logback?

so just write %t on your configuration file in logback. xml reference document : Link and find Outputs the ID of the thread that generated the logging event. [%t] prints thread name not thread id with logback.

What is Ch QOS Logback?

GitHub - qos-ch/logback: The reliable, generic, fast and flexible logging framework for Java.

What is root tag in Logback?

In a Logback. xml file, all the configuration options are enclosed within the <configuration> root element. In the root element, you can set the debug=true attribute to inspect Logback's internal status. You can also configure auto scanning of the configuration file by setting the scan=true attribute.


2 Answers

[%.7thread]

This will print the last 7 characters of the thread name.

Trailing characters of a thread name are often more interesting than the characters at the beginning of a thread name. :-)

You may read about the maximum field width modifier in the logback docs.

like image 106
broc.seib Avatar answered Sep 20 '22 14:09

broc.seib


You can use:

[%.-10t]

This expression prints the first 10 chars of the thread name.

like image 33
Luciano Fiandesio Avatar answered Sep 17 '22 14:09

Luciano Fiandesio