Enable TRACE in custom DFS application (DfLogger, log4j) - java

Summary
We're struggling with enabling log4j's TRACE level in a custom Documentum DFS application. The application runs on Tomcat 7.0 and uses Log4j 1.2.13, and is packaged as a WAR archive.
We have an appender called CustomServiceAppender that works just fine with all the other levels, i.e. DEBUG and upwards. During development we have this appender configured for the DEBUG level, and for production we change it to INFO or WARN. The logging then behaves like we expect (it limits the logging).
However we have written some code that logs at the TRACE level that we want to see in our logs. We've tried restarting, redeploying, deleting cache, checking log4j and commons-logging versions (they are 1.2.13 and 1.1.1, respectively). Also, there is no XML configuration file, and we know that our properties file is being picked up.
We use the default logger from DFS, namely the DfLogger class.
Changing the configuration - why doesn't it work?
In log4j.properties we change the following line from
log4j.logger.com.mycompany.services=DEBUG,CustomerServiceAppender
to
log4j.logger.com.mycompany.services=TRACE,CustomerServiceAppender
... which does not work! However, the following does work:
log4j.logger.com.mycompany.services=INFO,CustomerServiceAppender
What's happening here? Why can't we enable TRACE?
log4j.properties
For reference, here's our complete configuration file (identifying names altered):
#------------------- COMMON LOGGING LEVELS --------------------------
log4j.logger.com.emc.documentum.fs.rt = WARN, A1, F1
log4j.logger.com.emc.documentum.fs.datamodel = WARN, A1, F1
log4j.logger.com.emc.documentum.fs.services = WARN, A1, F1
log4j.logger.com.emc.documentum.fs.tools = WARN, A1, F1
log4j.logger.com.documentum.debug=ERROR, A1, F1
log4j.rootLogger=ERROR, A1
#------------------- CONSOLE LOG --------------------------
log4j.logger.com.mycompany.services=ERROR,A1
log4j.appender.A1.Threshold=ERROR
log4j.appender.A1=org.apache.log4j.ConsoleAppender
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%d{ISO8601} %5p [MYCOMPANY-SP] %c - %m%n
#------------------- ALL --------------------------
log4j.appender.F1=org.apache.log4j.RollingFileAppender
log4j.appender.F1.File=E\:/Documentum/logs/dfs-runtime.log
log4j.appender.F1.MaxFileSize=10MB
log4j.appender.F1.layout=org.apache.log4j.PatternLayout
log4j.appender.F1.layout.ConversionPattern=%d{ISO8601} %5p [MYCOMPANY-SP] %c- %m%n
#------------------- ASPECT_TRACE --------------------------
log4j.logger.com.emc.documentum.fs.tracing = DEBUG, ASPECT_TRACE
log4j.appender.ASPECT_TRACE=org.apache.log4j.RollingFileAppender
log4j.appender.ASPECT_TRACE.File=E\:/Documentum/logs/dfs-runtime-trace.log
log4j.appender.ASPECT_TRACE.MaxFileSize=10MB
log4j.appender.ASPECT_TRACE.layout=org.apache.log4j.PatternLayout
log4j.appender.ASPECT_TRACE.layout.ConversionPattern=%d{ISO8601} %5p [MYCOMPANY-SP] %m%n
#------------------- Customer TBO --------------------------
log4j.logger.no.customer=DEBUG,CustomerTBOAppender
log4j.appender.CustomerTBOAppender=org.apache.log4j.RollingFileAppender
log4j.appender.CustomerTBOAppender.File=E\:/Documentum/logs/CustomerTBO.log
log4j.appender.CustomerTBOAppender.MaxFileSize=10MB
log4j.appender.CustomerTBOAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.CustomerTBOAppender.layout.ConversionPattern=%d{ISO8601} %5p [MYCOMPANY-SP] [%t] %c - %m%n
#------------------- Customer Service --------------------------
log4j.logger.com.mycompany.services=TRACE,CustomerServiceAppender
log4j.appender.CustomerServiceAppender=org.apache.log4j.DailyRollingFileAppender
log4j.appender.CustomerServiceAppender.File=E\:/Documentum/logs/CustomerService.log
log4j.appender.CustomerServiceAppender.Append=true
log4j.appender.CustomerServiceAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.CustomerServiceAppender.layout.ConversionPattern=%d{ISO8601} %5p [MYCOMPANY-SP] [%t] %c - %m%n
****************************************************************************************

