I'm connecting with Java to neo4j using the GraphDatabase.driver and I have this log4j.properties file which suppresses the output of HBase and MongoDB but doesn't work with neo4j:
log4j.rootLogger=OFF, stdout
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{yy/MM/dd HH:mm:ss} %p %c{2}: %m%n
The logging output that shows up in the client application looks like this:
Mär 15, 2018 11:20:03 AM org.neo4j.driver.internal.logging.JULogger info
INFORMATION: Closing driver instance org.neo4j.driver.internal.InternalDriver#6743e411
Mär 15, 2018 11:20:03 AM org.neo4j.driver.internal.logging.JULogger info
INFORMATION: Closing connection pool towards localhost:7687
Mär 15, 2018 11:20:05 AM org.neo4j.driver.internal.logging.JULogger info
How can this be disabled?
The JULogger of the neo4j GraphDatabase.driver can be disabled using the java.util.logging.LogManager
LogManager.getLogManager().reset();
This will disable the logging, thus even suppress error messages. If just the INFO message shown in the example output should be suppressed then the log level has to be changed.
Logger rootLogger = LogManager.getLogManager().getLogger("");
rootLogger.setLevel(Level.SEVERE);
for (Handler h : rootLogger.getHandlers())
h.setLevel(Level.SEVERE);
<logger name="org.neo4j.ogm.drivers.http" level="WARN" additivity="false"></logger>
Related
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
I have hibernate running on app-engine and hibernate logs so much debug infos to the console/log (see attached screenshot) and I can't figure out how to stop it.
My log4j.properties looks like that:
# Root logger option
log4j.rootLogger=WARNING, stdout
# Direct log messages to stdout
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{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
log4j.logger.org.hibernate=WARNING
So this normally should only log warnings right?
My logging.propertis looks like that (But I guess hibernate does not care about that because it uses log4j):
java.util.logging.ConsoleHandler.level = SEVERE
In Log4J the keyword is WARN not WARNING. Thats Java Util Logging. See here.
I want to use Log4j for my logging on AppEngine. I configured the logger like this:
.level = INFO
log4j.rootLogger=DEBUG, stdout
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{ABSOLUTE} %5p %t %c{1}:%M:%L - %m%n
But the logger then logs everything to INFO and the real log level is just shown inline like this: (Log level error)
Is there a way to get the real log levels to work with log4j so that filtering on log levels works on the appengine UI?
Edit: More detailed example:
So I log an error like this:
import org.apache.log4j.Logger;
private static Logger logger = Logger.getLogger(PingServlet.class);
logger.error("Database was successfully pinged.");
And on the Appengine-UI, it shows up as an INFO (the green I). Only the loggin text indicates the correct log level:
The GAE Java documentation states that everything you write to stdout is logged as INFO and to stderr is WARNING [1]. Your root logger is writing everything to stdout.
I'm not a log4j expert, so I don't know of a way for a logger to write to both stdout and stderr. One workaround is to use two loggers, one for INFO and another one for WARNING.
[1] https://cloud.google.com/appengine/docs/java/requests#Java_Logging
My log messages always show up as "info" in the app engine logging console, even if i log a message as error (see screenshot).
I log a message like that:
private static Logger logger = Logger.getLogger(PingServlet.class);
logger.error("Database was successfully pinged!!.");
The configs like this:
src/main/resources/log4j.properties
# Root logger option
log4j.rootLogger=INFO, stdout
# Direct log messages to stdout
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{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
src/main/webapp/WEB-INF/logging.properties
# A default java.util.logging configuration.
# (All App Engine logging is through java.util.logging by default).
#
# To use this configuration, copy it into your application's WEB-INF
# folder and add the following to your appengine-web.xml:
#
# <system-properties>
# <property name="java.util.logging.config.file" value="WEB-INF/logging.properties"/>
# </system-properties>
#
# Set the default logging level for all loggers to WARNING
.level = INFO
How can I change that? I want to show an error as error and so on.
If you are logging with log4j the log messages are being printed to the "console" with ConsoleAppender which AppEngina then collects in its own log. The two log parts you have are not connected.
you either need to use java.util.logging directly instead of log4j or use slf4 to redirect log4j to java.util.logging (a bit tricky, read the documentation carefully)
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