Java Logging - Debug Level log not appeared in the eclipse console - java

For debugging my application, trying to display debug level logs in the eclipse console with the below configuration. But only INFO, ERROR and FATAL are displayed, but not the DEBUG level logs.
# Direct log messages to a log file
log4j.appender.file=org.apache.log4j.DailyRollingFileAppender
log4j.appender.file.File=D:/log/oms-web.log
#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} [%t] %p %c - %m%n
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
# Pattern to output the date/time, calling class and message.
log4j.appender.stdout.layout.ConversionPattern=%d{ISO8601} %p %C.%M(): %m%n
# Root logger option
log4j.rootCategory=INFO ,file,stdout,DEBUG
log4j.category.org.springframework.beans.factory=OFF
# Log everything. Good for troubleshooting
log4j.logger.org.hibernate=OFF
# Log all JDBC parameters
log4j.logger.org.hibernate.type=OFF
log4j.logger.org.springframework=OFF
Please help me to resolve.

Change the rootCategory to:
log4j.rootCategory=DEBUG ,file,stdout

Related

Log4j - logging of internal Log4j events

I am having some issue with log4j settings.
In order to solve them i have enabled internal log4j logging in log4j properties as that:
log4j.debug=true
It is working as i am getting logs like this in console which is fine:
log4j: Parsing for [root] with value=[DEBUG, console, rollingFile, test].
log4j: enter code here`: Level token is [DEBUG].
log4j: Category root set to DEBUG
log4j: Parsing appender named "console".
log4j: Parsing layout options for "console".
Now i need to save those logs also to file.
I have added FileAppender which works for other logs, but does not save the internal log4j logs.
Whole log4j configuration:
#log4j.category.org.hibernate=INFO, hibernate
log4j.category.org.hibernate.SQL=ERROR, hibernate
#log4j.category.org.hibernate.type=ALL, hibernate
log4j.additivity.org.hibernate.SQL=false
#Root logger setting
log4j.rootLogger=DEBUG, console, rollingFile, test
#Appenders configurations.
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.conversionPattern=%d{yyyyMMdd HH:mm:ss.SSS} %5p [%t] (%F:%L) - %m%n
log4j.appender.rollingFile=eu.unicorn.pcr.broker.logging.CustodianDailyRollingFileAppender
log4j.appender.rollingFile.File=${catalina.home}/logs/pcr-app.log
log4j.appender.rollingFile.DatePattern='.'yyyy-MM-dd-HH-mm
log4j.appender.rollingFile.MaxNumberOfDays=10
log4j.appender.rollingFile.layout=org.apache.log4j.PatternLayout
log4j.appender.rollingFile.layout.conversionPattern=%d{yyyyMMdd HH:mm:ss.SSS} %5p [%t] (%F:%L) - %m%n
#apender for stress request logging
log4j.appender.stressTest=org.apache.log4j.DailyRollingFileAppender
log4j.appender.stressTest.File=${catalina.home}/logs/requests.log
log4j.appender.stressTest.MaxBackupIndex=10
log4j.appender.stressTest.layout = org.apache.log4j.PatternLayout
log4j.appender.stressTest.layout.conversionPattern=%d{HH:mm:ss.SSS} [%t] - %m%n
log4j.category.stressTestLogger=TRACE, stressTest
log4j.additivty.stressTestLogger=false
log4j.appender.hibernate=org.apache.log4j.RollingFileAppender
log4j.appender.hibernate.File=${catalina.home}/logs/hibernate.log
log4j.appender.hibernate.MaxFileSize=20MB
log4j.appender.hibernate.MaxBackupIndex=10
log4j.appender.hibernate.layout = org.apache.log4j.PatternLayout
log4j.appender.hibernate.layout.conversionPattern=%d{yyyyMMdd HH:mm:ss.SSS} [%t] (%F:%L) - %m%n
# Define the test file appender
log4j.appender.test=org.apache.log4j.FileAppender
log4j.appender.test.File=${catalina.home}/logs/test.log
log4j.appender.test.ImmediateFlush=true
log4j.appender.test.Threshold=debug
log4j.appender.test.Append=false
log4j.appender.test.layout=org.apache.log4j.PatternLayout
log4j.appender.test.layout.conversionPattern=%m%n
log4j.debug=true
Any tips how to set up that the internal log4j logs will be also saved also in file? Would be glad for any hints.
If you want save your log in a file you must use the propierties for that.
# Define the root logger with appender file
log4j.rootLogger = DEBUG, FILE
# Define the file appender
log4j.appender.FILE=org.apache.log4j.FileAppender
# Set the name of the file
log4j.appender.FILE.File=${log}/log.out
# Set the immediate flush to true (default)
log4j.appender.FILE.ImmediateFlush=true
# Set the threshold to debug mode
log4j.appender.FILE.Threshold=debug
# Set the append to false, overwrite
log4j.appender.FILE.Append=false
# Define the layout for file appender
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.conversionPattern=%m%n

How to configure Log4j Multiple Appenders for classes in same package

Please help to correct the appenders with Threshold of info level to reroute to correct appenders for the classes within a package. Below is the properties file
`
# Root logger option
log4j.rootLogger=INFO, ffile, stdout ,sfile
# 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
# Direct log messages to a log file
log4j.appender.ffile=org.apache.log4j.DailyRollingFileAppender
log4j.appender.ffile.Threshold=ERROR
log4j.appender.ffile.File=failure.log
log4j.appender.ffile.layout=org.apache.log4j.PatternLayout
log4j.appender.ffile.layout.ConversionPattern=%d{ISO8601} %c{1}: - %m%n
# Direct log messages to a log file
log4j.appender.sfile=org.apache.log4j.DailyRollingFileAppender
log4j.appender.sfile.Threshold=INFO
log4j.appender.sfile.File=success.log
log4j.appender.sfile.layout=org.apache.log4j.PatternLayout
log4j.appender.sfile.layout.ConversionPattern=%d{ISO8601} %c{1}: - %m%n
#Additivity to stop the mix/repeate of logs in multiple appenders
log4j.additivity.com.rp.handler.AsynchSeeder=false
log4j.additivity.com.rp.handler=false
#Configured logger to route to the appender files. Failing
log4j.logger.com.rp.handler.AsynchSeeder=ERROR, stdout, ffile
log4j.logger.com.rp.handler=INFO, stdout, sfile
#Suppress all low level for open source 3rdparty
log4j.logger.org.apache=WARN
`

Override all log4j.properties for webapps in tomcat

i'm running Apache Tomcat 7.0.59 on a OpenSuse Leap 42.2 with Java 1.8.0_65 and have several webapplications deployed. Some of them are my own, and some of them are third-party.
Some webapps come with a log4j.properties file in their classpath. Now i want to have one global log4j.properties file which overrides all others so i can aggregate all logging information into one big my-tomcat.log file.
What i did was add the VM flag -Dlog4j.configuration=file:///path/to/my/custom-log4j.properties to tomcat's setenv.sh file which basically works great. Now i have my own my-tomcat.log file which contains all logging information.
But here is the problem: the "old" log files are still written. It seems that log4j is still reading all the app-specific log4j.properties files.
for example my custom-log4j.properties file looks like this:
# Set root logger level to error
log4j.rootLogger=INFO, File
###### Console appender definition #######
# All outputs currently set to be a ConsoleAppender.
log4j.appender.Console=org.apache.log4j.ConsoleAppender
log4j.appender.Console.layout=org.apache.log4j.PatternLayout
# use log4j NDC to replace %x with tenant domain / username
log4j.appender.Console.layout.ConversionPattern=%d{ISO8601} %x %-5p [%c{3}] [%t] %m%n
#log4j.appender.console.layout.ConversionPattern=%d{ABSOLUTE} %-5p [%c] %m%n
###### File appender definition #######
log4j.appender.File.Threshold=INFO
log4j.appender.File=org.apache.log4j.DailyRollingFileAppender
log4j.appender.File.File=eWork.log
log4j.appender.File.Append=true
log4j.appender.File.DatePattern='.'yyyy-MM-dd
log4j.appender.File.layout=org.apache.log4j.PatternLayout
log4j.appender.File.layout.ConversionPattern=%d{yyyy-MM-dd} %d{ABSOLUTE} %-5p [%c] [%t] %m%n
One of my webapps logging files looks like this:
# Set root logger level to error
log4j.rootLogger=error, Console, File
###### Console appender definition #######
# All outputs currently set to be a ConsoleAppender.
log4j.appender.Console=org.apache.log4j.ConsoleAppender
log4j.appender.Console.layout=org.apache.log4j.PatternLayout
# use log4j NDC to replace %x with tenant domain / username
log4j.appender.Console.layout.ConversionPattern=%d{ISO8601} %x %-5p [%c{3}] [%t] %m%n
#log4j.appender.Console.layout.ConversionPattern=%d{ABSOLUTE} %-5p [%c] %m%n
###### File appender definition #######
log4j.appender.File=org.apache.log4j.DailyRollingFileAppender
log4j.appender.File.File=alfresco.log
log4j.appender.File.Append=true
log4j.appender.File.DatePattern='.'yyyy-MM-dd
log4j.appender.File.layout=org.apache.log4j.PatternLayout
log4j.appender.File.layout.ConversionPattern=%d{yyyy-MM-dd} %d{ABSOLUTE} %-5p [%c] [%t] %m%n
both my-tomcat.log as well as alfresco.log are created. Also the catalina.out file is written although i have not added the console appender in my custom-log4j.properties. However the contents of catalina.out is quite small.
Do you have any ideas how to completely override any log4j.properties files from all webapps?
Thank you very much for any help and have a nice day!

Disable log4j console logging in linux

I have my log4j.properties file as -
# Root logger option
log4j.rootLogger=WARN, file
# Direct log messages to a log file
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=/tmp/logging.log
log4j.appender.file.MaxFileSize=10MB
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
Problem is, log messages are also getting printed on console. How can I disable that? I have read some of the posts here on stackoverflow but other users were facing issues because they defined the consoleAppender into their file but I haven't defined it in my log4j.properties file and still it displays it on console.
Please help.
Try doing additivity false. like below in your property file.
log4j.additivity=false
log4j.rootLogger=ERROR, console
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%d %5p %c (%F:%L) - %m%n
#hide the Log4jMemoryAppender from console
log4j.logger.nz.ac.massey.cs.sdc.log4jassignment.s06005586.MemoryAppender= ERROR, MEMORY_APPENDER
log4j.appender.MEMORY_APPENDER=nz.ac.massey.cs.sdc.log4jassignment.s06005586.MemoryAppender.Log4jMemoryAppender
log4j.additivity.rootLogger = false
log4j.additivity.console = false
log4j.additivity.MEMORY_APPENDER=false

Log messages except from a particular package to a file

I am using log4j for logging , my requirement is to log all the logs from package
pkg1 (except pkg1.pkg2) to pkg1.log
and pkg1.pkg2 (a sub package of the above package) to pkg2.log
is this possible ? I know i can achieve it through custom appenders but is there a way I can do it through configurations.
I am using the below properties file. Here the problem is PKG1.log contains logs from PKG2 also.
# Root logger option
log4j.rootLogger=WARN, CONSOLE
# Direct log messages to a log file
log4j.logger.com.pkg1=DEBUG, PKG1 log4j.appender.PKG1=org.apache.log4j.RollingFileAppender
log4j.appender.PKG1.File=logs/PKG1.log
log4j.appender.PKG1.MaxFileSize=1MB
log4j.appender.PKG1.MaxBackupIndex=1
log4j.appender.PKG1.layout=org.apache.log4j.PatternLayout
log4j.appender.PKG1.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
log4j.logger.com.pkg1.pkg2=DEBUG, PKG2
log4j.appender.PKG2=org.apache.log4j.RollingFileAppender
log4j.appender.PKG2.File=logs/PKG2.log
log4j.appender.PKG2.MaxFileSize=1MB
log4j.appender.PKG2.MaxBackupIndex=1
log4j.appender.PKG2.layout=org.apache.log4j.PatternLayout
log4j.appender.PKG2.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
# Direct log messages to CONSOLE
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.Target=System.out
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
You can stop PKG2's logs from reaching it's ancestor's appenders by disabling the additivity flag in the configuration:
log4j.appender.PKG2.additivity=false

Categories

Resources