Related

Log4j StringMatchFilter and denyAll filter properties configuration

Can anyone please let me know filter properties for a package where
I want to separate the logs in two different logs files. Below is the configuration which I am trying use but its not working. I want deny logs
based string like 'UserMgmt-' and allow rest logs in log1 appender and allow only log2 appender allow 'UserMgmt-' and deny rest allow logs.
log4j.logger.com.abc=DEBUG, log1
log4j.logger.com.abc=DEBUG, log2
log4j.appender.log1=org.apache.log4j.RollingFileAppender
log4j.appender.log1.Append=true
log4j.appender.log1.File=C:/Oracle/Middleware/user_projects/domains/logs/G_loAFg/UM.log
log4j.appender.log1.layout=org.apache.log4j.PatternLayout
log4j.appender.log1.layout.ConversionPattern=%d %-6p [%c] %m%n
log4j.appender.log1.filter.1=org.apache.log4j.varia.StringMatchFilter
log4j.appender.log1.filter.1.StringToMatch=UserMgmt-
log4j.appender.log1.filter.1.AcceptOnMatch=false
log4j.appender.log2=org.apache.log4j.RollingFileAppender
log4j.appender.log2.Append=true
log4j.appender.log2.File=C:/Oracle/Middleware/user_projects/domains/logs/PM.log
log4j.appender.log2.layout=org.apache.log4j.PatternLayout
log4j.appender.log2.layout.ConversionPattern=%d %-6p [%c] %m%n
log4j.appender.log2.filter.1=org.apache.log4j.varia.StringMatchFilter
log4j.appender.log2.filter.1.StringToMatch=UserMgmt-
log4j.appender.log2.filter.1.AcceptOnMatch=true
Added deny all filter in 1st log1 after that it worked
log4j.appender.log1.filter=org.apache.log4j.varia.DenyAllFilter
log4j.logger.com.abc=DEBUG, log1
log4j.logger.com.abc=DEBUG, log2
log4j.appender.log1=org.apache.log4j.RollingFileAppender
log4j.appender.log1.Append=true
log4j.appender.log1.File=C:/Oracle/Middleware/user_projects/domains/logs/G_loAFg/UM.log
log4j.appender.log1.layout=org.apache.log4j.PatternLayout
log4j.appender.log1.layout.ConversionPattern=%d %-6p [%c] %m%n
log4j.appender.log1.filter.1=org.apache.log4j.varia.StringMatchFilter
log4j.appender.log1.filter.1.StringToMatch=UserMgmt-
log4j.appender.log1.filter.1.AcceptOnMatch=false
log4j.appender.log1.filter=org.apache.log4j.varia.DenyAllFilter
log4j.appender.log2=org.apache.log4j.RollingFileAppender
log4j.appender.log2.Append=true
log4j.appender.log2.File=C:/Oracle/Middleware/user_projects/domains/logs/PM.log
log4j.appender.log2.layout=org.apache.log4j.PatternLayout
log4j.appender.log2.layout.ConversionPattern=%d %-6p [%c] %m%n
log4j.appender.log2.filter.1=org.apache.log4j.varia.StringMatchFilter
log4j.appender.log2.filter.1.StringToMatch=UserMgmt-
log4j.appender.log2.filter.1.AcceptOnMatch=true
using org.apache.log4j_1.2.17.jar I set the filter to deny what I didn't want and then allowed everything else.
log4j.appender.NormalAppender.filter.1=org.apache.log4j.varia.StringMatchFilter
log4j.appender.NormalAppender.filter.1.StringToMatch=User.Dashboard
log4j.appender.NormalAppender.filter.1.AcceptOnMatch=false
log4j.appender.NormalAppender.filter.1=org.apache.log4j.varia.AllowAllFilter

