Disable false-positive C3P0 logs - java

My Java7 project uses c3p0 (0.9.5.1) for connection pooling and Log4j (1.2.17) for logging. It seems that log4j logs c3p0 INFO logs in ERROR level:
2017-02-09T21:30:19.545+01:00 app_r41 jsvclog[5135] err: JSVC [MLog-Init-Reporter] INFO com.mchange.v2.log.MLog - MLog clients using slf4j logging.
2017-02-09T21:30:19.959+01:00 app_r41 jsvclog[5135] err: JSVC [main] INFO com.mchange.v2.c3p0.C3P0Registry - Initializing c3p0-0.9.5.1 [built 16-June-2015 00:06:36 -0700; debug? true; trace: 10]
2017-02-09T21:30:21.294+01:00 app_r41 jsvclog[5135] err: JSVC [main] INFO com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource - [configuration of ComboPooledDataSource follows here...]
Now this is confusing and I want to disable it.
This is the relevant part of my log4j.properties configuration:
log4j.rootLogger=INFO, SYSLOG_APPENDER
log4j.logger.com.mchange=WARN, SYSLOG_APPENDER
What am I missing?

Setting this system property during service start-up fixes the problem:
System.setProperty( "com.mchange.v2.log.Log4jMLog.DEFAULT_CUTOFF_LEVEL", "WARNING" );

Related

Spring Boot JDBC Transaction Logging settings

How do I set the following in Spring Boot JDBC Transaction Logging with yaml file?
org.springframework.transaction.interceptor to TRACE level
org.springframework.transaction.support to DEBUG level
The following is not working in application.yml
org:
springframework:
transaction:
support: DEBUG
interceptor: TRACE
Current Yaml:
logging:
level:
org:
tomcat: INFO
catalina: INFO
Should be:
logging:
level:
org.springframework.transaction.interceptor: TRACE
org.springframework.transaction.support: DEBUG
org.tomcat: INFO
org.catalina: INFO

How do I suppress INFO messages when using Kafka in Java?

I use Apache Kafka client in Java and now I'm getting a lot of messages with [INFO] mark. All the suggestions I've found on the Internet are of changing log4j output level. But I don't use log4j.
A small part of output:
[main] INFO org.apache.kafka.common.utils.AppInfoParser - Kafka version: 2.2.0
[main] INFO org.apache.kafka.common.utils.AppInfoParser - Kafka commitId: 05fcfde8f69b0349
[main] INFO org.apache.kafka.clients.consumer.KafkaConsumer - [Consumer clientId=consumer-1, groupId=group3] Subscribed to topic(s): test.topics.tasks
UPDATE:
I use org.apache.kafka:kafka-clients:2.2.0
But I don't use log4j.
Maybe you don't, but some library that you pull, probably does (for example, Spring).
You should consult the documentation for the framework that you use (if any), otherwise, you can add your own log4j.properties file into your classpath like so.
log4j.rootLogger=WARN, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=[%d] %p %m (%c)%n
log4j.appender.stdout.Target=System.out
You can do this programmatically by adding this line in your code System.setProperty(org.slf4j.impl.SimpleLogger.DEFAULT_LOG_LEVEL_KEY, "off");
This is because Kafka is using sl4j for logging, so disabling sl4j logging will suppress info messages. If you wish to log for other levels/purposes, you can replace "off" with one of these: "trace", "debug", "info", "warn", "error" based on https://www.slf4j.org/api/org/slf4j/impl/SimpleLogger.html

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

SL4J timestamps

I just switched my project from JUL (java.util.logging) to SL4J over JUL. Everything works great, I only have one grievance: when logging, the timestamps are not very relevant to me, for example:
2 [pool-2-thread-1] INFO com.lexit.server.ServerContext - Context initialized.
703 [pool-2-thread-1] INFO com.lexit.server.ServerContext - Connection with database succesful.
1144 [pool-2-thread-1] INFO com.lexit.server.ServerContext - External emails will be sent
1144 [pool-2-thread-1] INFO com.lexit.server.ServerContext - Alarms will be sent fr
1146 [pool-2-thread-1] INFO java.lang.Class - Adding reccuring timer with id: 1234567
How can I configure SL4J to have more relevant timestamps (e.g. 8-Mar-2012 5:38:00 PM)??
That's the logging format emitted by SLF4J's SimpleLogger.
See for yourself at:
http://www.slf4j.org/apidocs/org/slf4j/impl/SimpleLogger.html
SimpleLogger is the logger that gets used when you haven't added one of the SLF4J "bridge" jars to your classpath. Make sure you add slf4j-jdk14-x.x.x.jar (the JUL bridge) to your classpath, so that SLF4J will be configured to bridge to JUL.

Unable to disable Hibernate log messages

I'm using Hibernate for a personal project.
In my project, I have these directory:
+ conf
log4j.properties
+ bin
my classes
Using Windows console, I go to project directory (the parent of bin and conf) and I start the application with a command like this:
java -cp conf;lib/lib1.jar;lib/lib2.jar;[etc] com.moc.Main
My log4j.properties file is this (taken from an hibernate example):
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d - %m%n
log4j.rootLogger=info, stdout
log4j.logger.org.hibernate=error
log4j.logger.org.hibernate.tool.hbm2ddl=error
log4j.logger.org.hibernate.hql.ast.QueryTranslatorImpl=error
log4j.logger.org.hibernate.hql.ast.HqlSqlWalker=error
log4j.logger.org.hibernate.hql.ast.SqlGenerator=error
log4j.logger.org.hibernate.hql.ast.AST=error
On application start, this is the output:
2010-11-06 19:00:56,376 - Logger.getRootLogger().info() statement
12 [main] INFO org.hibernate.cfg.Environment - Hibernate 3.5.3-Final
13 [main] INFO org.hibernate.cfg.Environment - hibernate.properties not found
16 [main] INFO org.hibernate.cfg.Environment - Bytecode provider name : javassist
20 [main] INFO org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
108 [main] INFO org.hibernate.cfg.Configuration - configuring from resource: com/moc/hibernate.cfg.xml
108 [main] INFO org.hibernate.cfg.Configuration - Configuration resource: com/moc/hibernate.cfg.xml
124 [main] INFO org.hibernate.cfg.Configuration - Reading mappings from file: conf\hiber\Customer.hbm.xml
.
.
.
and so on
.
.
.
795 [main] INFO org.hibernate.impl.SessionFactoryImpl - closing
795 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - cleaning up connection pool: jdbc:mysql://localhost/mydb
The color of Hibernate log lines is red, my log lines are black.
Why I still see INFO output from Hibernate? What am I doing wrong?
A good way of checking your log4j configuration and the events occuring at runtime is adding
-Dlog4j.debug option to the java command line. In your case it will become:
java -Dlog4j.debug -cp conf;lib/lib1.jar;lib/lib2.jar;[etc] com.moc.Main
This will throw information on console of the sequence of loading of log4j configuration. You can then determine if your log4j.properties is getting loaded correctly or not.
Your log4j configuration looks ok, is your log4j.properties file on the classpath and in the root package? I.e. is it in the root of conf, lib1.jar, lib2.jar pr any other jar/directory in your classpath?
Try this to check if the file is being loaded correctly.
On this line:
log4j.rootLogger=info, stdout
chage to
log4j.rootLogger=error, stdout
This will set the log level for the root logger and hence all loggers to ERROR, if you are still seeing the INFO log entries then your log4j.properties file must not be loading correctly, most likely for the reasons stated above.
Can you try this syntax instead?
log4j.category.org.hibernate=ERROR

Categories