{"id":2512,"date":"2016-04-29T07:25:56","date_gmt":"2016-04-29T11:25:56","guid":{"rendered":"http:\/\/springframework.guru\/?p=2512"},"modified":"2024-10-18T08:37:46","modified_gmt":"2024-10-18T12:37:46","slug":"using-logback-spring-boot","status":"publish","type":"post","link":"https:\/\/springframework.guru\/using-logback-spring-boot\/","title":{"rendered":"Using Logback with Spring Boot"},"content":{"rendered":"\n<p>In this post we will explore using Spring Boot&#8217;s default logging framework, Logback.<\/p>\n\n\n\n<p>Logback makes an excellent logging framework for enterprise applications. It\u2019s fast, and has simple but powerful configuration options, and comes with a small memory footprint. I introduced logback in my introductory post, <a href=\"http:\/\/springframework.guru\/logback-enterprise-logging-framework-2\/\" target=\"_blank\" rel=\"noopener noreferrer\" title=\"Logback Introduction\">Logback Introduction: An Enterprise Logging Framework<\/a>.<\/p>\n\n\n\n<p>In a series of posts on Logback, I&#8217;ve also discussed how to configure Logback using XML and Groovy. The posts are available as <a title=\"Logback Configuration: using XML\" href=\"http:\/\/springframework.guru\/logback-configuration-using-xml\/\" target=\"_blank\" rel=\"noopener noreferrer\">Logback Configuration: using XML<\/a> and <a title=\"Logback Configuration: using Groovy\" href=\"http:\/\/springframework.guru\/logback-configuration-using-groovy\/\" target=\"_blank\" rel=\"noopener noreferrer\">Logback Configuration: using Groovy<\/a>.<\/p>\n\n\n\n<p>In this post, I\u2019ll discuss how to use Logback with Spring Boot. While there are a number of logging options for Java, the Spring Boot chose to use Logback for the default logger. Like many things in Spring Boot, Logback, by default, gets configured with sensible defaults. <\/p>\n\n\n\n<h1 class=\"wp-block-heading\">Log Levels<\/h1>\n\n\n\n<h2 class=\"wp-block-heading\">Available Log Levels<\/h2>\n\n\n\n<p>Logback, and most Java logging frameworks has 5 log levels:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>trace<\/code> &#8211; Detailed, fine grained, messages from program execution<\/li>\n\n\n\n<li><code>debug<\/code> &#8211; Messages intended to help debug program execution<\/li>\n\n\n\n<li><code>info<\/code> &#8211; informational messages, often some type of event to record<\/li>\n\n\n\n<li><code>warn <\/code>&#8211; A warning message about an unusual condition<\/li>\n\n\n\n<li><code>error<\/code> &#8211; Message that an unexpected error occured.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Log Level Selection<\/h2>\n\n\n\n<p>When a log level is selected, the selected log level and all higher log levels will produce output.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>trace<\/code> enabled &#8211; <code>trace<\/code>, <code>debug<\/code>, <code>info<\/code>, <code>warn<\/code> and <code>error<\/code> produce log output.<\/li>\n\n\n\n<li><code>debug<\/code> enabled &#8211; <code>debug<\/code>, <code>info<\/code>, <code>warn<\/code> and <code>error<\/code> produce log output.<\/li>\n\n\n\n<li><code>info<\/code> enabled &#8211; <code>info<\/code>, <code>warn<\/code> and <code>error<\/code> produce log output.<\/li>\n\n\n\n<li><code>warn<\/code> enabled &#8211;  <code>warn<\/code> and <code>error<\/code> produce log output.<\/li>\n\n\n\n<li><code>error<\/code> enabled &#8211; Only <code>error<\/code> produces log output.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Log Level Inheritance <\/h2>\n\n\n\n<p>The log level can be set at the root, package segment, and class level The log level will be inherited up this chain. If you set a log level for a package segment, the log level will apply to all classes under that segment.<\/p>\n\n\n\n<p>For example, if we set the log level on the package <code>guru.springframework.controllers<\/code> to <code>debug<\/code> all classes in <code>guru.springframework.controllers<\/code> and classes in any sub-packages will have their log level set to <code>debug<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Log Level Inheritance Examples<\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>Logger<\/strong><\/td><td><strong>Assigned Level<\/strong><\/td><td><strong>Inherited Level<\/strong><\/td><\/tr><tr><td><code>root<\/code><\/td><td><code>info<\/code><\/td><td><code>info<\/code><\/td><\/tr><tr><td><code>guru<\/code><\/td><td>none<\/td><td><code>info<\/code><\/td><\/tr><tr><td><code>guru.springframework<\/code><\/td><td>none<\/td><td><code>info<\/code><\/td><\/tr><tr><td><code>guru.springframework<\/code>.controllers<\/td><td>none<\/td><td><code>info<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>Logger<\/strong><\/td><td><strong>Assigned Level<\/strong><\/td><td><strong>Inherited Level<\/strong><\/td><\/tr><tr><td><code>root<\/code><\/td><td><code>warn<\/code><\/td><td><code>warn<\/code><\/td><\/tr><tr><td><code>guru<\/code><\/td><td>none<\/td><td><code>warn<\/code><\/td><\/tr><tr><td><code>guru.springframework<\/code><\/td><td><code>debug<\/code><\/td><td><code>debug<\/code><\/td><\/tr><tr><td><code>guru.springframework<\/code>.controllers<\/td><td>none<\/td><td>debug<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>Logger<\/strong><\/td><td><strong>Assigned Level<\/strong><\/td><td><strong>Inherited Level<\/strong><\/td><\/tr><tr><td><code>root<\/code><\/td><td><code>error<\/code><\/td><td><code>error<\/code><\/td><\/tr><tr><td><code>guru<\/code><\/td><td>none<\/td><td><code>error<\/code><\/td><\/tr><tr><td><code>guru.springframework<\/code><\/td><td><code>info<\/code><\/td><td><code>info<\/code><\/td><\/tr><tr><td><code>guru.springframework<\/code>.<code>controllers<\/code><\/td><td>none<\/td><td>info<\/td><\/tr><tr><td><code>guru.springframework<\/code>.<code>controllers.IndexController<\/code><\/td><td><code>trace<\/code><\/td><td><code>trace<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h1 class=\"wp-block-heading\">SLF4J &#8211; Simple Logging Facade for Java<\/h1>\n\n\n\n<p>SLF4J uses the Facade Design Pattern to provide an abstraction to popular Java logging frameworks. <\/p>\n\n\n\n<p>Spring Boot uses SLF4J to allow for the easy configuration of alternate logging frameworks. Spring Boot starter artifacts include the SLF4J binding to Logback, and the Logback implementation.<\/p>\n\n\n\n<p>When developing your Spring Boot Application, for logging, you will wish to use the SLFJ4 components, and NOT the logback components directly.<\/p>\n\n\n\n<p>Should you ever wish to use a different logging implementation, you will be able to change without updating your application code.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">Spring Boot Logback Example<\/h1>\n\n\n\n<h2 class=\"wp-block-heading\">Initial Setup<\/h2>\n\n\n\n<p>To follow this tutorial, you can create a new Spring Boot project using the Spring Initializr. <\/p>\n\n\n\n<p>Add the following dependencies:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Spring MVC<\/li>\n\n\n\n<li>Lombok<\/li>\n<\/ul>\n\n\n\n<p>You can also find this project in my <a href=\"https:\/\/github.com\/spring-framework-guru\/spring-6-posts\/tree\/main\" target=\"_blank\" rel=\"noopener\" title=\"\">Github repository here<\/a>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Dependencies<\/h3>\n\n\n\n<p>We can examine the Maven dependency tree to see the dependencies the Spring Boot starter is adding to the project.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/springframework.guru\/wp-content\/uploads\/2016\/04\/Screenshot-2024-10-17-at-2.01.17\u202fPM.png\"><img loading=\"lazy\" decoding=\"async\" width=\"926\" height=\"394\" src=\"https:\/\/springframework.guru\/wp-content\/uploads\/2016\/04\/Screenshot-2024-10-17-at-2.01.17\u202fPM.png\" alt=\"logback dependencies for Spring Boot\" class=\"wp-image-8168\" srcset=\"https:\/\/springframework.guru\/wp-content\/uploads\/2016\/04\/Screenshot-2024-10-17-at-2.01.17\u202fPM.png 926w, https:\/\/springframework.guru\/wp-content\/uploads\/2016\/04\/Screenshot-2024-10-17-at-2.01.17\u202fPM-300x128.png 300w, https:\/\/springframework.guru\/wp-content\/uploads\/2016\/04\/Screenshot-2024-10-17-at-2.01.17\u202fPM-768x327.png 768w, https:\/\/springframework.guru\/wp-content\/uploads\/2016\/04\/Screenshot-2024-10-17-at-2.01.17\u202fPM-848x361.png 848w, https:\/\/springframework.guru\/wp-content\/uploads\/2016\/04\/Screenshot-2024-10-17-at-2.01.17\u202fPM-410x174.png 410w\" sizes=\"(max-width: 926px) 100vw, 926px\" \/><\/a><\/figure>\n\n\n\n<p>Here we can see the Spring Boot starter for Spring MVC (web) brings in the Spring Boot starter for logging. Under this dependency we can the the dependencies for Logback. Logback itself implements the binder for SLF4J, and includes the SLF4J API.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Creating Logback Loggers<\/h2>\n\n\n\n<p>Add the following Spring MVC controller to your Spring Boot project.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#fff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"package guru.springframework.springlogback.controller;\n\nimport org.slf4j.Logger;\nimport org.slf4j.LoggerFactory;\nimport org.springframework.web.bind.annotation.RequestMapping;\nimport org.springframework.web.bind.annotation.RestController;\n\nimport java.util.Map;\n\n@RestController\npublic class IndexController {\n    private final Logger logger = LoggerFactory.getLogger(this.getClass());\n\n    @RequestMapping(value = &quot;\/&quot; )\n    Map&lt;String, String&gt;  index(){\n        logger.trace(&quot;This is a trace message&quot;);\n        logger.debug(&quot;This is a debug message&quot;);\n        logger.info(&quot;This is an info message&quot;);\n        logger.warn(&quot;This is a warn message&quot;);\n        logger.error(&quot;This is an error message&quot;);\n\n        return Map.of(&quot;message&quot;, &quot;Hello, World!&quot;);\n    }\n}\" style=\"color:#24292e;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-light\" style=\"background-color: #fff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #D73A49\">package<\/span><span style=\"color: #24292E\"> guru.springframework.springlogback.controller;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D73A49\">import<\/span><span style=\"color: #24292E\"> org.slf4j.Logger;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D73A49\">import<\/span><span style=\"color: #24292E\"> org.slf4j.LoggerFactory;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D73A49\">import<\/span><span style=\"color: #24292E\"> org.springframework.web.bind.annotation.RequestMapping;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D73A49\">import<\/span><span style=\"color: #24292E\"> org.springframework.web.bind.annotation.RestController;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D73A49\">import<\/span><span style=\"color: #24292E\"> java.util.Map;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">@<\/span><span style=\"color: #D73A49\">RestController<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D73A49\">public<\/span><span style=\"color: #24292E\"> <\/span><span style=\"color: #D73A49\">class<\/span><span style=\"color: #24292E\"> <\/span><span style=\"color: #6F42C1\">IndexController<\/span><span style=\"color: #24292E\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><span style=\"color: #D73A49\">private<\/span><span style=\"color: #24292E\"> <\/span><span style=\"color: #D73A49\">final<\/span><span style=\"color: #24292E\"> Logger logger <\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #24292E\"> LoggerFactory.<\/span><span style=\"color: #6F42C1\">getLogger<\/span><span style=\"color: #24292E\">(<\/span><span style=\"color: #005CC5\">this<\/span><span style=\"color: #24292E\">.<\/span><span style=\"color: #6F42C1\">getClass<\/span><span style=\"color: #24292E\">());<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    @<\/span><span style=\"color: #D73A49\">RequestMapping<\/span><span style=\"color: #24292E\">(<\/span><span style=\"color: #005CC5\">value<\/span><span style=\"color: #24292E\"> <\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #24292E\"> <\/span><span style=\"color: #032F62\">&quot;\/&quot;<\/span><span style=\"color: #24292E\"> )<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    Map&lt;<\/span><span style=\"color: #D73A49\">String<\/span><span style=\"color: #24292E\">, <\/span><span style=\"color: #D73A49\">String<\/span><span style=\"color: #24292E\">&gt;  <\/span><span style=\"color: #6F42C1\">index<\/span><span style=\"color: #24292E\">(){<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">        logger.<\/span><span style=\"color: #6F42C1\">trace<\/span><span style=\"color: #24292E\">(<\/span><span style=\"color: #032F62\">&quot;This is a trace message&quot;<\/span><span style=\"color: #24292E\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">        logger.<\/span><span style=\"color: #6F42C1\">debug<\/span><span style=\"color: #24292E\">(<\/span><span style=\"color: #032F62\">&quot;This is a debug message&quot;<\/span><span style=\"color: #24292E\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">        logger.<\/span><span style=\"color: #6F42C1\">info<\/span><span style=\"color: #24292E\">(<\/span><span style=\"color: #032F62\">&quot;This is an info message&quot;<\/span><span style=\"color: #24292E\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">        logger.<\/span><span style=\"color: #6F42C1\">warn<\/span><span style=\"color: #24292E\">(<\/span><span style=\"color: #032F62\">&quot;This is a warn message&quot;<\/span><span style=\"color: #24292E\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">        logger.<\/span><span style=\"color: #6F42C1\">error<\/span><span style=\"color: #24292E\">(<\/span><span style=\"color: #032F62\">&quot;This is an error message&quot;<\/span><span style=\"color: #24292E\">);<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">        <\/span><span style=\"color: #D73A49\">return<\/span><span style=\"color: #24292E\"> Map.<\/span><span style=\"color: #6F42C1\">of<\/span><span style=\"color: #24292E\">(<\/span><span style=\"color: #032F62\">&quot;message&quot;<\/span><span style=\"color: #24292E\">, <\/span><span style=\"color: #032F62\">&quot;Hello, World!&quot;<\/span><span style=\"color: #24292E\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>In this example, we get an SLF4J logger from the SLF4J logger factory with the class of the controller. <\/p>\n\n\n\n<p>When the <code>index()<\/code> method is called, 5 logging statements, one for each log level, are called.<\/p>\n\n\n\n<p>You can start your Spring Boot application and go to the url <code>http:\\\\localhost:8080<\/code> in your browser. You&#8217;ll see the <code>Hello World<\/code> message in the browser. In the console, you will see the following output.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#fff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"2024-10-17T14:16:35.487-04:00  INFO 76058 --- [spring-logback] [nio-8080-exec-2] g.s.s.controller.IndexController         : This is an info message\n2024-10-17T14:16:35.487-04:00  WARN 76058 --- [spring-logback] [nio-8080-exec-2] g.s.s.controller.IndexController         : This is a warn message\n2024-10-17T14:16:35.487-04:00 ERROR 76058 --- [spring-logback] [nio-8080-exec-2] g.s.s.controller.IndexController         : This is an error message\" style=\"color:#24292e;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-light\" style=\"background-color: #fff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #005CC5\">2024<\/span><span style=\"color: #D73A49\">-<\/span><span style=\"color: #005CC5\">10<\/span><span style=\"color: #D73A49\">-<\/span><span style=\"color: #24292E\">17T14<\/span><span style=\"color: #D73A49\">:<\/span><span style=\"color: #005CC5\">16<\/span><span style=\"color: #D73A49\">:<\/span><span style=\"color: #005CC5\">35.487<\/span><span style=\"color: #D73A49\">-<\/span><span style=\"color: #005CC5\">04<\/span><span style=\"color: #D73A49\">:<\/span><span style=\"color: #005CC5\">00<\/span><span style=\"color: #24292E\">  INFO <\/span><span style=\"color: #005CC5\">76058<\/span><span style=\"color: #24292E\"> <\/span><span style=\"color: #D73A49\">---<\/span><span style=\"color: #24292E\"> [spring<\/span><span style=\"color: #D73A49\">-<\/span><span style=\"color: #24292E\">logback] [nio<\/span><span style=\"color: #D73A49\">-<\/span><span style=\"color: #005CC5\">8080<\/span><span style=\"color: #D73A49\">-<\/span><span style=\"color: #24292E\">exec<\/span><span style=\"color: #D73A49\">-<\/span><span style=\"color: #005CC5\">2<\/span><span style=\"color: #24292E\">] g.s.s.controller.IndexController         <\/span><span style=\"color: #D73A49\">:<\/span><span style=\"color: #24292E\"> This is an info message<\/span><\/span>\n<span class=\"line\"><span style=\"color: #005CC5\">2024<\/span><span style=\"color: #D73A49\">-<\/span><span style=\"color: #005CC5\">10<\/span><span style=\"color: #D73A49\">-<\/span><span style=\"color: #24292E\">17T14<\/span><span style=\"color: #D73A49\">:<\/span><span style=\"color: #005CC5\">16<\/span><span style=\"color: #D73A49\">:<\/span><span style=\"color: #005CC5\">35.487<\/span><span style=\"color: #D73A49\">-<\/span><span style=\"color: #005CC5\">04<\/span><span style=\"color: #D73A49\">:<\/span><span style=\"color: #005CC5\">00<\/span><span style=\"color: #24292E\">  WARN <\/span><span style=\"color: #005CC5\">76058<\/span><span style=\"color: #24292E\"> <\/span><span style=\"color: #D73A49\">---<\/span><span style=\"color: #24292E\"> [spring<\/span><span style=\"color: #D73A49\">-<\/span><span style=\"color: #24292E\">logback] [nio<\/span><span style=\"color: #D73A49\">-<\/span><span style=\"color: #005CC5\">8080<\/span><span style=\"color: #D73A49\">-<\/span><span style=\"color: #24292E\">exec<\/span><span style=\"color: #D73A49\">-<\/span><span style=\"color: #005CC5\">2<\/span><span style=\"color: #24292E\">] g.s.s.controller.IndexController         <\/span><span style=\"color: #D73A49\">:<\/span><span style=\"color: #24292E\"> This is a warn message<\/span><\/span>\n<span class=\"line\"><span style=\"color: #005CC5\">2024<\/span><span style=\"color: #D73A49\">-<\/span><span style=\"color: #005CC5\">10<\/span><span style=\"color: #D73A49\">-<\/span><span style=\"color: #24292E\">17T14<\/span><span style=\"color: #D73A49\">:<\/span><span style=\"color: #005CC5\">16<\/span><span style=\"color: #D73A49\">:<\/span><span style=\"color: #005CC5\">35.487<\/span><span style=\"color: #D73A49\">-<\/span><span style=\"color: #005CC5\">04<\/span><span style=\"color: #D73A49\">:<\/span><span style=\"color: #005CC5\">00<\/span><span style=\"color: #24292E\"> ERROR <\/span><span style=\"color: #005CC5\">76058<\/span><span style=\"color: #24292E\"> <\/span><span style=\"color: #D73A49\">---<\/span><span style=\"color: #24292E\"> [spring<\/span><span style=\"color: #D73A49\">-<\/span><span style=\"color: #24292E\">logback] [nio<\/span><span style=\"color: #D73A49\">-<\/span><span style=\"color: #005CC5\">8080<\/span><span style=\"color: #D73A49\">-<\/span><span style=\"color: #24292E\">exec<\/span><span style=\"color: #D73A49\">-<\/span><span style=\"color: #005CC5\">2<\/span><span style=\"color: #24292E\">] g.s.s.controller.IndexController         <\/span><span style=\"color: #D73A49\">:<\/span><span style=\"color: #24292E\"> This is an error message<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>Notice, you are only seeing <code>info<\/code>, <code>warn<\/code>, and <code>error<\/code> log messages. The <code>trace<\/code> and <code>debug <\/code>messages are not there.<\/p>\n\n\n\n<p>This is because the default configuration Spring Boot uses sets the root log level to <code>info<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Creating Logback Loggers with Project Lombok<\/h2>\n\n\n\n<p>Project Lombok has become very popular for its features saving us from writing excessive cerimonial code. I previously covered Project Lombok in this <a href=\"https:\/\/springframework.guru\/spring-boot-with-lombok-part-1\/\" target=\"_blank\" rel=\"noopener\" title=\"\">post<\/a>. In this post I wish to cover creating loggers using <a href=\"https:\/\/projectlombok.org\/\" target=\"_blank\" rel=\"noopener\" title=\"\">Project Lombok<\/a>. <\/p>\n\n\n\n<p>Project Lombok will generate code for you at compile time through a Java feature known as Annotation Processing. To use Project Lombok, be sure to add the dependency and enable Annotation processing in your IDE compiler settings. <\/p>\n\n\n\n<p>Here is an example controller using Project Lombok to create its logger.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#fff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"@Slf4j\n@RestController\npublic class LombokController {\n    \n    @RequestMapping(value = &quot;\/lombok&quot; )\n    Map&lt;String, String&gt; index(){\n        log.trace(&quot;This is a trace message&quot;);\n        log.debug(&quot;This is a debug message&quot;);\n        log.info(&quot;This is an info message&quot;);\n        log.warn(&quot;This is a warn message&quot;);\n        log.error(&quot;This is an error message&quot;);\n\n        return Map.of(&quot;message&quot;, &quot;Hello, World!&quot;);\n    }\n}\" style=\"color:#24292e;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-light\" style=\"background-color: #fff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #24292E\">@<\/span><span style=\"color: #D73A49\">Slf4j<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">@<\/span><span style=\"color: #D73A49\">RestController<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D73A49\">public<\/span><span style=\"color: #24292E\"> <\/span><span style=\"color: #D73A49\">class<\/span><span style=\"color: #24292E\"> <\/span><span style=\"color: #6F42C1\">LombokController<\/span><span style=\"color: #24292E\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    @<\/span><span style=\"color: #D73A49\">RequestMapping<\/span><span style=\"color: #24292E\">(<\/span><span style=\"color: #005CC5\">value<\/span><span style=\"color: #24292E\"> <\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #24292E\"> <\/span><span style=\"color: #032F62\">&quot;\/lombok&quot;<\/span><span style=\"color: #24292E\"> )<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    Map&lt;<\/span><span style=\"color: #D73A49\">String<\/span><span style=\"color: #24292E\">, <\/span><span style=\"color: #D73A49\">String<\/span><span style=\"color: #24292E\">&gt; <\/span><span style=\"color: #6F42C1\">index<\/span><span style=\"color: #24292E\">(){<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">        log.<\/span><span style=\"color: #6F42C1\">trace<\/span><span style=\"color: #24292E\">(<\/span><span style=\"color: #032F62\">&quot;This is a trace message&quot;<\/span><span style=\"color: #24292E\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">        log.<\/span><span style=\"color: #6F42C1\">debug<\/span><span style=\"color: #24292E\">(<\/span><span style=\"color: #032F62\">&quot;This is a debug message&quot;<\/span><span style=\"color: #24292E\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">        log.<\/span><span style=\"color: #6F42C1\">info<\/span><span style=\"color: #24292E\">(<\/span><span style=\"color: #032F62\">&quot;This is an info message&quot;<\/span><span style=\"color: #24292E\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">        log.<\/span><span style=\"color: #6F42C1\">warn<\/span><span style=\"color: #24292E\">(<\/span><span style=\"color: #032F62\">&quot;This is a warn message&quot;<\/span><span style=\"color: #24292E\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">        log.<\/span><span style=\"color: #6F42C1\">error<\/span><span style=\"color: #24292E\">(<\/span><span style=\"color: #032F62\">&quot;This is an error message&quot;<\/span><span style=\"color: #24292E\">);<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">        <\/span><span style=\"color: #D73A49\">return<\/span><span style=\"color: #24292E\"> Map.<\/span><span style=\"color: #6F42C1\">of<\/span><span style=\"color: #24292E\">(<\/span><span style=\"color: #032F62\">&quot;message&quot;<\/span><span style=\"color: #24292E\">, <\/span><span style=\"color: #032F62\">&quot;Hello, World!&quot;<\/span><span style=\"color: #24292E\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>In the above example, we annotate the class with the Project Lombok annotation <code>@Slf4j<\/code>. <\/p>\n\n\n\n<p>At compile time, Project Lombok will add the following to your class:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#fff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(LombokController.class);\" style=\"color:#24292e;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-light\" style=\"background-color: #fff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #D73A49\">private<\/span><span style=\"color: #24292E\"> <\/span><span style=\"color: #D73A49\">static<\/span><span style=\"color: #24292E\"> <\/span><span style=\"color: #D73A49\">final<\/span><span style=\"color: #24292E\"> org.slf4j.Logger log <\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #24292E\"> org.slf4j.LoggerFactory.<\/span><span style=\"color: #6F42C1\">getLogger<\/span><span style=\"color: #24292E\">(LombokController.class);<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>While it is a small time saver, its is easy to use. And in my opinion, your code is cleaner.<\/p>\n\n\n\n<p>In this case, we are using the SLF4J logger. Project Lombok <a href=\"https:\/\/projectlombok.org\/features\/log\" target=\"_blank\" rel=\"noopener\" title=\"\">supports the popular<\/a> Java logging frameworks. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Setting Log Levels<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Setting Log Levels from the Command Line<\/h3>\n\n\n\n<p>We can pass <code>--debug<\/code> or <code>--trace<\/code> as command line arguments to change the log level of the root logger. <\/p>\n\n\n\n<p>For finer control, we can change just the log level of our class using the following command line argument:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#fff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"-Dlogging.level.guru.springframework.springlogback.controller=TRACE\" style=\"color:#24292e;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-light\" style=\"background-color: #fff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #D73A49\">-<\/span><span style=\"color: #24292E\">Dlogging.level.guru.springframework.springlogback.controller<\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #24292E\">TRACE<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>If we are using the Spring Boot Maven Plugin to run the application, we can pass the following command line argument to change the log level.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#fff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"mvn spring-boot:run \n  -Dspring-boot.run.arguments=--logging.level.guru.springframework.springlogback.controller=trace\" style=\"color:#24292e;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-light\" style=\"background-color: #fff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #24292E\">mvn spring<\/span><span style=\"color: #D73A49\">-<\/span><span style=\"color: #24292E\">boot<\/span><span style=\"color: #D73A49\">:<\/span><span style=\"color: #24292E\">run <\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">  <\/span><span style=\"color: #D73A49\">-<\/span><span style=\"color: #24292E\">Dspring<\/span><span style=\"color: #D73A49\">-<\/span><span style=\"color: #24292E\">boot.run.arguments<\/span><span style=\"color: #D73A49\">=--<\/span><span style=\"color: #24292E\">logging.level.guru.springframework.springlogback.controller<\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #24292E\">trace<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>If we are using the Spring Boot Gradle plugin, we can pass the following command line argument to change the log level.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#fff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\".\/gradlew bootRun -Pargs=--logging.level.guru.springframework.springlogback.controller=TRACE\" style=\"color:#24292e;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-light\" style=\"background-color: #fff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #24292E\">.<\/span><span style=\"color: #D73A49\">\/<\/span><span style=\"color: #24292E\">gradlew bootRun <\/span><span style=\"color: #D73A49\">-<\/span><span style=\"color: #24292E\">Pargs<\/span><span style=\"color: #D73A49\">=--<\/span><span style=\"color: #24292E\">logging.level.guru.springframework.springlogback.controller<\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #24292E\">TRACE<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Setting Log Levels from Environment Variables<\/h3>\n\n\n\n<p>We can also control log levels by setting environment variables. For example, we could set:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#fff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"export LOGGING_LEVEL_ROOT=ERROR\nexport LOGGING_LEVEL_GURU_SPRINGFRAMEWORK=TRACE\" style=\"color:#24292e;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-light\" style=\"background-color: #fff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #24292E\">export LOGGING_LEVEL_ROOT<\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #24292E\">ERROR<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">export LOGGING_LEVEL_GURU_SPRINGFRAMEWORK<\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #24292E\">TRACE<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Setting Log Levels from application.properties<\/h3>\n\n\n\n<p>To change log levels from application.properties, we can add the following:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#fff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"logging.level.root=error\nlogging.level.guru.springfamework=TRACE\" style=\"color:#24292e;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-light\" style=\"background-color: #fff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #24292E\">logging.level.root<\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #24292E\">error<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">logging.level.guru.springfamework<\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #24292E\">TRACE<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Setting Log Levels in Logback XML Configuration<\/h3>\n\n\n\n<p>In the Logback XML Configuration file, we can set the following:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#fff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"&lt;logger name=&quot;guru.springframework&quot; level=&quot;DEBUG&quot; \/&gt;\" style=\"color:#24292e;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-light\" style=\"background-color: #fff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #D73A49\">&lt;<\/span><span style=\"color: #24292E\">logger name<\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #032F62\">&quot;guru.springframework&quot;<\/span><span style=\"color: #24292E\"> level<\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #032F62\">&quot;DEBUG&quot;<\/span><span style=\"color: #24292E\"> <\/span><span style=\"color: #D73A49\">\/&gt;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>We&#8217;ll look closer at XML configuration later in this post.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Setting Log Levels Using Spring Boot Profiles<\/h3>\n\n\n\n<p>While developing in your local machine, it is common to set the log level to<code data-enlighter-theme=\"git\" data-enlighter-linenumbers=\"false\" data-enlighter-language=\"java\" class=\"EnlighterJSRAW\"> DEBUG<\/code>. This will give you detailed log messages for your development use. While on production, it is typical to set the log level to <code data-enlighter-theme=\"git\" data-enlighter-linenumbers=\"false\" data-enlighter-language=\"java\" class=\"EnlighterJSRAW\"> WARN<\/code> or above. This is to avoid filling your logs with excessive debug information and logging overhead while running in production. While logging is very efficient, there is still a cost.<\/p>\n\n\n\n<p>There are two ways to set log levels using Spring Boot Profiles. Using appplication.properties and using the Logback configuration file.<\/p>\n\n\n\n<p>To use application.properties with the profile name appended to &#8220;application&#8221;. For example, a properties file for the active profile <code>dev<\/code> would be <code>application-dev.properties<\/code> or <code>application-dev.yaml<\/code>.<\/p>\n\n\n\n<p>Spring Boot has addressed these requirements by extending Spring profiles for Logback configuration with the <code>&lt;springProfile><\/code> element. Using this element in your <code>logback-spring.xml<\/code> file, you can optionally include or exclude sections of logging configuration based on the active Spring profile.<\/p>\n\n\n\n<p><strong>Note<\/strong>: Support for<code data-enlighter-theme=\"git\" data-enlighter-linenumbers=\"false\" data-enlighter-language=\"java\" class=\"EnlighterJSRAW\"> &lt;springProfile><\/code> in Logback configuration is available from Spring Boot 1.3.0.M2 milestone onwards.<\/p>\n\n\n\n<p>Here is an XML example to configure Logback&nbsp;using&nbsp;active Spring profiles.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#fff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;\n&lt;configuration&gt;\n    &lt;include resource=&quot;org\/springframework\/boot\/logging\/logback\/base.xml&quot; \/&gt;\n    &lt;springProfile name=&quot;dev,staging&quot;&gt;\n        &lt;logger name=&quot;guru.springframework.controllers&quot; level=&quot;DEBUG&quot; additivity=&quot;false&quot;&gt;\n            &lt;appender-ref ref=&quot;CONSOLE&quot; \/&gt;\n        &lt;\/logger&gt;&gt;\n    &lt;\/springProfile&gt;\n    &lt;springProfile name=&quot;production&quot;&gt;\n        &lt;logger name=&quot;guru.springframework.controllers&quot; level=&quot;WARN&quot; additivity=&quot;false&quot;&gt;\n            &lt;appender-ref ref=&quot;FILE&quot; \/&gt;\n        &lt;\/logger&gt;\n    &lt;\/springProfile&gt;\n &lt;\/configuration&gt;\" style=\"color:#24292e;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-light\" style=\"background-color: #fff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #D73A49\">&lt;?<\/span><span style=\"color: #24292E\">xml version<\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #032F62\">&quot;1.0&quot;<\/span><span style=\"color: #24292E\"> encoding<\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #032F62\">&quot;UTF-8&quot;<\/span><span style=\"color: #D73A49\">?&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D73A49\">&lt;<\/span><span style=\"color: #24292E\">configuration<\/span><span style=\"color: #D73A49\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><span style=\"color: #D73A49\">&lt;<\/span><span style=\"color: #24292E\">include resource<\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #032F62\">&quot;org\/springframework\/boot\/logging\/logback\/base.xml&quot;<\/span><span style=\"color: #24292E\"> <\/span><span style=\"color: #D73A49\">\/&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><span style=\"color: #D73A49\">&lt;<\/span><span style=\"color: #24292E\">springProfile name<\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #032F62\">&quot;dev,staging&quot;<\/span><span style=\"color: #D73A49\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">        <\/span><span style=\"color: #D73A49\">&lt;<\/span><span style=\"color: #24292E\">logger name<\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #032F62\">&quot;guru.springframework.controllers&quot;<\/span><span style=\"color: #24292E\"> level<\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #032F62\">&quot;DEBUG&quot;<\/span><span style=\"color: #24292E\"> additivity<\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #032F62\">&quot;false&quot;<\/span><span style=\"color: #D73A49\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">            <\/span><span style=\"color: #D73A49\">&lt;<\/span><span style=\"color: #24292E\">appender<\/span><span style=\"color: #D73A49\">-<\/span><span style=\"color: #24292E\">ref ref<\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #032F62\">&quot;CONSOLE&quot;<\/span><span style=\"color: #24292E\"> <\/span><span style=\"color: #D73A49\">\/&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">        <\/span><span style=\"color: #D73A49\">&lt;\/<\/span><span style=\"color: #24292E\">logger<\/span><span style=\"color: #D73A49\">&gt;&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><span style=\"color: #D73A49\">&lt;\/<\/span><span style=\"color: #24292E\">springProfile<\/span><span style=\"color: #D73A49\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><span style=\"color: #D73A49\">&lt;<\/span><span style=\"color: #24292E\">springProfile name<\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #032F62\">&quot;production&quot;<\/span><span style=\"color: #D73A49\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">        <\/span><span style=\"color: #D73A49\">&lt;<\/span><span style=\"color: #24292E\">logger name<\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #032F62\">&quot;guru.springframework.controllers&quot;<\/span><span style=\"color: #24292E\"> level<\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #032F62\">&quot;WARN&quot;<\/span><span style=\"color: #24292E\"> additivity<\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #032F62\">&quot;false&quot;<\/span><span style=\"color: #D73A49\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">            <\/span><span style=\"color: #D73A49\">&lt;<\/span><span style=\"color: #24292E\">appender<\/span><span style=\"color: #D73A49\">-<\/span><span style=\"color: #24292E\">ref ref<\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #032F62\">&quot;FILE&quot;<\/span><span style=\"color: #24292E\"> <\/span><span style=\"color: #D73A49\">\/&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">        <\/span><span style=\"color: #D73A49\">&lt;\/<\/span><span style=\"color: #24292E\">logger<\/span><span style=\"color: #D73A49\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><span style=\"color: #D73A49\">&lt;\/<\/span><span style=\"color: #24292E\">springProfile<\/span><span style=\"color: #D73A49\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\"> <\/span><span style=\"color: #D73A49\">&lt;\/<\/span><span style=\"color: #24292E\">configuration<\/span><span style=\"color: #D73A49\">&gt;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Log Level Configuration Hierarchy  <\/h3>\n\n\n\n<p>If the log level is defined in multiple locations, the following hierarchy applies:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Log Levels set in application.properties will override XML properties<\/li>\n\n\n\n<li>Log Levels set in application-&lt;profile>.properties will override application.properties<\/li>\n\n\n\n<li>Log Levels set in environment variables will override application.properties and application-&lt;profile>.properties<\/li>\n\n\n\n<li>Log Levels set via command line arguments will override environment variables  <\/li>\n<\/ul>\n\n\n\n<p>See <a href=\"https:\/\/docs.spring.io\/spring-boot\/reference\/features\/external-config.html\" target=\"_blank\" rel=\"noopener\" title=\"\">Externalized Configuration for Spring Boot<\/a> for additional information <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Logback Configuration with Spring Boot<\/h2>\n\n\n\n<p>If you need more granular control over the Logback configuration, you can specify a configuration file.<\/p>\n\n\n\n<p>If Spring Boot finds one of these 4 files on the classpath, it will load it over the default configuration. <\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>logback-spring.xml<\/li>\n\n\n\n<li>logback.xml<\/li>\n\n\n\n<li>logback-spring.groovy<\/li>\n\n\n\n<li>logback.groovy <\/li>\n<\/ul>\n\n\n\n<p>Spring recommends using <code>logback-spring.xml<\/code> over <code>logback.xml<\/code>. <\/p>\n\n\n\n<p>You can also include the Spring Boot default configuration an simply extend it with your customizations. <\/p>\n\n\n\n<p>Following is an example <code>logback-spring.xml<\/code> file.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#fff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;\n&lt;configuration&gt;\n\n    &lt;include resource=&quot;org\/springframework\/boot\/logging\/logback\/base.xml&quot; \/&gt;\n\n    &lt;logger name=&quot;guru.springframework&quot; level=&quot;DEBUG&quot;\/&gt;\n&lt;\/configuration&gt;\" style=\"color:#24292e;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-light\" style=\"background-color: #fff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #D73A49\">&lt;?<\/span><span style=\"color: #24292E\">xml version<\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #032F62\">&quot;1.0&quot;<\/span><span style=\"color: #24292E\"> encoding<\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #032F62\">&quot;UTF-8&quot;<\/span><span style=\"color: #D73A49\">?&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D73A49\">&lt;<\/span><span style=\"color: #24292E\">configuration<\/span><span style=\"color: #D73A49\">&gt;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><span style=\"color: #D73A49\">&lt;<\/span><span style=\"color: #24292E\">include resource<\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #032F62\">&quot;org\/springframework\/boot\/logging\/logback\/base.xml&quot;<\/span><span style=\"color: #24292E\"> <\/span><span style=\"color: #D73A49\">\/&gt;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><span style=\"color: #D73A49\">&lt;<\/span><span style=\"color: #24292E\">logger name<\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #032F62\">&quot;guru.springframework&quot;<\/span><span style=\"color: #24292E\"> level<\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #032F62\">&quot;DEBUG&quot;<\/span><span style=\"color: #D73A49\">\/&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D73A49\">&lt;\/<\/span><span style=\"color: #24292E\">configuration<\/span><span style=\"color: #D73A49\">&gt;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>In this example file, we are including the base Spring Boot Logback configuration, and setting the log level of the package <code>guru.springframework<\/code> to <code>debug<\/code>. <\/p>\n\n\n\n<p>You can learn more about Logback XML <a href=\"http:\/\/springframework.guru\/logback-configuration-using-xml\/\" target=\"_blank\" rel=\"noopener\" title=\"\">configuration in this post<\/a>, and <a href=\"http:\/\/springframework.guru\/logback-configuration-using-groovy\/\" target=\"_blank\" rel=\"noopener noreferrer\">Groovy configuration<\/a> files.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Logback File Logging<\/h2>\n\n\n\n<p>By default, Spring Boot will only write log output to the console.<\/p>\n\n\n\n<p>To enable log output to a file, you need to set the file name in the property <code>logging.file.name<\/code> or the directory to write log files to in the property <code>logging.file.path<\/code>. <\/p>\n\n\n\n<p><strong>NOTE:<\/strong> If you set both values, only <code>logging.file.name<\/code> is used.<\/p>\n\n\n\n<p>The Spring Boot default configuration will rotate the log files when they reach 10 MB, and keep up to 7 archive log files. See the <a href=\"https:\/\/docs.spring.io\/spring-boot\/reference\/features\/logging.html#features.logging.file-rotation\" target=\"_blank\" rel=\"noopener\" title=\"\">Spring Boot documentation<\/a> if you would like to modify this behavior. <\/p>\n\n\n\n<p>In the configuration code above, for the <code class=\"EnlighterJSRAW\" data-enlighter-language=\"java\" data-enlighter-theme=\"git\" data-enlighter-linenumbers=\"false\">dev<\/code> and <code class=\"EnlighterJSRAW\" data-enlighter-language=\"java\" data-enlighter-theme=\"git\" data-enlighter-linenumbers=\"false\">staging<\/code> profiles, we configured the <code class=\"EnlighterJSRAW\" data-enlighter-language=\"java\" data-enlighter-theme=\"git\" data-enlighter-linenumbers=\"false\">guru.springframework.controllers<\/code> logger to log <code class=\"EnlighterJSRAW\" data-enlighter-language=\"java\" data-enlighter-theme=\"git\" data-enlighter-linenumbers=\"false\">DEBUG<\/code> and higher level messages to console. For the <code class=\"EnlighterJSRAW\" data-enlighter-language=\"java\" data-enlighter-theme=\"git\" data-enlighter-linenumbers=\"false\">production<\/code> profile, we configured the same logger to log <code class=\"EnlighterJSRAW\" data-enlighter-language=\"java\" data-enlighter-theme=\"git\" data-enlighter-linenumbers=\"false\">WARN<\/code> and higher level messages to a file.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">JSON Logging with Logback<\/h2>\n\n\n\n<p>For environments which need to use consolidated logging, it is common to use JSON log output. This is typically needed with distributed microservices.<\/p>\n\n\n\n<p>If you need to setup JSON logging with Logback, check <a href=\"https:\/\/springframework.guru\/json-logging-with-spring-boot\/\">out this post<\/a>!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Logback Auto-Scan Issue with Spring Boot<\/h2>\n\n\n\n<p>In a <code class=\"EnlighterJSRAW\" data-enlighter-language=\"java\" data-enlighter-theme=\"git\" data-enlighter-linenumbers=\"false\">logback-spring.xml<\/code> file, you can enable auto-scan of the configuration by setting the <code class=\"EnlighterJSRAW\" data-enlighter-language=\"java\" data-enlighter-theme=\"git\" data-enlighter-linenumbers=\"false\">scan=\"true\"<\/code> attribute. With auto-scan enabled, Logback scans for changes in the configuration file. For any changes, Logback automatically reconfigure itself with them. You can specify a scanning period by passing a time period to the <code class=\"EnlighterJSRAW\" data-enlighter-language=\"java\" data-enlighter-theme=\"git\" data-enlighter-linenumbers=\"false\">scanPeriod<\/code> attribute, with a value specified in units of milliseconds, seconds, minutes or hours.<br>For example, this code tells Logback to scan <code class=\"EnlighterJSRAW\" data-enlighter-language=\"java\" data-enlighter-theme=\"git\" data-enlighter-linenumbers=\"false\">logback-spring.xml<\/code> after every 10 seconds.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#fff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"&lt;configuration debug=&quot;true&quot; scan=&quot;true&quot; scanPeriod=&quot;10 seconds&quot; &gt; \n  ...\n&lt;\/configuration&gt;\" style=\"color:#24292e;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-light\" style=\"background-color: #fff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #D73A49\">&lt;<\/span><span style=\"color: #24292E\">configuration debug<\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #032F62\">&quot;true&quot;<\/span><span style=\"color: #24292E\"> scan<\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #032F62\">&quot;true&quot;<\/span><span style=\"color: #24292E\"> scanPeriod<\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #032F62\">&quot;10 seconds&quot;<\/span><span style=\"color: #24292E\"> <\/span><span style=\"color: #D73A49\">&gt;<\/span><span style=\"color: #24292E\"> <\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">  ...<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D73A49\">&lt;\/<\/span><span style=\"color: #24292E\">configuration<\/span><span style=\"color: #D73A49\">&gt;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>One limitation of Spring Boot Logback is that with <code class=\"EnlighterJSRAW\" data-enlighter-language=\"java\" data-enlighter-theme=\"git\" data-enlighter-linenumbers=\"false\">springProfile<\/code> and <code class=\"EnlighterJSRAW\" data-enlighter-language=\"java\" data-enlighter-theme=\"git\" data-enlighter-linenumbers=\"false\">springProperty<\/code>, setting auto-scan results in error.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">ANSI Color Mode<\/h2>\n\n\n\n<p>For console output, Logback will apply coloring to the console output. Refer to the Logback <a href=\"https:\/\/logback.qos.ch\/manual\/layouts.html#coloring\" target=\"_blank\" rel=\"noopener\" title=\"\">configuration  guide<\/a> if you would like to customize this.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">ANSI Color Mode on Windows<\/h3>\n\n\n\n<p>To enable ANSI colors on Windows, you will need add the Jansi library version 1.17 or higher to your classpath and enable Jansi in the Logback configuration. <\/p>\n\n\n\n<p>Add the following Maven dependency:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#fff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"&lt;dependency&gt;\n    &lt;groupId&gt;org.fusesource.jansi&lt;\/groupId&gt;\n    &lt;artifactId&gt;jansi&lt;\/artifactId&gt;\n    &lt;version&gt;2.4.1&lt;\/version&gt;\n&lt;\/dependency&gt;\n\" style=\"color:#24292e;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-light\" style=\"background-color: #fff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #D73A49\">&lt;<\/span><span style=\"color: #24292E\">dependency<\/span><span style=\"color: #D73A49\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><span style=\"color: #D73A49\">&lt;<\/span><span style=\"color: #24292E\">groupId<\/span><span style=\"color: #D73A49\">&gt;<\/span><span style=\"color: #24292E\">org.fusesource.jansi<\/span><span style=\"color: #D73A49\">&lt;\/<\/span><span style=\"color: #24292E\">groupId<\/span><span style=\"color: #D73A49\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><span style=\"color: #D73A49\">&lt;<\/span><span style=\"color: #24292E\">artifactId<\/span><span style=\"color: #D73A49\">&gt;<\/span><span style=\"color: #24292E\">jansi<\/span><span style=\"color: #D73A49\">&lt;\/<\/span><span style=\"color: #24292E\">artifactId<\/span><span style=\"color: #D73A49\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><span style=\"color: #D73A49\">&lt;<\/span><span style=\"color: #24292E\">version<\/span><span style=\"color: #D73A49\">&gt;<\/span><span style=\"color: #005CC5\">2.4<\/span><span style=\"color: #24292E\">.<\/span><span style=\"color: #B31D28; font-style: italic\">1<\/span><span style=\"color: #D73A49\">&lt;\/<\/span><span style=\"color: #24292E\">version<\/span><span style=\"color: #D73A49\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D73A49\">&lt;\/<\/span><span style=\"color: #24292E\">dependency<\/span><span style=\"color: #D73A49\">&gt;<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p>Following is a Logback configuration example to enable Jansi. <\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#fff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"&lt;configuration debug=&quot;true&quot;&gt;\n  &lt;appender name=&quot;STDOUT&quot; class=&quot;ch.qos.logback.core.ConsoleAppender&quot;&gt;\n    &lt;withJansi&gt;true&lt;\/withJansi&gt;\n    &lt;encoder&gt;\n      &lt;pattern&gt;[%thread] %highlight(%-5level) %cyan(%logger{15}) -%kvp -%msg %n&lt;\/pattern&gt;\n    &lt;\/encoder&gt;\n  &lt;\/appender&gt;\n  &lt;root level=&quot;DEBUG&quot;&gt;\n    &lt;appender-ref ref=&quot;STDOUT&quot; \/&gt;\n  &lt;\/root&gt;\n&lt;\/configuration&gt;\" style=\"color:#24292e;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-light\" style=\"background-color: #fff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #D73A49\">&lt;<\/span><span style=\"color: #24292E\">configuration debug<\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #032F62\">&quot;true&quot;<\/span><span style=\"color: #D73A49\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">  <\/span><span style=\"color: #D73A49\">&lt;<\/span><span style=\"color: #24292E\">appender name<\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #032F62\">&quot;STDOUT&quot;<\/span><span style=\"color: #24292E\"> class<\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #032F62\">&quot;ch.qos.logback.core.ConsoleAppender&quot;<\/span><span style=\"color: #D73A49\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><span style=\"color: #D73A49\">&lt;<\/span><span style=\"color: #24292E\">withJansi<\/span><span style=\"color: #D73A49\">&gt;<\/span><span style=\"color: #005CC5\">true<\/span><span style=\"color: #D73A49\">&lt;\/<\/span><span style=\"color: #24292E\">withJansi<\/span><span style=\"color: #D73A49\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><span style=\"color: #D73A49\">&lt;<\/span><span style=\"color: #24292E\">encoder<\/span><span style=\"color: #D73A49\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">      <\/span><span style=\"color: #D73A49\">&lt;<\/span><span style=\"color: #24292E\">pattern<\/span><span style=\"color: #D73A49\">&gt;<\/span><span style=\"color: #24292E\">[<\/span><span style=\"color: #D73A49\">%<\/span><span style=\"color: #24292E\">thread] <\/span><span style=\"color: #D73A49\">%<\/span><span style=\"color: #6F42C1\">highlight<\/span><span style=\"color: #24292E\">(<\/span><span style=\"color: #D73A49\">%-<\/span><span style=\"color: #24292E\">5level) <\/span><span style=\"color: #D73A49\">%<\/span><span style=\"color: #6F42C1\">cyan<\/span><span style=\"color: #24292E\">(<\/span><span style=\"color: #D73A49\">%<\/span><span style=\"color: #24292E\">logger{<\/span><span style=\"color: #005CC5\">15<\/span><span style=\"color: #24292E\">}) <\/span><span style=\"color: #D73A49\">-%<\/span><span style=\"color: #24292E\">kvp <\/span><span style=\"color: #D73A49\">-%<\/span><span style=\"color: #24292E\">msg <\/span><span style=\"color: #D73A49\">%<\/span><span style=\"color: #24292E\">n<\/span><span style=\"color: #D73A49\">&lt;\/<\/span><span style=\"color: #24292E\">pattern<\/span><span style=\"color: #D73A49\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><span style=\"color: #D73A49\">&lt;\/<\/span><span style=\"color: #24292E\">encoder<\/span><span style=\"color: #D73A49\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">  <\/span><span style=\"color: #D73A49\">&lt;\/<\/span><span style=\"color: #24292E\">appender<\/span><span style=\"color: #D73A49\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">  <\/span><span style=\"color: #D73A49\">&lt;<\/span><span style=\"color: #24292E\">root level<\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #032F62\">&quot;DEBUG&quot;<\/span><span style=\"color: #D73A49\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><span style=\"color: #D73A49\">&lt;<\/span><span style=\"color: #24292E\">appender<\/span><span style=\"color: #D73A49\">-<\/span><span style=\"color: #24292E\">ref ref<\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #032F62\">&quot;STDOUT&quot;<\/span><span style=\"color: #24292E\"> <\/span><span style=\"color: #D73A49\">\/&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">  <\/span><span style=\"color: #D73A49\">&lt;\/<\/span><span style=\"color: #24292E\">root<\/span><span style=\"color: #D73A49\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D73A49\">&lt;\/<\/span><span style=\"color: #24292E\">configuration<\/span><span style=\"color: #D73A49\">&gt;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">ANSI Color Mode on Linux and macOS<\/h3>\n\n\n\n<p>For Linux and macOS no additional configuration is required. These operating systems typically support ANSI colors natively. They do not need Jansi on the classpath, but doing so is harmless. <\/p>\n\n\n\n<p>Following is an example of ANSI color console log output. <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/springframework.guru\/wp-content\/uploads\/2016\/04\/Screenshot-2024-10-18-at-7.38.40\u202fAM.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"101\" src=\"https:\/\/springframework.guru\/wp-content\/uploads\/2016\/04\/Screenshot-2024-10-18-at-7.38.40\u202fAM-1024x101.png\" alt=\"Logback with Spring Boot ANSI Color Console output\" class=\"wp-image-8171\" srcset=\"https:\/\/springframework.guru\/wp-content\/uploads\/2016\/04\/Screenshot-2024-10-18-at-7.38.40\u202fAM-1024x101.png 1024w, https:\/\/springframework.guru\/wp-content\/uploads\/2016\/04\/Screenshot-2024-10-18-at-7.38.40\u202fAM-300x30.png 300w, https:\/\/springframework.guru\/wp-content\/uploads\/2016\/04\/Screenshot-2024-10-18-at-7.38.40\u202fAM-768x76.png 768w, https:\/\/springframework.guru\/wp-content\/uploads\/2016\/04\/Screenshot-2024-10-18-at-7.38.40\u202fAM-1536x151.png 1536w, https:\/\/springframework.guru\/wp-content\/uploads\/2016\/04\/Screenshot-2024-10-18-at-7.38.40\u202fAM-2048x202.png 2048w, https:\/\/springframework.guru\/wp-content\/uploads\/2016\/04\/Screenshot-2024-10-18-at-7.38.40\u202fAM-848x83.png 848w, https:\/\/springframework.guru\/wp-content\/uploads\/2016\/04\/Screenshot-2024-10-18-at-7.38.40\u202fAM-410x40.png 410w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<h1 class=\"wp-block-heading\">Use Log4J2 Instead of Logback with Spring Boot<\/h1>\n\n\n\n<p>For long time, the Java community considered Log4J the &#8220;best&#8221; logging framework. The team behind Log4J announced its end of life in 2015. Log4J is still used in a lot older, legacy applications. <\/p>\n\n\n\n<p>Log4J4 is the successor of Log4J, and had its first GA release in 2014. <\/p>\n\n\n\n<p>To use Log4J2 instead of Logback with Spring Boot, the steps are simple and straightforward. To use Log4J2, we need to:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Exclude Logback from our dependencies <\/li>\n\n\n\n<li>Add the Log4J2 dependency <\/li>\n\n\n\n<li>Add the Log4J2 configuration <\/li>\n<\/ol>\n\n\n\n<p>Since our application code is using SLF4J, rather than the logging framework directly, no further changes are required.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Log4J2 Dependencies<\/h2>\n\n\n\n<p>First we need to exclude the Log4J2 dependency from our Spring Boot starter was follows:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#fff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"&lt;dependency&gt;\n    &lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;\n    &lt;artifactId&gt;spring-boot-starter-web&lt;\/artifactId&gt;\n    &lt;exclusions&gt;\n        &lt;exclusion&gt;\n            &lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;\n            &lt;artifactId&gt;spring-boot-starter-logging&lt;\/artifactId&gt;\n        &lt;\/exclusion&gt;\n    &lt;\/exclusions&gt;\n&lt;\/dependency&gt;\" style=\"color:#24292e;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-light\" style=\"background-color: #fff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #D73A49\">&lt;<\/span><span style=\"color: #24292E\">dependency<\/span><span style=\"color: #D73A49\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><span style=\"color: #D73A49\">&lt;<\/span><span style=\"color: #24292E\">groupId<\/span><span style=\"color: #D73A49\">&gt;<\/span><span style=\"color: #24292E\">org.springframework.boot<\/span><span style=\"color: #D73A49\">&lt;\/<\/span><span style=\"color: #24292E\">groupId<\/span><span style=\"color: #D73A49\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><span style=\"color: #D73A49\">&lt;<\/span><span style=\"color: #24292E\">artifactId<\/span><span style=\"color: #D73A49\">&gt;<\/span><span style=\"color: #24292E\">spring<\/span><span style=\"color: #D73A49\">-<\/span><span style=\"color: #24292E\">boot<\/span><span style=\"color: #D73A49\">-<\/span><span style=\"color: #24292E\">starter<\/span><span style=\"color: #D73A49\">-<\/span><span style=\"color: #24292E\">web<\/span><span style=\"color: #D73A49\">&lt;\/<\/span><span style=\"color: #24292E\">artifactId<\/span><span style=\"color: #D73A49\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><span style=\"color: #D73A49\">&lt;<\/span><span style=\"color: #24292E\">exclusions<\/span><span style=\"color: #D73A49\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">        <\/span><span style=\"color: #D73A49\">&lt;<\/span><span style=\"color: #24292E\">exclusion<\/span><span style=\"color: #D73A49\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">            <\/span><span style=\"color: #D73A49\">&lt;<\/span><span style=\"color: #24292E\">groupId<\/span><span style=\"color: #D73A49\">&gt;<\/span><span style=\"color: #24292E\">org.springframework.boot<\/span><span style=\"color: #D73A49\">&lt;\/<\/span><span style=\"color: #24292E\">groupId<\/span><span style=\"color: #D73A49\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">            <\/span><span style=\"color: #D73A49\">&lt;<\/span><span style=\"color: #24292E\">artifactId<\/span><span style=\"color: #D73A49\">&gt;<\/span><span style=\"color: #24292E\">spring<\/span><span style=\"color: #D73A49\">-<\/span><span style=\"color: #24292E\">boot<\/span><span style=\"color: #D73A49\">-<\/span><span style=\"color: #24292E\">starter<\/span><span style=\"color: #D73A49\">-<\/span><span style=\"color: #24292E\">logging<\/span><span style=\"color: #D73A49\">&lt;\/<\/span><span style=\"color: #24292E\">artifactId<\/span><span style=\"color: #D73A49\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">        <\/span><span style=\"color: #D73A49\">&lt;\/<\/span><span style=\"color: #24292E\">exclusion<\/span><span style=\"color: #D73A49\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><span style=\"color: #D73A49\">&lt;\/<\/span><span style=\"color: #24292E\">exclusions<\/span><span style=\"color: #D73A49\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D73A49\">&lt;\/<\/span><span style=\"color: #24292E\">dependency<\/span><span style=\"color: #D73A49\">&gt;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>Next we need to add the Log4J2 Maven Dependency:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#fff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"&lt;dependency&gt;\n    &lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;\n    &lt;artifactId&gt;spring-boot-starter-log4j2&lt;\/artifactId&gt;\n&lt;\/dependency&gt;\" style=\"color:#24292e;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-light\" style=\"background-color: #fff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #D73A49\">&lt;<\/span><span style=\"color: #24292E\">dependency<\/span><span style=\"color: #D73A49\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><span style=\"color: #D73A49\">&lt;<\/span><span style=\"color: #24292E\">groupId<\/span><span style=\"color: #D73A49\">&gt;<\/span><span style=\"color: #24292E\">org.springframework.boot<\/span><span style=\"color: #D73A49\">&lt;\/<\/span><span style=\"color: #24292E\">groupId<\/span><span style=\"color: #D73A49\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><span style=\"color: #D73A49\">&lt;<\/span><span style=\"color: #24292E\">artifactId<\/span><span style=\"color: #D73A49\">&gt;<\/span><span style=\"color: #24292E\">spring<\/span><span style=\"color: #D73A49\">-<\/span><span style=\"color: #24292E\">boot<\/span><span style=\"color: #D73A49\">-<\/span><span style=\"color: #24292E\">starter<\/span><span style=\"color: #D73A49\">-<\/span><span style=\"color: #24292E\">log4j2<\/span><span style=\"color: #D73A49\">&lt;\/<\/span><span style=\"color: #24292E\">artifactId<\/span><span style=\"color: #D73A49\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D73A49\">&lt;\/<\/span><span style=\"color: #24292E\">dependency<\/span><span style=\"color: #D73A49\">&gt;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Log4J Configuration<\/h2>\n\n\n\n<p>The Spring Boot auto configuration will look for the Log4J2 configration in two files on the classpath:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>log4j2-spring.xml<\/code><\/li>\n\n\n\n<li><code>log4j2.xml<\/code><\/li>\n<\/ul>\n\n\n\n<p>Following is an example <code>log4j2-spring.xml<\/code> configuration file:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#fff\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;\n&lt;Configuration status=&quot;WARN&quot;&gt;\n  &lt;Appenders&gt;\n    &lt;Console name=&quot;Console&quot; target=&quot;SYSTEM_OUT&quot;&gt;\n      &lt;PatternLayout pattern=&quot;%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n&quot;\/&gt;\n    &lt;\/Console&gt;\n  &lt;\/Appenders&gt;\n  &lt;Loggers&gt;\n    &lt;Logger name=&quot;com.foo.Bar&quot; level=&quot;trace&quot; additivity=&quot;false&quot;&gt;\n      &lt;AppenderRef ref=&quot;Console&quot;\/&gt;\n    &lt;\/Logger&gt;\n    &lt;Root level=&quot;error&quot;&gt;\n      &lt;AppenderRef ref=&quot;Console&quot;\/&gt;\n    &lt;\/Root&gt;\n  &lt;\/Loggers&gt;\n&lt;\/Configuration&gt;\" style=\"color:#24292e;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki github-light\" style=\"background-color: #fff\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #D73A49\">&lt;?<\/span><span style=\"color: #24292E\">xml version<\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #032F62\">&quot;1.0&quot;<\/span><span style=\"color: #24292E\"> encoding<\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #032F62\">&quot;UTF-8&quot;<\/span><span style=\"color: #D73A49\">?&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D73A49\">&lt;<\/span><span style=\"color: #24292E\">Configuration status<\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #032F62\">&quot;WARN&quot;<\/span><span style=\"color: #D73A49\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">  <\/span><span style=\"color: #D73A49\">&lt;<\/span><span style=\"color: #24292E\">Appenders<\/span><span style=\"color: #D73A49\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><span style=\"color: #D73A49\">&lt;<\/span><span style=\"color: #24292E\">Console name<\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #032F62\">&quot;Console&quot;<\/span><span style=\"color: #24292E\"> target<\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #032F62\">&quot;SYSTEM_OUT&quot;<\/span><span style=\"color: #D73A49\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">      <\/span><span style=\"color: #D73A49\">&lt;<\/span><span style=\"color: #24292E\">PatternLayout pattern<\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #032F62\">&quot;%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n&quot;<\/span><span style=\"color: #D73A49\">\/&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><span style=\"color: #D73A49\">&lt;\/<\/span><span style=\"color: #24292E\">Console<\/span><span style=\"color: #D73A49\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">  <\/span><span style=\"color: #D73A49\">&lt;\/<\/span><span style=\"color: #24292E\">Appenders<\/span><span style=\"color: #D73A49\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">  <\/span><span style=\"color: #D73A49\">&lt;<\/span><span style=\"color: #24292E\">Loggers<\/span><span style=\"color: #D73A49\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><span style=\"color: #D73A49\">&lt;<\/span><span style=\"color: #24292E\">Logger name<\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #032F62\">&quot;com.foo.Bar&quot;<\/span><span style=\"color: #24292E\"> level<\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #032F62\">&quot;trace&quot;<\/span><span style=\"color: #24292E\"> additivity<\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #032F62\">&quot;false&quot;<\/span><span style=\"color: #D73A49\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">      <\/span><span style=\"color: #D73A49\">&lt;<\/span><span style=\"color: #24292E\">AppenderRef ref<\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #032F62\">&quot;Console&quot;<\/span><span style=\"color: #D73A49\">\/&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><span style=\"color: #D73A49\">&lt;\/<\/span><span style=\"color: #24292E\">Logger<\/span><span style=\"color: #D73A49\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><span style=\"color: #D73A49\">&lt;<\/span><span style=\"color: #24292E\">Root level<\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #032F62\">&quot;error&quot;<\/span><span style=\"color: #D73A49\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">      <\/span><span style=\"color: #D73A49\">&lt;<\/span><span style=\"color: #24292E\">AppenderRef ref<\/span><span style=\"color: #D73A49\">=<\/span><span style=\"color: #032F62\">&quot;Console&quot;<\/span><span style=\"color: #D73A49\">\/&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">    <\/span><span style=\"color: #D73A49\">&lt;\/<\/span><span style=\"color: #24292E\">Root<\/span><span style=\"color: #D73A49\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #24292E\">  <\/span><span style=\"color: #D73A49\">&lt;\/<\/span><span style=\"color: #24292E\">Loggers<\/span><span style=\"color: #D73A49\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D73A49\">&lt;\/<\/span><span style=\"color: #24292E\">Configuration<\/span><span style=\"color: #D73A49\">&gt;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h1 class=\"wp-block-heading\">Conclusion<\/h1>\n\n\n\n<p>The popularity of Logback is trending in the open source community. A number of popular open source projects use Logback for their logging needs.&nbsp;<a title=\"Apache Camel\" href=\"http:\/\/camel.apache.org\/\" target=\"_blank\" rel=\"noopener noreferrer\">Apache Camel<\/a>, <a title=\"Gradle\" href=\"http:\/\/gradle.org\/\" target=\"_blank\" rel=\"noopener noreferrer\">Gradle<\/a>, and <a href=\"http:\/\/www.sonarqube.org\/\" target=\"_blank\" rel=\"noopener noreferrer\">SonarQube<\/a> are just a few examples.<\/p>\n\n\n\n<p>Logback is clearly has the capabilities to handle the needs of logging in a complex enterprise application. So, it&#8217;s no wonder the Spring Boot team selected Logback for the default logging implementation. As you&#8217;ve seen in this post, the Spring Boot team has provided a nice integration with Logback. Out of the box, Logback is ready to use with Spring Boot. In this post, you&#8217;ve seen how easy it is to configure Logback in Spring Boot as your logging requirements evolve.<\/p>\n\n\n\n<p>The source code used in this tutorial is available in my <a href=\"https:\/\/github.com\/spring-framework-guru\/spring-6-posts\/tree\/main\/spring-logback\" target=\"_blank\" rel=\"noopener\" title=\"\">Github account here<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this post we will explore using Spring Boot&#8217;s default logging framework, Logback. Logback makes an excellent logging framework for enterprise applications. It\u2019s fast, and has simple but powerful configuration options, and comes with a small memory footprint. I introduced logback in my introductory post, Logback Introduction: An Enterprise Logging Framework. In a series of [&hellip;]<a href=\"https:\/\/springframework.guru\/using-logback-spring-boot\/\" class=\"df-link-excerpt\">Continue reading<\/a><\/p>\n","protected":false},"author":1,"featured_media":4575,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_lmt_disableupdate":"","_lmt_disable":"","_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"Configuring Logback with Spring Boot is crazy easy. #springboot","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[20,162,104],"tags":[166,29],"class_list":["post-2512","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-java","category-logback","category-spring-boot","tag-logbback","tag-spring-boot"],"jetpack_publicize_connections":[],"aioseo_notices":[],"modified_by":"jt","jetpack_sharing_enabled":true,"jetpack_featured_media_url":"https:\/\/springframework.guru\/wp-content\/uploads\/2018\/06\/NewBannerBOOTSWeb.jpg","jetpack_shortlink":"https:\/\/wp.me\/p5BZrZ-Ew","_links":{"self":[{"href":"https:\/\/springframework.guru\/wp-json\/wp\/v2\/posts\/2512"}],"collection":[{"href":"https:\/\/springframework.guru\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/springframework.guru\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/springframework.guru\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/springframework.guru\/wp-json\/wp\/v2\/comments?post=2512"}],"version-history":[{"count":11,"href":"https:\/\/springframework.guru\/wp-json\/wp\/v2\/posts\/2512\/revisions"}],"predecessor-version":[{"id":8172,"href":"https:\/\/springframework.guru\/wp-json\/wp\/v2\/posts\/2512\/revisions\/8172"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/springframework.guru\/wp-json\/wp\/v2\/media\/4575"}],"wp:attachment":[{"href":"https:\/\/springframework.guru\/wp-json\/wp\/v2\/media?parent=2512"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/springframework.guru\/wp-json\/wp\/v2\/categories?post=2512"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/springframework.guru\/wp-json\/wp\/v2\/tags?post=2512"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}