In this post, I would demo how to print or show line number of loggers in SpringBoot applications.
By default, SpringBoot does not print or show linenubmer of loggers, just like this:
How should we do when we want to print or show the logger’s linenubmer?
- SpringBoot 1.x and 2.x
3. The solution
Change your SpringBoot’s application.properties file like this:
And rerun your application, you would get this log:
Pay attention to the %L of the logging.pattern.console, it means the linenumber of the logger.
4. The SpringBoot logging properties
There are some logging pattern properties in SpringBoot apps:
The pattern is provided by logback.
5. LogBack pattern variables
By default, SpringBoot depends on the slf4j and logback, you can specify the logback layout patterns as follows:
- L / line
- Outputs the line number from where the logging request was issued.Generating the line number information is not particularly fast. Thus, its use should be avoided unless execution speed is not an issue.
- t / thread
- Outputs the name of the thread that generated the logging event.
- Outputs the platform dependent line separator character or characters.This conversion word offers practically the same performance as using non-portable line separator strings such as “\n”, or “\r\n”. Thus, it is the preferred way of specifying a line separator.
If you want to specify the logging layout patterns in SpringBoot apps, you can specify the logging.pattern.console or logging.pattern.file in the application.properties, the pattern variables is provided by logback.