Get spring messages from sysout to file using log4j

I'm trying to get Spring messages redirected to a log file.
I am able to get only some of the messages but not all of them.
This is my log4j file
log4j.rootLogger=DEBUG, stdout, file, fileDebug
log4j.logger = ERROR
log4j.category.org.springframework = DEBUG
log4j.category.org.springframework.jdbc.core = DEBUG
org.springframework.jdbc.core.JdbcTemplate = DEBUG
org.springframework.jdbc.core.StatementCreatorUtils = DEBUG
# Redirect 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=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
# Redirect log messages to a log file INFO level
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.Threshold=INFO
log4j.appender.file.MaxFileSize=5MB
log4j.appender.file.MaxBackupIndex=10
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
# Redirect log messages to a log file DEBUG level
log4j.appender.fileDebug=org.apache.log4j.RollingFileAppender
log4j.appender.fileDebug.Threshold=DEBUG
log4j.appender.fileDebug.MaxFileSize=5MB
log4j.appender.fileDebug.MaxBackupIndex=10
log4j.appender.fileDebug.layout=org.apache.log4j.PatternLayout
log4j.appender.fileDebug.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
# log locations
log4j.appender.file.File=logInfo.log
log4j.appender.fileDebug.File=debug.log
What I get in my debug.log is for example
2015-04-14 11:18:16 DEBUG ConfigurationImpl:120 - Setting custom MessageInterpolator of type org.springframework.validation.beanvalidation.LocaleContextMessageInterpolator 2015-04-14 11:18:16 DEBUG ConfigurationImpl:140 - Setting custom ConstraintValidatorFactory of type org.springframework.validation.beanvalidation.SpringConstraintValidatorFactory 2015-04-14 11:18:16 DEBUG ConfigurationImpl:154 - Setting custom ParameterNameProvider of type com.sun.proxy.$Proxy15 2015-04-14 11:18:16 DEBUG ValidationXmlParser:88 - Trying to load META-INF/validation.xml for XML based Validator configuration. 2015-04-14 11:18:16 DEBUG ValidationXmlParser:95 - No META-INF/validation.xml found. Using annotation based configuration only.
But I don't see there anything from jdbcTemplate but it is in my console.
11:19:19.673 [http-bio-8080-exec-6] DEBUG o.s.jdbc.core.JdbcTemplate - Executing prepared SQL query
So this should be debug level for org.springframework.jdbc.core.JdbcTemplate, but that doesn't seem to do anything.
I am probably missing something obvious but I just can't see it... Thanks for advice.
You need to Change following lines:
From
org.springframework.jdbc.core.JdbcTemplate = DEBUG
org.springframework.jdbc.core.StatementCreatorUtils = DEBUG
To
log4j.logger.org.springframework.jdbc.core.JdbcTemplate = DEBUG, fileDebug
log4j.additivity.org.springframework.jdbc.core.JdbcTemplate=false
log4j.logger.org.springframework.jdbc.core.StatementCreatorUtils = DEBUG, fileDebug
log4j.additivity.org.springframework.jdbc.core.StatementCreatorUtils=false

log4j.properties

I have a debug,info,warn,error logs in my code. But i want to print only info,error logs in my console. I want to store all the logs in a file. Can anyone suggest a way.
I trie with
log4j.rootLogger=debug,R1,R2
log4j.appender.R1=org.apache.log4j.ConsoleAppender
log4j.appender.R1.layout=org.apache.log4j.PatternLayout
log4j.appender.R1.layout.ConversionPattern=%d{dd/MM/yy kk:mm:ss.SSS} %-5p [%t] %x (%F:%L) - %m%n
#OAPIFacade front logs
log4j.appender.R2=org.apache.log4j.DailyRollingFileAppender
log4j.appender.R2.File=app/log4j/prop/log4j.log
log4j.appender.R1.DatePattern='.'dd-MM-yy
log4j.appender.R2.layout=org.apache.log4j.PatternLayout
log4j.appender.R2.layout.ConversionPattern=%d{dd/MM/yy kk:mm:ss.SSS} %-5p [%t] %x (%F:%L) - %m%n
In this case, all the logs are printing in the console, but i want only info and error logs in the console.
As far as I know, you can't see INFO, hide WARN, and see ERROR at the same time; this violates the design of the log levels. The levels are defined in this order:
TRACE
DEBUG
INFO
WARN
ERROR
FATAL
However, if you wanted to see only WARN and ERROR in the console, you can do this using the Threshold setting of the appender. Specifically, you just need to add:
log4j.appender.R1.Threshold=WARN

