spring cloud sleuth cannot geerate spanID - spring

it is necessary to generate a span-id for all that gets into the console log, but unfortunately the span-id is not generated:
2019-03-13 12:35:27.116 INFO [core.data,,,] 13304 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext#1fd386c3: startup date [Wed Mar 13 12:35:27 MSK 2019]; root of context hierarchy
2019-03-13 12:35:27.268 INFO [core.data,,,] 13304 --- [ main] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
2019-03-13 12:35:27.298 INFO [core.data,,,] 13304 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'configurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$66207a2f] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-03-13 14:58:43,737+0300 p=INFO l=org.springframework.boot.web.servlet.FilterRegistrationBean trace-id= span-id= Mapping filter: 'characterEncodingFilter' to: [/*]
2019-03-13 14:58:43,737+0300 p=INFO l=org.springframework.boot.web.servlet.FilterRegistrationBean trace-id= span-id= Mapping filter: 'webMvcMetricsFilter' to: [/*]
2019-03-13 14:58:43,738+0300 p=INFO l=org.springframework.boot.web.servlet.FilterRegistrationBean trace-id= span-id= Mapping filter: 'unauthorizedLogbookFilter' to: [/*]
application.yml
logging:
config: classpath:config/logging/logback.xml
pattern:
console: '%d{"yyyy-MM-dd HH:mm:ss,SSSZ"} %clr(p=%level) %clr(t=%t){yellow} %clr(l=%logger){magenta} %clr(trace-id=%X{X-B3-TraceId:-}){blue} %clr(span-id=%X{X-B3-SpanId:-}){cyan} %msg%n'
level:
org.hibernate: info
org.springframework: info
logback.xml
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<!--spring defaults-->
<include
resource="org/springframework/boot/logging/logback/defaults.xml"/>
<include resource="org/springframework/boot/logging/logback/console-
appender.xml"/>
<!--custom configurations-->
<include resource="config/logging/file-appender.xml"/>
<!-- level configurations-->
<root level="INFO">
<appender-ref ref="CONSOLE"/>
<appender-ref ref="FILE"/>
</root>
span-id generation occurs for an explicitly called logging method:
Logger log = loggerFactory().getLogger(this.class);
public void method(){ log.info("test"); }

First create an Rest Api and make an api request to it, if not already done.
If you are using Restemplate try creating a RestTemplate bean.
Also set the logging level to debug
logging.level.org.springframework.web.servlet.DispatcherServlet=DEBUG

It's not necessary to generate a span-id for all that gets into the console log. Hit your API's then you can see the span-id and trace-id in your logs in console.

Related

spring diasable logging for controller

There is a polling service which fills up my log
2022-01-09T05:24:32,827 DEBUG [ajp-nio-8009-exec-7] o.s.c.l.LogFormatUtils: GET "/VenusD/anonymous/
Somewhat like above. I just need to disable spring logging for a selected controller or request mapping.
What is the right way of doing it? How can I probably exclude it?
If you don't have to change log level of package, comment please.
You can set log level of pacakge.
My log4j2.xml
<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
<Appenders>
<Console name="console" target="SYSTEM_OUT">
<PatternLayout
pattern="[%d{yyyy-MM-dd HH:mm:ss}:%-3relative][%thread] %-5level %logger{100}.%M - %msg%n" />
</Console>
</Appenders>
<Loggers>
<Root level="DEBUG" additivity="false">
<AppenderRef ref="console" />
</Root>
<!-- <Logger name="org.springframework.web.servlet.DispatcherServlet" level="warn"></Logger> -->
</Loggers>
</Configuration>
My log, When I set log levl debug
[2022-01-09 10:01:34:5876][http-nio-8080-exec-1] INFO org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/].log - Initializing Spring DispatcherServlet 'dispatcherServlet'
[2022-01-09 10:01:34:5877][http-nio-8080-exec-1] INFO org.springframework.web.servlet.DispatcherServlet.initServletBean - Initializing Servlet 'dispatcherServlet'
[2022-01-09 10:01:34:5877][http-nio-8080-exec-1] DEBUG org.springframework.web.servlet.DispatcherServlet.initMultipartResolver - Detected StandardServletMultipartResolver
[2022-01-09 10:01:34:5877][http-nio-8080-exec-1] DEBUG org.springframework.web.servlet.DispatcherServlet.initLocaleResolver - Detected AcceptHeaderLocaleResolver
[2022-01-09 10:01:34:5877][http-nio-8080-exec-1] DEBUG org.springframework.web.servlet.DispatcherServlet.initThemeResolver - Detected FixedThemeResolver
[2022-01-09 10:01:34:5877][http-nio-8080-exec-1] DEBUG org.springframework.web.servlet.DispatcherServlet.initRequestToViewNameTranslator - Detected org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator#5889aa66
[2022-01-09 10:01:34:5878][http-nio-8080-exec-1] DEBUG org.springframework.web.servlet.DispatcherServlet.initFlashMapManager - Detected org.springframework.web.servlet.support.SessionFlashMapManager#25bd45e9
[2022-01-09 10:01:34:5878][http-nio-8080-exec-1] DEBUG org.springframework.web.servlet.DispatcherServlet.initServletBean - enableLoggingRequestDetails='false': request parameters and headers will be masked to prevent unsafe logging of potentially sensitive data
[2022-01-09 10:01:34:5878][http-nio-8080-exec-1] INFO org.springframework.web.servlet.DispatcherServlet.initServletBean - Completed initialization in 1 ms
[2022-01-09 10:01:34:5890][http-nio-8080-exec-1] DEBUG org.springframework.web.servlet.DispatcherServlet.traceDebug - GET "/", parameters={}
[2022-01-09 10:01:34:5894][http-nio-8080-exec-1] DEBUG org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping.getHandler - Mapped to com.example.rest.timeout.controller.ControllerTest#get()
[2022-01-09 10:01:34:5919][http-nio-8080-exec-1] DEBUG org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.writeWithMessageConverters - Using 'application/json;q=0.8', given [text/html, application/xhtml+xml, image/avif, image/webp, image/apng, application/xml;q=0.9, application/signed-exchange;v=b3;q=0.9, */*;q=0.8] and supported [application/json, application/*+json, application/json, application/*+json]
[2022-01-09 10:01:34:5919][http-nio-8080-exec-1] DEBUG org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.writeWithMessageConverters - Nothing to write: null body
[2022-01-09 10:01:34:5921][http-nio-8080-exec-1] DEBUG org.springframework.web.servlet.DispatcherServlet.logResult - Completed 200 OK
My log, When I remove following comment in log4j2.xml
<!-- <Logger name="org.springframework.web.servlet.DispatcherServlet" level="warn"></Logger> -->
to
<Logger name="org.springframework.web.servlet.DispatcherServlet" level="warn"></Logger>
Debug log level of org.springframework.web.servlet.DispatcherServlet is removed.
[2022-01-09 10:12:34:666106][http-nio-8080-exec-1] INFO org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/].log - Initializing Spring DispatcherServlet 'dispatcherServlet'
[2022-01-09 10:12:34:666108][http-nio-8080-exec-1] DEBUG org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping.getHandler - Mapped to com.example.rest.timeout.controller.ControllerTest#get()
[2022-01-09 10:12:34:666109][http-nio-8080-exec-1] DEBUG org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.writeWithMessageConverters - Using 'application/json;q=0.8', given [text/html, application/xhtml+xml, image/avif, image/webp, image/apng, application/xml;q=0.9, application/signed-exchange;v=b3;q=0.9, */*;q=0.8] and supported [application/json, application/*+json, application/json, application/*+json]
[2022-01-09 10:12:34:666110][http-nio-8080-exec-1] DEBUG org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.writeWithMessageConverters - Nothing to write: null body

Springboot logging layout

I don't understand what the numbers after logging level indicate
2019-03-05 10:57:51.112 INFO 45469 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/7.0.52
2019-03-05 10:57:51.253 INFO 45469 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2019-03-05 10:57:51.253 INFO 45469 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1358 ms
2019-03-05 10:57:51.698 INFO 45469 --- [ost-startStop-1] o.s.b.c.e.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
2019-03-05 10:57:51.702 INFO 45469 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
For example INFO 45469 what does 45469 indicate?
Other example
1857 [main] 2021-06-23T17:23:04.222+0300 INFO org.springframework.boot.SpringApplication -
1856 [main] 2021-06-23T17:23:04.221+0300 DEBUG org.springframework.boot.StartupInfoLogger -
1853 [main] 2021-06-23T17:23:04.218+0300 INFO org.springframework.boot.StartupInfoLogger -
what is the purpose of the first column?
By looking at the log4j2.xml in spring boot project, it seems the default pattern for the console is :
<Property name="CONSOLE_LOG_PATTERN">
%clr{%d{${LOG_DATEFORMAT_PATTERN}}}{faint} %clr{${LOG_LEVEL_PATTERN}} %clr{${sys:PID}}{magenta} %clr{---}{faint} %clr{[%15.15t]}{faint} %clr{%-40.40c{1.}}{cyan} %clr{:}{faint} %m%n${sys:LOG_EXCEPTION_CONVERSION_WORD}
</Property>
So the number should indicates the PID, so the ID of the process which runs your app.
Personally I never used the default format (for my own logs, yours are the startup logs). My first thing is to replace it whith my configuration. It looks and based on this it should be the PID (process ID).

Spring Boot Application gets stuck on "Hikari-Pool-1 - Starting..."

I'm trying to run Spring Boot application connected to PostgreSQL database. However, when it comes to Hikari connection pool initializing, it just gets stuck and nothing goes on. HikariPool-1 - Starting... appears in logs and then nothing happens.
Logs:
2018-07-09 15:32:48.475 INFO 21920 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext#68999068: startup date [Mon Jul 09 15:32:48 ALMT 2018]; root of context hierarchy
2018-07-09 15:32:48.736 INFO 21920 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'configurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$1b7bd026] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.0.3.RELEASE)
2018-07-09 15:32:49.207 INFO 21920 --- [ main] o.paperplane.todoapp.TodoappApplication : No active profile set, falling back to default profiles: default
2018-07-09 15:32:49.217 INFO 21920 --- [ main] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext#1b410b60: startup date [Mon Jul 09 15:32:49 ALMT 2018]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext#68999068
2018-07-09 15:32:49.763 INFO 21920 --- [ main] o.s.b.f.s.DefaultListableBeanFactory : Overriding bean definition for bean 'dataSource' with a different definition: replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration$Dbcp2; factoryMethodName=dataSource; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Dbcp2.class]] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration$Hikari; factoryMethodName=dataSource; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]]
2018-07-09 15:32:50.046 INFO 21920 --- [ main] o.s.b.f.s.DefaultListableBeanFactory : Overriding bean definition for bean 'dataSource' with a different definition: replacing [Root bean: class [null]; scope=refresh; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=false; primary=false; factoryBeanName=org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration$Hikari; factoryMethodName=dataSource; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]] with [Root bean: class [org.springframework.aop.scope.ScopedProxyFactoryBean]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in BeanDefinition defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]]
2018-07-09 15:32:50.212 INFO 21920 --- [ main] o.s.cloud.context.scope.GenericScope : BeanFactory id=2203ab9b-5bb0-34f2-b496-2cbda1e334a2
2018-07-09 15:32:50.342 INFO 21920 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$ff61cd29] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-07-09 15:32:50.380 INFO 21920 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.security.config.annotation.configuration.ObjectPostProcessorConfiguration' of type [org.springframework.security.config.annotation.configuration.ObjectPostProcessorConfiguration$$EnhancerBySpringCGLIB$$980f9563] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-07-09 15:32:50.389 INFO 21920 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'objectPostProcessor' of type [org.springframework.security.config.annotation.configuration.AutowireBeanFactoryObjectPostProcessor] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-07-09 15:32:50.393 INFO 21920 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler#309028af' of type [org.springframework.security.oauth2.provider.expression.OAuth2MethodSecurityExpressionHandler] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-07-09 15:32:50.397 INFO 21920 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.security.config.annotation.method.configuration.GlobalMethodSecurityConfiguration' of type [org.springframework.security.config.annotation.method.configuration.GlobalMethodSecurityConfiguration$$EnhancerBySpringCGLIB$$bce43815] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-07-09 15:32:50.404 INFO 21920 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'methodSecurityMetadataSource' of type [org.springframework.security.access.method.DelegatingMethodSecurityMetadataSource] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-07-09 15:32:50.424 INFO 21920 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$1b7bd026] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-07-09 15:32:50.692 INFO 21920 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2018-07-09 15:32:50.710 INFO 21920 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2018-07-09 15:32:50.710 INFO 21920 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.31
2018-07-09 15:32:50.714 INFO 21920 --- [ost-startStop-1] o.a.catalina.core.AprLifecycleListener : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [C:\Program Files\Java\jdk1.8.0_151\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Program Files (x86)\Common Files\Intel\Shared Files\cpp\bin\Intel64;C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\7-Zip;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\130\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\140\Tools\Binn\;C:\Program Files\Microsoft SQL Server\140\Tools\Binn\;C:\Program Files\Microsoft SQL Server\140\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\Client SDK\ODBC\130\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\140\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\140\Tools\Binn\ManagementStudio\;D:\node_js\;C:\Program Files\Git\cmd;C:\WINDOWS\System32\OpenSSH\;C:\Users\User\AppData\Local\Microsoft\WindowsApps;C:\Users\User\AppData\Local\GitHubDesktop\bin;C:\Users\User\AppData\Roaming\npm;%USERPROFILE%\AppData\Local\Microsoft\WindowsApps;;.]
2018-07-09 15:32:50.817 INFO 21920 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2018-07-09 15:32:50.817 INFO 21920 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1600 ms
2018-07-09 15:32:51.784 INFO 21920 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2018-07-09 15:32:51.785 INFO 21920 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2018-07-09 15:32:51.785 INFO 21920 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2018-07-09 15:32:51.785 INFO 21920 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
2018-07-09 15:32:51.785 INFO 21920 --- [ost-startStop-1] .s.DelegatingFilterProxyRegistrationBean : Mapping filter: 'springSecurityFilterChain' to: [/*]
2018-07-09 15:32:51.785 INFO 21920 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpTraceFilter' to: [/*]
2018-07-09 15:32:51.786 INFO 21920 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'webMvcMetricsFilter' to: [/*]
2018-07-09 15:32:51.786 INFO 21920 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Servlet dispatcherServlet mapped to [/]
2018-07-09 15:32:51.885 INFO 21920 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
My pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.paperplane</groupId>
<artifactId>todoapp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>todoapp</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<spring-cloud.version>Finchley.RELEASE</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-oauth2</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.3</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.9.3</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
My apllication.properties:
spring.datasource.url=jdbc:postgresql://127.0.0.1:55491/TodoAppDatabase
spring.datasource.username=admin
spring.datasource.password=root
spring.datasource.hikari.connection-timeout=10000
spring.datasource.hikari.driver-class-name=org.postgresql.Driver
spring.datasource.hikari.maximum-pool-size=100
spring.data.jpa.repositories.enabled=true
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto = update
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQL94Dialect
spring.jpa.properties.hibernate.cache.use_query_cache=true
spring.jpa.properties.hibernate.connection.provider_class=com.zaxxer.hikari.hibernate.HikariConnectionProvider
How can I overcome this issue?
Normal postgresql port is 5432, so I assume you also configured it to 55491.
Double check this via your postgresql client using psql -h 127.0.0.1 -p 55491 -d TodoAppDatabase -U admin
At last you can put the HikariCP into DEBUG mode, so you can see what parameters its using.
If your properties file is really apllication.properties than this may also an issue because spring boot only picks up application.properties automatically.
Making below change in application.properties should work fine:
spring.datasource.url=jdbc:postgresql://localhost:5432/<dbName>
Also make sure, you have Fixed Port Number box unchecked, in the pgAdmin configuration BOX, refer the screenshot
In my case spring.datasource.hikari.initializationFailTimeout was set to a really high value, 3600000 (1 hour). This, in it self, was not a malconfiguration but it hid the real problem as the app was hanging on startup.
Once that value was adjusted, I got a much more understandable stack trace which led me to the conclusion that in this case I couldn't use the default MariaDB driver configuration that I probably got through a jHipster.
A very wierd problem that I so far only has seen with MySQL8 and Ubuntu 20 on AWS EC2. Locally I run Ubuntu and MySQL8 via Docker without issues.
It might not be able to connect to DB.
try restarting your DB instance and make sure it is accessible.
try passing this parameter when you run your jar file:
-Djava.security.egd=file:/dev/../dev/urandom
In my case it was a problem with a network connectivity. Make sure you can access your any configured servers if you got into this issue.
telnet host 5432 will let you connect to see if a route exists to the DB server.
in my case (windows 10), it took three steps:
stop the postgresql service running
open command prompt as administrator and kill any service on port 5432
restart the postgresql service from services window.
and you're good.
I had the same problem and solved this by removing the AUTO_SERVER=true line in the application.properties file, so after removing that the application runs as usual.
Remove the AUTO_SERVER=true in #spring.datasource.url=jdbc:... AUTO_SERVER=true
Whit this you loose the functionality to access the database from different sources like from the terminal, meaning you can't access the database from your terminal while your app is running (ie using the database)
But if you need AUTO_SERVER=true then please restart your pc, and with it the database will restart which might solve your problem (this is not a joke).
There could be several reasons why hikaripool-1 is taking a long time to start. One possibility is that there may be high traffic on the network or server, causing delays in processing requests.
Another possibility is that there may be technical issues with the software or hardware, which can also cause delays. It is recommended to check the logs and error messages for any clues about what might be causing the delay and to contact technical support for assistance if necessary.

Spring boot log4j pattern

I'm moving from logback to log4j and I have to replicate the default configuration in Spring Boot for Log4j.
That's what I have so far, but it doesn't look like the previous one.
log4j.category.org.springframework=INFO
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
I'm trying to make it look like this:
2014-03-05 10:57:51.112 INFO 45469 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/7.0.52
2014-03-05 10:57:51.253 INFO 45469 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2014-03-05 10:57:51.253 INFO 45469 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1358 ms
2014-03-05 10:57:51.698 INFO 45469 --- [ost-startStop-1] o.s.b.c.e.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
2014-03-05 10:57:51.702 INFO 45469 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
Where is the config file so I can check the pattern and the rest of the config and see what I'm missing?
This is the pattern you are looking for:
"%d{yyyy-MM-dd HH:mm:ss.SSS} %-4p %4L --- [%15.15t] %-40.40C : %m%n%wEx"
You will get what you want.
Spring Boot Default Logback Configuration
private static final String CONSOLE_LOG_PATTERN = "%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} "
+ "%clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} "
+ "%clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} "
+ "%clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}";
You may find guide which gives detailed explanation about PatternLayout from org.apache.log4j.PatternLayout
There is a sample, maybe you could get some inspiration.
<layout class="org.apache.log4j.EnhancedPatternLayout">
<param name="ConversionPattern" value="%-5p %d{yyyy-MM-dd/HH:mm:ss.SSS}{UTC} [%t] %c{1} -|%-5X{requestId}|- %m%n" />
</layout>
Application log likes:
INFO 2016-07-21/12:14:49.613 [http-nio-9040-exec-9] QrCodeTestController -|29909|- BufferedImage is BufferedImage#2e5adf04: type = 5 ColorModel: #pixelBits = 24 numComponents = 3 color space = java.awt.color.ICC_ColorSpace#4996a909 transparency = 1 has alpha = false isAlphaPre = false ByteInterleavedRaster: width = 556 height = 776 #numDataElements 3 dataOff[0] = 6782

How to turn off debug log messages in spring boot

I read in spring boot docs (https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-logging.html)
you can also specify debug=true in your application.properties"
So I guess I can turn off the debug logs by adding debug=false in application.properties. I did it but unfortunately, it didn't work. Then I read in the same doc
The logging system is initialized early in the application lifecycle and as such logging properties will not be found in property files loaded via #PropertySource annotations"
and
"Since logging is initialized before the ApplicationContext is created, it isn’t possible to control logging from #PropertySources in Spring #Configuration files"
and
"When possible we recommend that you use the -spring variants for your logging configuration" so I added a file named log4j-spring.properties in src/main/resources.
In such file, I added debug=false (only this line and nothing else) but I am still seeing all "current date" [main] DEBUG ... messages. So, my question is how can I turn off the debug messages in my Spring Boot Application as I will deploy to the application to production. Is there a recommended way to reach this via maven?
Added in Feb 12th
The two main methods:
1)By using AnnotationConfigApplicationContext:
public class DemoAppNoBoot {
public static void main(String[] args) {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
BatchConfiguration.class);
JobLauncher jobLauncher = (JobLauncher) context.getBean("jobLauncher");
Job job = (Job) context.getBean("job");
try {
JobExecution execution = jobLauncher.run(job, new JobParameters());
} catch (Exception e) {
e.printStackTrace();
}
}
}
Snippet output:
08:26:18.713 [main] DEBUG o.s.core.env.StandardEnvironment - Adding [systemProperties] PropertySource with lowest search precedence
08:26:18.744 [main] DEBUG o.s.core.env.StandardEnvironment - Adding [systemEnvironment] PropertySource with lowest search precedence
08:26:18.744 [main] DEBUG o.s.core.env.StandardEnvironment - Initialized StandardEnvironment with PropertySources [systemProperties,systemEnvironment]
08:26:18.947 [main] INFO o.s.c.a.AnnotationConfigApplicationContext - Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext#532760d8: startup date [Fri Feb 12 08:26:18 CST 2016]; root of context hierarchy
08:26:18.947 [main] DEBUG o.s.c.a.AnnotationConfigApplicationContext - Bean factory for org.springframework.context.annotation.AnnotationConfigApplicationContext#532760d8: org.springframework.beans.factory.support.DefaultListableBeanFactory#50b494a6: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.event.internalEventListenerProcessor,org.springframework.context.event.internalEventListenerFactory,batchConfiguration]; root of factory hierarchy
08:26:18.979 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating shared instance of singleton bean
...
08:26:32.560 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'lifecycleProcessor'
08:26:32.560 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'org.springframework.context.annotation.internalScheduledAnnotationProcessor'
08:26:32.560 [main] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor'
08:26:32.560 [main] DEBUG o.s.s.a.ScheduledAnnotationBeanPostProcessor - Could not find default TaskScheduler bean
org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.scheduling.TaskScheduler] is defined at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:372) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE] at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:332) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
...
08:26:33.529 [pool-1-thread-1] DEBUG o.s.jdbc.core.JdbcTemplate - Executing prepared SQL update
08:26:33.529 [pool-1-thread-1] DEBUG o.s.jdbc.core.JdbcTemplate - Executing prepared SQL statement [UPDATE BATCH_JOB_EXECUTION set START_TIME = ?, END_TIME = ?, STATUS = ?, EXIT_CODE = ?, EXIT_MESSAGE = ?, VERSION = ?, CREATE_TIME = ?, LAST_UPDATED = ? where JOB_EXECUTION_ID = ? and VERSION = ?]
08:26:33.529 [pool-1-thread-1] DEBUG o.s.jdbc.core.JdbcTemplate - SQL update affected 1 rows
08:26:33.545 [pool-1-thread-1] DEBUG o.s.j.d.DataSourceTransactionManager - Initiating transaction commit
08:26:33.545 [pool-1-thread-1] DEBUG o.s.j.d.DataSourceTransactionManager - Committing JDBC transaction on Connection [org.hsqldb.jdbc.JDBCConnection#33bbce9c]
08:26:33.545 [pool-1-thread-1] DEBUG o.s.j.d.DataSourceTransactionManager - Releasing JDBC Connection [org.hsqldb.jdbc.JDBCConnection#33bbce9c] after transaction
08:26:33.545 [pool-1-thread-1] DEBUG o.s.jdbc.datasource.DataSourceUtils - Returning JDBC Connection to DataSource
08:26:33.545 [pool-1-thread-1] INFO o.s.b.c.l.support.SimpleJobLauncher - Job: [SimpleJob: [name=job1]] completed with the following parameters: [{}] and the following status: [COMPLETED]
Main method with SpringApplication.run
#SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(BatchConfiguration.class, args);
}
}
Entire output:
: Spring Boot :: (v1.3.1.RELEASE)
2016-02-12 08:02:36.145 INFO 12172 --- [ main] com.example.DemoApplication : Starting DemoApplication on GH-VDIKCISV252 with PID 12172 (C:\STS\wsRestTemplate\demo\target\classes started by e049447 in C:\STS\wsRestTemplate\demo)
2016-02-12 08:02:36.145 INFO 12172 --- [ main] com.example.DemoApplication : No active profile set, falling back to default profiles: default
2016-02-12 08:02:36.473 INFO 12172 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext#4e4aea35: startup date [Fri Feb 12 08:02:36 CST 2016]; root of context hierarchy
2016-02-12 08:02:42.176 WARN 12172 --- [ main] o.s.c.a.ConfigurationClassEnhancer : #Bean method ScopeConfiguration.stepScope is non-static and returns an object assignable to Spring's BeanFactoryPostProcessor interface. This will result in a failure to process annotations such as #Autowired, #Resource and #PostConstruct within the method's declaring #Configuration class. Add the 'static' modifier to this method to avoid these container lifecycle issues; see #Bean javadoc for complete details.
2016-02-12 08:02:42.349 WARN 12172 --- [ main] o.s.c.a.ConfigurationClassEnhancer : #Bean method ScopeConfiguration.jobScope is non-static and returns an object assignable to Spring's BeanFactoryPostProcessor interface. This will result in a failure to process annotations such as #Autowired, #Resource and #PostConstruct within the method's declaring #Configuration class. Add the 'static' modifier to this method to avoid these container lifecycle issues; see #Bean javadoc for complete details.
2016-02-12 08:02:42.724 INFO 12172 --- [ main] o.s.j.d.e.EmbeddedDatabaseFactory : Starting embedded database: url='jdbc:hsqldb:mem:testdb', username='sa'
2016-02-12 08:02:43.802 WARN 12172 --- [ main] o.s.b.c.l.AbstractListenerFactoryBean : org.springframework.batch.item.ItemReader is an interface. The implementing class will not be queried for annotation based listener configurations. If using #StepScope on a #Bean method, be sure to return the implementing class so listner annotations can be used.
2016-02-12 08:02:44.990 INFO 12172 --- [ main] o.s.jdbc.datasource.init.ScriptUtils : Executing SQL script from class path resource [org/springframework/batch/core/schema-hsqldb.sql]
2016-02-12 08:02:45.179 INFO 12172 --- [ main] o.s.jdbc.datasource.init.ScriptUtils : Executed SQL script from class path resource [org/springframework/batch/core/schema-hsqldb.sql] in 189 ms.
2016-02-12 08:02:46.804 INFO 12172 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2016-02-12 08:02:46.868 INFO 12172 --- [ main] o.s.b.a.b.JobLauncherCommandLineRunner : Running default command line with: []
2016-02-12 08:02:46.962 INFO 12172 --- [ main] o.s.b.c.r.s.JobRepositoryFactoryBean : No database type set, using meta data indicating: HSQL
2016-02-12 08:02:47.040 INFO 12172 --- [pool-2-thread-1] o.s.b.c.r.s.JobRepositoryFactoryBean : No database type set, using meta data indicating: HSQL
2016-02-12 08:02:47.243 INFO 12172 --- [ main] o.s.b.c.l.support.SimpleJobLauncher : No TaskExecutor has been set, defaulting to synchronous executor.
2016-02-12 08:02:47.259 INFO 12172 --- [pool-2-thread-1] o.s.b.c.l.support.SimpleJobLauncher : No TaskExecutor has been set, defaulting to synchronous executor.
2016-02-12 08:02:47.321 INFO 12172 --- [ main] o.s.b.c.l.support.SimpleJobLauncher : Job: [SimpleJob: [name=job1]] launched with the following parameters: [{run.id=1}]
2016-02-12 08:02:47.368 INFO 12172 --- [ main] o.s.batch.core.job.SimpleStepHandler : Executing step: [step1]
2016-02-12 08:02:47.400 INFO 12172 --- [ main] com.example.CustomItemReader : read method - collecting the MYAPP2 out file names
2016-02-12 08:02:47.525 INFO 12172 --- [ main] com.example.CustomItemReader : read method - no file found
2016-02-12 08:02:47.556 INFO 12172 --- [ main] o.s.b.c.l.support.SimpleJobLauncher : Job: [SimpleJob: [name=job1]] completed with the following parameters: [{run.id=1}] and the following status: [COMPLETED]
2016-02-12 08:02:47.556 INFO 12172 --- [ main] com.example.DemoApplication : Started DemoApplication in 12.1 seconds (JVM running for 13.405)
2016-02-12 08:02:47.556 INFO 12172 --- [pool-2-thread-1] o.s.b.c.l.support.SimpleJobLauncher : Job: [SimpleJob: [name=job1]] launched with the following parameters: [{}]
2016-02-12 08:02:47.618 INFO 12172 --- [pool-2-thread-1] o.s.batch.core.job.SimpleStepHandler : Executing step: [step1]
2016-02-12 08:02:47.634 INFO 12172 --- [pool-2-thread-1] com.example.CustomItemReader : read method - collecting the MYAPP2 out file names
2016-02-12 08:02:47.634 INFO 12172 --- [pool-2-thread-1] com.example.CustomItemReader : read method - no file found
2016-02-12 08:02:47.650 INFO 12172 --- [pool-2-thread-1] o.s.b.c.l.support.SimpleJobLauncher : Job: [SimpleJob: [name=job1]] completed with the following parameters: [{}] and the following status: [COMPLETED]
BatchConfiguration class
#Configuration
#ComponentScan("com.example")
#EnableBatchProcessing
#EnableAutoConfiguration
#EnableScheduling
#PropertySource("config.properties")
public class BatchConfiguration {
#Autowired
private JobBuilderFactory jobBuilderFactory;
#Autowired
private StepBuilderFactory stepBuilderFactory;
#Bean
public Step step1(ItemReader<String> reader,
ItemProcessor<String, String> processor, ItemWriter<String> writer) {
return stepBuilderFactory.get("step1").<String, String> chunk(1) .reader(reader).processor(processor).writer(writer)
.allowStartIfComplete(true).build();
}
//I took out the rest of BatchConfiguration class
Application.properties (only one line)
logging.level.*=OFF
P.S. I will not show config.properties because it only contains several property names with path settup used in business logic
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.1.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<spring.batch.version>3.0.6.RELEASE</spring.batch.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-batch</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.example.DemoAppNoBoot</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<goals>install</goals>
<preparationGoals>install</preparationGoals>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>com.example.DemoAppNoBoot</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>
Maven Dependencies (the relevant ones for my doubt):
logback-classic-1.1.3.jar
logback-core-1.1.3.jar
slf4j-api-1.7.13.jar
log4j-over-slf4j-1.7.13.jar
In application.properties you can add ‘logging.level.*=LEVEL’ where ‘LEVEL’ is one of TRACE, DEBUG, INFO, WARN, ERROR, FATAL, OFF. * is responsible for package/class.
For example
logging.level.root=WARN
logging.level.org.springframework.web=DEBUG
logging.level.org.hibernate=ERROR
This means that root logger has WARN level.
org.springframework.web is on DEBUG level, but all hibernates files are logged only ERROR.
In your case you must set logging.level.root on one of level from INFO, WARN, ERROR,FATAL or OFF to turn off all logging.
See https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-logging.html#boot-features-custom-log-levels
While using Spring Rest Docs with SpringMockMVC with testLogging.showStandardStreams set to true in Gradle, Spring cluttered the console with info & debug logs. I had to use Mkyong's solution where in a logback-test.xml in src/test/resources needs to be created on top of the chosen solution here. Use log-level OFF, ERROR, WARN, DEBUG
logback-test.xml
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/base.xml" />
<logger name="org.springframework" level="ERROR"/>
</configuration>
in addition to a log4j.properties or log4j.xml file you will need all three of these entries in your maven pom.xml... adding the log4j-acl artifact instantly fixed the problem for me. it routes apache-commons-logging entries from commons logging over to log4j
I'm not sure how you would go about this in grunt but the bridge is what you need.
<!-- Log4J -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-jcl</artifactId>
<version>${log4j.version}</version>
</dependency>
Simply add these two lines to you app main:
Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
root.setLevel(Level.ERROR);
The necessary import are:
import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.Logger;
import org.slf4j.LoggerFactory;
I am using XML configured Log4j2 and Spring Boot. For me, I needed to specify the logging subpackage also, so inside the <Loggers> block:
<Logger name="org.springframework.boot.autoconfigure.logging" level="error" />
You can also use bellow pattern to see the neat logging results in Console.
logging.pattern.console=%clr(%d{yy-MM-dd E HH:mm:ss.SSS}){blue} %clr(%-5p) %clr(%logger{0}){blue} %clr(%m){faint}%n
Click Breakpoints icon and untick checkBox. After Done Re-Run again

Resources