How to add slf4j marker in quarkus application logs - java

Using quarkus version 1.5.2.Final
LoggerFactory.getLogger("test").info(MarkerFactory.getMarker("TEST_MARKER"),"log statement");
This gets logged as :
2020-09-12 21:08:08,282 INFO [test] (executor-thread-1) log statement
I would also like to include TEST_MARKER in this logline.
Unfortunately Quarkus logging guide doesn't even talk about markers.
My application.properties looks like this
quarkus.http.port=8181
quarkus.http.access-log.enabled=true
quarkus.resteasy.gzip.enabled=true
quarkus.native.additional-build-args =-H:ReflectionConfigurationFiles=reflection-config.json
microprofile.rest.client.disable.default.mapper=true

Related

Spring Logging setting Log level for JDK classes

currently I'm trying to set trace logging level for internal JDK classes, especially for the new HttpClient.
When I add to my application.yaml:
logging:
level:
root: INFO
Everything logs in trace.
But when I want to enable trace logging only for JDK packages like:
logging:
level:
root: INFO
jdk.internal.net.http: TRACE
Those packages don't start log in trace, the entire app uses root level, which is INFO.
What do I need to solve this problem? Thanks guys.

Jetty Runner IDEA Community Logging

I am working on a project using Intellij IDEA Community, so I am using Jetty Runner to deploy my web application in localhost, everything is working ok, but I want to configure logs regarding Jetty, at server startup I see this kind of log :
14:50:20.516 [main] DEBUG o.eclipse.jetty.webapp.WebAppContext - isSystemResource==false org.springframework.expression.spel.ast.OpDec jar:file:/C:/Mario/development/spring/spring5/workspace/springsecurity/chapter02/chapter02.00-calendar/build/exploded/WEB-INF/lib/spring-expression-4.3.11.RELEASE.jar!/org/springframework/expression/spel/ast/OpDec.class
14:50:20.516 [main] DEBUG o.e.jetty.webapp.WebAppClassLoader - WAP webapp loaded class org.springframework.expression.spel.ast.OpDec
14:50:20.516 [main] DEBUG o.eclipse.jetty.webapp.WebAppContext - isSystemResource==false org.springframework.expression.spel.ast.OperatorNot jar:file:/C:/Mario/development/spring/spring5/workspace/springsecurity/chapter02/chapter02.00-calendar/build/exploded/WEB-INF/lib/spring-expression-4.3.11.RELEASE.jar!/org/springframework/expression/spel/ast/OperatorNot.class
14:50:20.517 [main] DEBUG o.e.jetty.webapp.WebAppClassLoader - WAP webapp loaded class org.springframework.expression.spel.ast.OperatorNot
1
I want to change the granularity from DEBUG to info regarding jetty server.
Put a jetty-logging.properties file in your resources folder and configure the logging there:
# Configure for System.err output
org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog
# Configure StdErrLog to log all jetty namespace at default of WARN or above
org.eclipse.jetty.LEVEL=INFO
More info here: https://www.eclipse.org/jetty/documentation/9.4.x/configuring-logging.html

remove hibernate logging from Dropwizard app logs

I see a lot of logs logging al the queries that make the logs not very useful. I am trying to remove this logging from my dropwizard app logs I tried to do it through the yml file
logging:
level: "DEBUG"
loggers:
org.hibernate: ERROR
And also in the logback.xml
<logger name="org.hibernate">
<level value="ERROR" />
</logger>
I also tried appenders to the yml file as console and syslog. What is the way to remove these SELECT statements from the logs?
I dont want to move the logs to another file as I do want to see the errors
The logger isnt org.hibernate but I only see "Hibernate: select * FROM ....."
You should try changing your default application logging level to INFO instead
logging:
level: INFO
and further, modify log level of a package using
# Sets the level for 'org.hibernate' to ERROR
loggers:
org.hibernate: ERROR
Here is an effective example of the usage from dropwizard itself.
Or in your case probably the package contributing to the logs as
loggers:
org.hibernate.SQL: ERROR # note - not moving to another file either
You have to set hibernate.show_sql to false
database:
properties:
hibernate.show_sql: false
However, this alone may not work. I upvoted the other answer as it led me to this - you do indeed have to pay attention to your configured logging levels for the hibernate package because surprisingly, if your org.hibernate.SQL logging level is set to DEBUG then this will override the hibernate.show_sql: false config and log the SQL anyway!
You need to make sure it's set to INFO or greater
logging:
loggers:
"org.hibernate.SQL":
level: INFO
In my case, setting the "hibernate engine" level (in the application.yaml file) decreased the number of log messages:
loggers:
org.hibernate.engine: error

spring-boot default log location

In a spring-boot application I can specify a custom log file with
java -jar spring-boot-app.jar --logging.file=/home/ubuntu/spring-boot-app.log
But if I don't specify one, where does it go?
I couldn't find it in any of the following folders:
/tmp/
/var/log/
~/
I do not have spring-boot-starter-logging or any additional logging dependencies.
I was hoping to have something similar to catalina.out since the default configuration runs an embedded Tomcat:
INFO 10374 --- [main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8100 (http)
Spring Boot uses Commons Logging for all internal logging, but leaves the underlying log implementation open.
Default configurations are provided for Java Util Logging, Log4J, Log4J2 and Logback. In each case loggers are pre-configured to use console output with optional file output also available.
From the Spring Boot logging documentation.
The default log configuration will echo messages to the console as they are written.
So until you explicitly specify a file as you described, it stays in the Console.
By default Spring Boot does not output logs to any file. If you want to have logs written in a file (in addition to the console output) then you should use either of logging.file or logging.path properties (not both).
In application.properties, just set:
logging.file=/home/ubuntu/spring-boot-app.log
This will create a spring-boot-app.log file under /home/ubuntu.
By default, Spring Boot logs only to the console and does not write log files. If you want to write log files in addition to the console output, you need to set a logging.file or logging.path property (for example, in your application.properties).
Below codes in your application.properties will write the log into /home/user/my.log:
logging.path = /home/user
logging.file = my.log

How do I log SQL Statements in Dropwizard

How do I turn on SQL query logging for a Dropwizard application? I would like it to only log SQL in certain environments.
In your application YAML file add a "logging:" definition like the following:
# Logging settings.
logging:
# The default level of all loggers. Can be OFF, ERROR, WARN, INFO, DEBUG, TRACE, or ALL.
level: INFO
# Logger-specific levels.
loggers:
# Overrides the levels of certain packages or files.
"org.skife.jdbi.v2": TRACE
Are you using jdbi?, if so, this is working for me:
Set a logger when you create the DBI instance:
DBI dbi = new DBI(dataSource);
dbi.setSQLLog(new SLF4JLog());
Add this configuration to your config file:
logging:
level: INFO
loggers:
"org.skife": TRACE
I guess this idea should be also valid for Hibernate or any other DB access framework.

Categories