Log4J attach only one class to an appender

I need to poll the JVM memory stats of my running application on a regular basis. I'm running a service that does this and writes the stats to the root Logger (I don't have much control over Root Logger usage or not).
What I want to do is route just these logging messages to a single appender. This appender should only process logging messages from this one class, and not from any other class. The other appenders shouldn't receive the messages from this one class.
So far I have the log messages only going to this 'memoryStats' appender. However, all the other logging message are also going to that appender, and I need to get rid of them, but I'm not sure how short of listing out every single class which would be a nightmare.
log4j.rootCategory=info, A1, R, MEM
# A1 is set to be a ConsoleAppender.
log4j.appender.A1=org.apache.log4j.ConsoleAppender
# A1 uses PatternLayout.
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=[%p] %d{dd MMM yyyy HH;mm:ss,SSS} %t %c{2} (line:%L) - %m%n
log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=logs/ui.log
log4j.appender.R.MaxFileSize=100MB
# Keep backup files
log4j.appender.R.MaxBackupIndex=9
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=[%p] %d{dd MMM yyyy HH;mm:ss,SSS} %t %c{2} (line:%L) - %m%n
log4j.category.foo.bar.services.App.MemoryStats=debug, MEM
log4j.additivity.foo.bar.services.App.MemoryStats=false
log4j.appender.MEM=org.apache.log4j.RollingFileAppender
log4j.appender.MEM.File=logs/memStats.log
log4j.appender.MEM.MaxFileSize=100MB
# Keep backup files
log4j.appender.MEM.MaxBackupIndex=9
log4j.appender.MEM.layout=org.apache.log4j.PatternLayout
log4j.appender.MEM.layout.ConversionPattern=[%p] %d{dd MMM yyyy HH;mm:ss,SSS} %t %c{2} (line:%L) - %m%n
You should remove MEM from log4j.rootCategory.
Change:
log4j.rootCategory=info, A1, R, MEM
to:
log4j.rootCategory=info, A1, R

Log Level per appender for a single Logger

Is it possible to configure different log levels for a single Logger based on the appender?
I realize this is similar to this question, and this is as far as I had already got myself, but the problem with this is that the threshold applies to all loggers that log to that appender, whereas I only want the threshold to apply to a single logger.
i.e. So far I have something like this:
log4j.rootLogger=WARN, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Threshold=WARN
log4j.appender.stdout.layout=org.apache.log4j.SimpleLayout
log4j.logger.mylogger=DEBUG,logfile
log4j.appender.logfile=org.apache.log4j.DailyRollingFileAppender
log4j.appender.logfile.DatePattern=${roll.pattern.daily}
log4j.appender.logfile.layout=org.apache.log4j.PatternLayout
log4j.appender.logfile.layout.ConversionPattern=%d{${datestamp}} [%t] %-5p %C{2} - %m%n
log4j.appender.logfile.File=mylogfile.log
I want mylogger DEBUG messages to be send to the logfile appender, but I also want mylogger INFO messages to be sent to the stdout appender (but for all other loggers only WARN ings). Using the Threshold to limit stdout to WARN restricts the output of mylogger.
Aha, I fixed it by changing
log4j.appender.stdout.Threshold=WARN
to
log4j.appender.stdout.Threshold=INFO
Should have been more careful first time round.

Categories