Unable to stop debug logging in log4J - java

I use log4j on a project that utilizes SpringAMQP to consume and write to a Rabbit pipe. Despite trying everything, I am unable to stop the debug logging on a couple of classes, specifically: Rabbittemplate and BlockingQueueconsumer
My log files are constantly flooded with these these couple of lines.
2014-10-09 11:19:20,914 DEBUG RabbitTemplate - Executing callback on RabbitMQ Channel: Cached Rabbit Channel: AMQChannel(amqp://guest#127.0.0.1:5672/,8)
2014-10-09 11:20:24,141 DEBUG BlockingQueueConsumer - Retrieving delivery for Consumer: tag=[amq.ctag-BbFL7Ow0d_fL_aSaZgXMtg], channel=Cached Rabbit Channel: AMQChannel(amqp://guest#127.0.0.1:5672/,6), acknowledgeMode=AUTO local queue size=0
This is what my Log4J configuration looks like now.
# 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{ABSOLUTE} %5p %c{1}:%L - %m%n
#org.springframework.amqp.rabbit.listener=WARN|ERROR|FATAL
log4j.logger.org.springframework.amqp.rabbit.listener=WARN
I have tried everything in the Log4J configuration to turn off the debug logs on these dependencies but I haven't seen any difference in the logging. I use gradle to manage dependencies and builds and I have the Log4j.properties file in the src/main/resources folder. And it is dumped in the classpath when I build/run the project.
Can anyone help me turn off these logs so that I can keep the logs clean.

Related

Jenkins does not show log4j logs

my problem is that I can not see the JUnit log4j logs of my integration tests, when I run them on jenkins.
When I start them from my local eclipse everything works fine. I tried Java Utils Logging before that worked fine as well.
I tried lots of log4j.properties settings. The current one looks as follows:
# Set root category priority to INFO and its only appender to CONSOLE.
log4j.rootCategory=INFO, CONSOLE
#log4j.rootCategory=INFO, CONSOLE, LOGFILE
# Set the enterprise logger priority to FATAL
log4j.logger.org.apache.axis2.enterprise=FATAL
log4j.logger.de.hunsicker.jalopy.io=FATAL
log4j.logger.httpclient.wire.header=FATAL
log4j.logger.org.apache.commons.httpclient=FATAL
# CONSOLE is set to be a ConsoleAppender using a PatternLayout.
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=[%p] %m%n
# LOGFILE is set to be a File appender using a PatternLayout.
log4j.appender.LOGFILE=org.apache.log4j.FileAppender
log4j.appender.LOGFILE.File=axis2.log
log4j.appender.LOGFILE.Append=true
log4j.appender.LOGFILE.layout=org.apache.log4j.PatternLayout
log4j.appender.LOGFILE.layout.ConversionPattern=%d [%t] %-5p %c %x - %m%n
What am I doing wrong? The log4j.properties file is placed in /src/main/resources. As there is no No log4j appenders-warning in the log, I assume that it is in the classpath and consumed.
I found the solution in Logging while testing through Gradle
The problem was in the gradle settings:
testLogging {
events 'passed', 'failed', 'standardError'
showStandardStreams = true
}

Log4j not writing logs to file on one Websphere server and writing to file on other

I have maven application with log4j.properties in it with setting to write the logs to a specified file instead of console. When I run the EAR on one of the websphere servers it is creating the file as expected and writing logs to it. But, when I am running the same EAR on other webspehere server it is writing to console instead of writing the logs to the specified file. I have checked the permissions and everything seems to be fine. Please help me in identifying what the issue is. Thanks in advance.
# CONSOLE APPENDER (stdout)
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Threshold=DEBUG
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=[%d] [%t] %-5p %20c - %m%n
# ROLLING FILE APPENDER (on the file system) for memberpolicyattributesservice code
log4j.appender.xxxxService=org.apache.log4j.RollingFileAppender
log4j.appender.xxxxService.Threshold=DEBUG
log4j.appender.xxxxService.File=/var/logs/xxxServer1/xxxServiceLog.log
log4j.appender.xxxxService.layout=org.apache.log4j.PatternLayout
log4j.appender.xxxxService.layout.ConversionPattern=%d{MM-dd#HH:mm:ss} %-5p (%13F:%L) %3x - %m%n
log4j.appender.xxxxService.MaxFileSize=10000KB
log4j.appender.xxxxService.MaxBackupIndex=30
log4j.appender.xxxxService.layout=org.apache.log4j.PatternLayout
log4j.appender.xxxxService.layout.ConversionPattern=[%d] [%t] %-5p %20c - %m%n
# ROLLING FILE APPENDER (on the file system) for hiberate, open source code log files
log4j.appender.open_source_code=org.apache.log4j.RollingFileAppender
log4j.appender.open_source_code.layout=org.apache.log4j.PatternLayout
log4j.appender.open_source_code.Threshold=DEBUG
#message format:YYYY-MM-DD HH:mm:ss,ms [ThreadId] <PRIORITY> classname.message
log4j.appender.open_source_code.layout.ConversionPattern=%d [%t]<%-5p> %c.%m \r\n
#file that will be logged to
log4j.appender.open_source_code.File=/var/logs/xxxServer1/open_source_code.log
log4j.appender.open_source_code.Append=true
log4j.appender.open_source_code.MaxFileSize=1024KB
log4j.appender.open_source_code.MaxBackupIndex=5
#turn on log4j verbose mode
log4j.debug = true
# Set root logger level to INFO and its appender to DSInstrumentor,stdout.
log4j.rootLogger=DEBUG,stdout,xxxxService
# YOUR CATEGORIES (to customize logging per class/pkg/project/etc)
log4j.category.fatal=FATAL,xxxxService
log4j.category.error=ERROR,xxxxService
#This will also enable the logging for all the children (packages and classes) of this package
log4j.logger.com.xxxxx=ALL,xxxxService
# Print only messages of level INFO in the open source code
log4j.logger.org=INFO,open_source_code
You have multiple loggers defined in your root logger (DEBUG, stdout, xxxxService) but the xxxxService loggers look like they're bound to the file system on one of the systems:
log4j.appender.open_source_code.File=/var/logs/xxxServer1/open_source_code.log
Make sure that path is valid for each server in your WAS cluster.
As a side note, you should probably avoid using debug and stdout on a remote server. This is fine for local development in your workstation, but not on a remote box. Instead, provide different log4j properties on your various deployment tiers. This lets you customize the log location or appender (say c:\temp or CONSOLE on your desktop, but /var/logs ... on all remote machines) as well as your log levels (DEBUG for desktop, maybe INFO for QA or Staging, and WARN or ERROR for Production).

log4j - Configuration, Ignoring the lib/jar Logging

I am working on a java application and I am using log4j for logging. My "log4j.properties" file (in WEB-INF/conf) is here -
log4j.rootLogger=info, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%p %t %c - %m%n
log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=C:/billingAutomationService/infotrac20.log
log4j.appender.R.MaxFileSize=30MB
log4j.appender.R.MaxBackupIndex=10
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n
In my application there are a some debug messages with logger.debug("debug message"). But with the configuration I ca not see these debug message in my log file - "stdout.log". To see the debug message in my log file ("stdout.log") I have added the following line in my log4j.properties file -
log4j.rootLogger=debug,stdout
But adding this line enables all 'DEBUG' level on my jar/lib along the whole project. I am using a log of spring, hibernate and other jars/libs. This incident makes my log file ("stdout.log") very large even on a single operation. Because a lots of 'DEBUG' message coming from the standard lib/jars which I don't want to debug. Is there any way to turn off the debug message coming form the lib/jars?
Thanks
Please check the below thread.
log4j: package-specific logging
Usually you would have a common package starting for all your files, only enable debug for those package names.
Use root logger as warn.
Also.
Specify only some packages to have debug output

log4j with tomcat does not log what is logged in mvn test

I have a web application. When I run 'mvn test', it logs the debug messages to console, as I have configured it. But when I deploy it to tomcat, I don't see the the logs of the application. I am absolutely sure that I got the log4j.properties file on the right place in the war, as when I change values in the deployed /var/lib/tomcat7/webapps/worldmodel/WEB-INF/classes/log4j.properties for root logger or for hibernate and touch web.xml, I see/chease to see debug logs for hibernate. But I cannot get my application's debug messages to be logged with any configuration I've tried.
Here is how I do the logging:
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
logger = Logger.getLogger(BaseObject.class);
log(Level.DEBUG,"message");
Here is log4j.properties for testing:
log4j.rootLogger=INFO, CONSOLE
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.Encoding=UTF-8
log4j.appender.CONSOLE.layout = org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern = %d [%t] %-5p %c- %m%n
log4j.appender.SYSLOG = org.apache.log4j.net.SyslogAppender
log4j.appender.SYSLOG.syslogHost = 127.0.0.1
log4j.appender.SYSLOG.layout = org.apache.log4j.PatternLayout
log4j.appender.SYSLOG.layout.ConversionPattern = %d [%t] %-5p %c- %m%n
log4j.appender.SYSLOG.Facility = LOCAL0
log4j.logger.org.rulez.magwas.worldmodel=DEBUG
#log4j.logger.org.hibernate.SQL=debug
#log4j.logger.org.hibernate.type.descriptor.sql.BasicBinder=trace
#log4j.logger.org.hibernate.type=trace
here is the log4j.properties which gets deployed:
log4j.rootLogger=INFO, SYSLOG
log4j.appender.SYSLOG = org.apache.log4j.net.SyslogAppender
log4j.appender.SYSLOG.syslogHost = 127.0.0.1
log4j.appender.SYSLOG.layout = org.apache.log4j.PatternLayout
log4j.appender.SYSLOG.layout.ConversionPattern = %d [%t] %-5p %c- %m%n
log4j.appender.SYSLOG.Facility = LOCAL0
log4j.logger.org.rulez.magwas.worldmodel=DEBUG
#log4j.logger.org.hibernate.SQL=debug
#log4j.logger.org.hibernate.type.descriptor.sql.BasicBinder=trace
#log4j.logger.org.hibernate.type=trace
I get such lines in mvn test:
2013-05-21 07:12:17,751 [main] DEBUG org.rulez.magwas.worldmodel.BaseObject- setValue0e9é 072r 074t 0e9é 06bk
The whole project: https://github.com/magwas/worldmodel/commit/c6b08da0a733d9b61257c669e0cc4af9e59444be
edit:
ok, forget it, the code (getter and setter methods in a bean) seems not being been called, perhaps hibernate sets/gets the values directly?
Since, you're configuring your ROOT logger with level INFO it won't display any DEBUG level messages.
log4j.rootLogger=INFO, SYSLOG
The above rootLogger should be configured as DEBUG to see debug and other higher levels (Fatal, Error, Warn and Info) in your logs.
log4j.rootLogger=DEBUG, SYSLOG
I'm not sure what your Maven test case configuration is but perhaps the log4j.properties you've shared isn't having any effect there.
EDIT: It seems from your edit that your logging in production is misconfigured. If your logging is set to INFO it should not log DEBUG messages. I mean, that simply defeats the purpose of having log levels, clearly shows Log4j has not been configured properly and drains Prod resources both space and time.

Shunting certain org.apache.log4j log messages off to a particular log file

We already have extensive logging in our application using org.apache.log4j. We now want to shunt some of these messages off to a new XML log file (while continuing to go to the original log file).
Is this possible? Is there a way we can identify these messages and send them someplace special in addition to the regular log file?
I think you can define two file appenders. One at the root level and other at the package(select the package level as appropriate) level as below:
# Root logger option
log4j.rootLogger=DEBUG, RootFileAppender
#Shunted Logger option
log4j.logger.com.shunted=ERROR,ShuntedFileAppender
# RootFileAppender - used to log messages in the root.log file.
log4j.appender.RootFileAppender=org.apache.log4j.FileAppender
log4j.appender.RootFileAppender.File=root.log
log4j.appender.RootFileAppender.MaxFileSize=100MB
log4j.appender.RootFileAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.RootFileAppender.layout.ConversionPattern= %5p [%t] (%F:%L) - %m%n
# ShuntedFileAppender - used to log messages in the shunted.log file.
log4j.appender.ShuntedFileAppender=org.apache.log4j.FileAppender
log4j.appender.ShuntedFileAppender.File=shunted.log
log4j.appender.ShuntedFileAppender.MaxFileSize=10MB
log4j.appender.ShuntedFileAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.ShuntedFileAppender.layout.ConversionPattern= %5p [%t] (%F:%L) - %m%n
Please Note: You can define the two logger option as different levels as well. In above example, ROOT is defined at DEBUG while shunted is devined as ERROR level.

Categories