I am using log4j for my application - there I need to see all log messages, so I defined
# General configuration
log4j.rootLogger = ALL, ConsoleAppender
# Appender configuration
log4j.appender.ConsoleAppender = org.apache.log4j.ConsoleAppender
log4j.appender.ConsoleAppender.layout = org.apache.log4j.PatternLayout
log4j.appender.ConsoleAppender.layout.ConversionPattern = %5p (%c) %m%n
But, after I started using Apache's HTTPClient library (which is awesome btw), my console got clouded up by its logging - everything was logged and I am not able to see the log output from my own application any more.
So how can I tell the HTTPClient library that it should only log WARN messages, while my own application still logs on ALL levels?
I create my application logger using
Logger logger = Logger.getLogger(MyClass.class);
PropertyConfigurator.configure("log4j.properties");
It's quite simple. Just add the below line.
log4j.logger.org.apache.commons.httpclient=WARN
Similarly, you can configure levels for any package com.foo or class com.foo.Bar by appending it to the prefix log4j.logger as follows:
log4j.logger.com.foo=MYLEVEL
log4j.logger.com.foo.Bar=DEBUG
Related
I want to create log file for two packages: net.biomodels.jummp.indexing and net.biomodels.jummp.indexing.solrindexer. However, it does not work as I expect. The log only contains what are involving in net.biomodels.jummp.indexing package.
Could you help me finding out the missing of the following logging configuration?
log4j.rootLogger=WARN, R
# everything goes to the general log
log4j.logger.net.biomodels.jummp.indexing=DEBUG, stdout, R
log4j.additivity.net.biomodels.jummp.indexing=false
# I want to log classes in solrindexer package, underneath indexing package
log4j.logger.net.biomodels.jummp.indexing.solrindexer=INFO, stdout, R
log4j.additivity.net.biomodels.jummp.indexing.solrindexer=false
## general log
log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=logs/general.log
log4j.appender.R.MaxFileSize=1MB
log4j.appender.R.MaxBackupIndex=1
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%5p %t %d{ISO8601} %c{2} - %m%n
Your configuration is fine from a syntax point of view. I suspect your log level is the problem. You have your first logger set to DEBUG level:
log4j.logger.net.biomodels.jummp.indexing=DEBUG, stdout, R
while your second logger is set to INFO level:
log4j.logger.net.biomodels.jummp.indexing.solrindexer=INFO, stdout, R
Thus if you are expecting to see DEBUG level logs from classes in the package net.biomodels.jummp.indexing.solrindexer you will not see them unless you change the log level of your logger to DEBUG or lower.
How to enable logging in mysql j connector driver?
I used the following command while creating the connection
"jdbc:mysql://localhost/test?logger=com.mysql.jdbc.log.StandardLogger&profileSQL=true";
My log4j property file is like this
# Root logger option
log4j.rootLogger=TRACE, rfile
log4j.logger.com.mysql=trace, rfile
log4j.appender.rfile = org.apache.log4j.RollingFileAppender
log4j.appender.rfile.File =PrepStmt.log
log4j.appender.rfile.MaxFileSize = 100KB
log4j.appender.rfile.Append = true
log4j.appender.rfile.layout = org.apache.log4j.PatternLayout
log4j.appender.rfile.layout.ConversionPattern= %d [%t] %-5p %c %x - %m%n
No log is getting captured in my log file.
Mysql does not know about your log4j properties.
From the docs, scroll to section Debugging/Profiling:
logger
The name of a class that implements "com.mysql.jdbc.log.Log" that will
be used to log messages to. (default is
"com.mysql.jdbc.log.StandardLogger", which logs to STDERR)
Default: com.mysql.jdbc.log.StandardLogger
So your mysql logs simply go to STDERR. If you want to log to a log4j defined destination you can implement com.mysql.jdbc.log.Log, forward to a log4j logger, and specify that implementation class in the connect URL.
You could configure log4jdbc to intercept the JDBC connection and log the sql.
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
How can I disable Struts2 zillions of logs?
I constantly get logs like this:
2012-04-12 23:20:31,487 DEBUG [XWorkConverter.java:388] : Property: menuExpandedOps
I'm using struts 2.0 and standard java logging (I'm not using log4j).
The logging.properties file of the JVM is set by default to INFO, and I already have struts.devMode = false in my struts.properties file.
If you are free to use log4j, i suggest you to use that, since Log4j has the ability to set different log levels for different packages and hence using the log level OFF we can disable logging for a particular package.
In S2 most of the log messages will be from these packages
xwork2
struts2
freemarker
ognl
and a simple property file/xml file in class-path can help you to turn on or off the logging information.
and a simple property file/xml file in class-path can help you to turn on or off the logging information.
For those who want an example:
1) Put log4j.properties inside src (where your packages are):
2) Turn OFF low-level logging:
# root logger option
log4j.rootLogger=DEBUG, stdout, file
# direct log messages to console
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=[%p: %d{yyyy-MM-dd HH:mm:ss} %F:%L] %m%n
# direct log messages to a log file, support file rolling
log4j.appender.file=org.apache.log4j.DailyRollingFileAppender
log4j.appender.file.File=${catalina.home}/logs/sortingmonitor.log
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=[%p: %d{yyyy-MM-dd HH:mm:ss} %F:%L] %m%n
# disable apache low level logging
log4j.category.com.opensymphony.xwork2=OFF
log4j.category.org.apache.struts2=OFF
log4j.category.freemarker.beans=OFF
log4j.category.freemarker.cache=OFF
Further reading for XML: http://deepaksrivastav.github.io/blog/2011/01/06/disable-struts-2-log-messages/
I want to be able to log debugging messages from my Java classes in a file on my web server, using log4j. I am able to log messages successfully to a file on the server if the Java classes are run from a JUnit test, using the following settings:
log4j.properties:
log4j.appender.rollingFile=org.apache.log4j.RollingFileAppender
log4j.appender.rollingFile.File=D:/logs/fair.log
log4j.appender.rollingFile.MaxFileSize=2MB
log4j.appender.rollingFile.MaxBackupIndex=2
log4j.appender.rollingFile.layout = org.apache.log4j.PatternLayout
log4j.appender.rollingFile.layout.ConversionPattern=%p %t %c - %m%n
log4j.rootLogger = INFO, rollingFile
FairScheduler.java:
private static Logger logger = Logger.getLogger(FairScheduler.class);
logger.info("initializing Scheduler");
But when I deploy the application to my Coldfusion application, the log messages are no longer logged.
How can I configure my Coldfusion server to log messages to this log file (or view any of my log4j log messages at all)?