I'm using Spring Boot 1.3.2, with Logback, and using EhCache as the Hibernate second-level cache with JGroups 3.6.8.Final for distribution. All of the log messages for org.jgroups loggers are coming out as unknown.jul.logger. This originates in the SLF4JBridgeHandler that Spring Boot installs to bridge java.util.logging loggers over to SLF4J.
Is there something I can do to have the logger name propagated over to the SLF4J logger? When I was using JGroups 3.1.0.Final it was working fine, but after the upgrade all I get is the unknown logger.
Since jgroups 3.6.x I switched to the following configuration (slf4j + log4j2).
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.6</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.5</version>
</dependency>
Related
I am using Zipkin server to aggregate the logs, and my project uses Spring Boot 3.0.2
and want to push logs to RabbitMQ with micrometer.
The pom.xml contains:
<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-micrometer</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-tracing-bridge-otel</artifactId>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-exporter-zipkin</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.amqp</groupId>
<artifactId>spring-rabbit</artifactId>
</dependency>
and the properties file contains:
management.tracing.sampling.probability=1.0
management.zipkin.tracing.endpoint=http://localhost:9411/api/v2/spans
management.metrics.distribution.percentiles-histogram.http.server.requests=true
logging.pattern.level=%5p [${spring.application.name:},%X{traceId:-},%X{spanId:-}]
spring.rabbitmq.host=localhost
spring.rabbitmq.port=5672
spring.rabbitmq.username=guest
spring.rabbitmq.password=guest
But I cannot see any message in the queue when I call any endpoint.
I am migrating from open tracing to open telemetry with jaeger.
Earlier the pom had following:
<dependency>
<groupId>io.opentracing</groupId>
<artifactId>opentracing-api</artifactId>
<version>0.31.0</version>
</dependency>
<dependency>
<groupId>io.opentracing.contrib</groupId>
<artifactId>opentracing-spring-cloud-starter</artifactId>
<version>0.1.13</version>
</dependency>
<dependency>
<groupId>io.jaegertracing</groupId>
<artifactId>jaeger-client</artifactId>
<version>0.31.0</version>
</dependency>
Then I migrated from java 8 spring boot v2.3 to java 17 spring boot v3. So I updated the config as follows:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-sleuth</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-sleuth-brave</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-sleuth-otel-autoconfigure</artifactId>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-exporter-otlp-trace</artifactId>
<version>1.14.0</version>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-okhttp</artifactId>
<version>1.51.0</version>
</dependency>
the properties are mentioned below:
<java.version>17</java.version>
<spring-boot.version>3.0.0</spring-boot.version>
<spring-cloud.version>2021.0.5</spring-cloud.version>
<spring-cloud-sleuth-otel.version>1.1.0</spring-cloud-sleuth-otel.version>
<opentelemetry-exporter-otlp>1.20.1</opentelemetry-exporter-otlp>
The problem I encounter is that the spans are not logged. I do not see any logs that say span reported, which I usually get before. I haven't connected this to any collector or added any telemetry related configuration. I was following this tutorial () but it says the app should work out of the box.
What kind of configurations am I missing here?
EDIT: The second approach (The open telemetry one) works when spring boot version is 2.5.6 (https://qdnqn.com/opentelemetry-spring-boot-kafka-and-jaeger-in-action/) but not when 3.0. How can make this work in spring boot 3?
I am trying to upgrade log4j to log4j2.I am using some methods of log4j1 like removeAllappender(),setName(), these not found in log4j2.
I have included these dependencies:-
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.14.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.14.1</version>
</dependency>
I tried to include bridge also but it fails the build. How can I solve these?
note:-My project is in maven.
**i have also added bridge dependency 1.x to 2.x
I use SL4J for logging in my Java Spring MVC Web Application. I have the logback.xml file under /src/main/resources. In my pom.xml file, I have the following related to logging:
<properties>
<org.slf4j-version>1.6.4</org.slf4j-version>
<logback.version>1.0.1</logback.version>
</properties>
And the following dependencies:
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${org.springframework-version}</version>
<exclusions>
<!-- Exclude Commons Logging in favor of SLF4j -->
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- Logging -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${org.slf4j-version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>${org.slf4j-version}</version>
<scope>runtime</scope>
</dependency>
<!-- logback -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback.version}</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>${logback.version}</version>
</dependency>
</dependencies>
Now logging is working fine for me. But now I am trying to move the logback.xml file outside the war file so that I do not have to change the war file to change the logging level. I was trying to move the file to ${catalina.base}/conf/. I was unable to find a way to specify the path of the file which would be ${catalina.base}/conf/logback.xml. I have found a couple of similar questions, but I couldint find a solution that I could use:
Externalized the location of logback.xml in Spring Boot using application.properties and
logback externalization. Is there any way I can move the file under the conf folder under tomcat and specify its path so that I can keep this logback.xml ouside the war file
It is not good idea to put logging properties in tomcat config folder. Better to put it inside application folder/war.
But there is a way to locate logback.xml from external directory by setting a property in your spring application properties file.
For example in application.properties add
logging.config=file:/home/user/tomcat/conf/logback.xml
I would like to have all the internal Springboot log messages directed to log4j so that the messages follow my log4j properties (i.e. they go to the console and my log4j file using my layout).
I attempted to configure Springboot to use only log4j logging per this guide: http://spring.io/blog/2009/12/04/logging-dependencies-in-spring/
I have successfully setup log4j to log to the console and to file when using a log4j logger object.
However, it appears that Springboot is still using slf4j when it logs internally. I tried removing the slf4j dependencies, but Springboot fails to startup with a missing class exception.
How can I direct all the internal Springboot logging to log4j?
Have you tried this from the official docs?
http://docs.spring.io/spring-boot/docs/1.2.2.RELEASE/reference/htmlsingle/#howto-configure-log4j-for-logging
Basically you have to exclude the logback stuff that comes by default with the starter poms.
Quoted here for reference:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j</artifactId>
</dependency>
If you are using spring-boot, I recommend following the spring documentation, which I found easier than your reference.
I have log4j working, and it prints messages like:
[2015-03-06 15:34:54 INFO ] [main] [tomcat.TomcatEmbeddedServletContainer] Tomcat initialized with port(s): 8080 (http)
Not sure if that's what you mean by internal messages.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot</artifactId>
<version>1.1.4.RELEASE</version>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- add slf4j interfaces to classpath this is for log4j -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.6.4</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.6.4</version>
<scope>runtime</scope>
</dependency>
<!-- add log4j to classpath -->
<!-- does the logging -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
</dependency>
Add log4j.properties under resources
log4j.rootLogger=INFO, Console, File
# Direct log messages to stdout
log4j.appender.Console=org.apache.log4j.ConsoleAppender
log4j.appender.Console.Target=System.out
log4j.appender.Console.layout=org.apache.log4j.PatternLayout
log4j.appender.Console.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} [%t] %-5p %c{1}:%L - %m%n
log4j.appender.File=org.apache.log4j.RollingFileAppender
log4j.appender.File.append=true
log4j.appender.File.file=/tmp/projectdir/logfile-ws.log
log4j.appender.File.threshold=INFO
log4j.appender.File.layout=org.apache.log4j.PatternLayout
log4j.appender.File.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} [%t] %-5p %c{1}:%L - %m%n
log4j.appender.File.MaxFileSize=100MB
log4j.appender.File.MaxBackupIndex=1