Issue with logging on Openshift jboss using log4j - java

i am having a couple of issues regarding logging using OpenShift with log4j on jboss.
I am using a log4j properties file as follows but seem to be getting no log messages in the file. I have the log4j properties file in the following locations in my app;
/src/log4j.properties
Deployed Resources/WEB-INF/log4j.properties
WebContent/WEB-INF/log4j.properties
Is there anything specific i need to do differently for JBoss ?
Thanks
log=/var/lib/openshift/52c0260d4382ec7329000120/app-root/runtime/dependencies/jbossas/deployments/Logs/HotOrNotLog.log
log4j.rootLogger=default.file.debug
# System.out.println appender
log4j.appender.default.out=org.apache.log4j.ConsoleAppender
log4j.appender.default.out.threshold=INFO
log4j.appender.default.out.layout=org.apache.log4j.PatternLayout
# Print the date in ISO 8601 format
log4j.appender.default.out.layout.ConversionPattern=%d [%t] %-5p %c - %m%n
# File appender for DEBUG
log4j.appender.default.file.debug=org.apache.log4j.FileAppender
log4j.appender.default.file.debug.append=true
log4j.appender.default.file.debug.file=${log}
log4j.appender.default.file.debug.threshold=DEBUG
log4j.appender.default.file.debug.layout=org.apache.log4j.PatternLayout
log4j.appender.default.file.debug.layout.ConversionPattern=%d [%t] %-5p %c - %m%n
# File appender for INFO log4j.appender.default.file.info=org.apache.log4j.FileAppender
log4j.appender.default.file.info.append=true
log4j.appender.default.file.info.file=${log}
log4j.appender.default.file.info.threshold=INFO
log4j.appender.default.file.info.layout=org.apache.log4j.PatternLayout
log4j.appender.default.file.info.layout.ConversionPattern=%d [%t] %-5p %c - %m%n
# File appender for WARN log4j.appender.default.file.warn=org.apache.log4j.FileAppender
log4j.appender.default.file.warn.append=true
log4j.appender.default.file.warn.file=${log}
log4j.appender.default.file.warn.threshold=WARN
log4j.appender.default.file.warn.layout=org.apache.log4j.PatternLayout
log4j.appender.default.file.warn.layout.ConversionPattern=%d [%t] %-5p %c - %m%n
# File appender for ERROR
log4j.appender.default.file.error=org.apache.log4j.FileAppender
log4j.appender.default.file.error.append=true
log4j.appender.default.file.error.file=${log}
log4j.appender.default.file.error.threshold=ERROR
log4j.appender.default.file.error.layout=org.apache.log4j.PatternLayout
log4j.appender.default.file.error.layout.ConversionPattern=%d [%t] %-5p %c - %m%n
# File appender for FATAL
log4j.appender.default.file.fatal=org.apache.log4j.FileAppender
log4j.appender.default.file.fatal.append=true
log4j.appender.default.file.fatal.file=${log}
log4j.appender.default.file.fatal.threshold=FATAL
log4j.appender.default.file.fatal.layout=org.apache.log4j.PatternLayout
log4j.appender.default.file.fatal.layout.ConversionPattern=%d [%t] %-5p %c - %m%n
EDIT
having looked in the jboss server logs (server.log in /var/lib/openshift/52c0260d4382ec7329000120/jbossas/logs) i can see the following
2014/03/31 17:29:58,393 ERROR [stderr] (MSC service thread 1-1) log4j:WARN No appenders could be found for logger (com.hotornot.database.DBFactory).
2014/03/31 17:29:58,425 ERROR [stderr] (MSC service thread 1-1) log4j:WARN Please initialize the log4j system properly.
2014/03/31 17:29:58,426 ERROR [stderr] (MSC service thread 1-1) log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
however stack overflow suggests the properties file isn't in the class path - but it is in source as well as two other places lol

Two things that jump out.
None of the following are on the classpath:
/src/log4j.properties
Deployed Resources/WEB-INF/log4j.properties
WebContent/WEB-INF/log4j.properties
Try WEB-INF/classes within your web application (depending on your build having it in /src should copy it over there).
Your first line is log4j.rootLogger=default.file.debug. Shouldn't this be log4j.rootLogger=DEBUG, default.file.debug? It should be a level, then a comma, then an appender.
Do you need all those appenders, anyway? Wouldn't this be the same thing:
log4j.rootLogger=DEBUG, FILE
log4j.appender.FILE=org.apache.log4j.FileAppender
log4j.appender.FILE.append=true
log4j.appender.FILE.file=${log}
log4j.appender.FILE.threshold=DEBUG
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.ConversionPattern=%d [%t] %-5p %c - %m%n

I needed to put log4 props in the src/resources folder - its a maven issue as it appears it has a standard dir it checks for log4j props

I don't know how it is in later versions, in JBoss 4 there is a jboss-log4j.xml and i'd say that is used by default. You could check that file..

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

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!

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

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

Tomcat System.out redirection

We have got a legacy Java application, running on Tomcat. It logs its events in somewhat unconsistent way, sometimes even relying on System.out/err. These stdout/stderr records end up in catalina.log where they are mixed with "proper logged" events. We would like to separate the stdout/stderr log streams into separate files (and eventually get rid of them) but we don't know how to do it. The server runs default JULI configuration but we are open to any other option (such as SLF4J + Logback).
This explains it in full: Log4J Just put log4j.jar and log4j.properties into WEB-INF/lib and WEB-INF/classes of your web application. Create a file called log4j.properties with the following content and save it into $CATALINA_BASE/lib
Example of log4j.properties that would cease output to stdout:
log4j.rootLogger=INFO, yourapp
#Define all the appenders
log4j.appender.CATALINA=org.apache.log4j.DailyRollingFileAppender
log4j.appender.CATALINA.File=${catalina.base}/logs/catalina.
log4j.appender.CATALINA.Append=true
log4j.appender.CATALINA.Encoding=UTF-8
#Roll-over the log once per day
log4j.appender.CATALINA.DatePattern='.'yyyy-MM-dd'.log'
log4j.appender.CATALINA.layout = org.apache.log4j.PatternLayout
log4j.appender.CATALINA.layout.ConversionPattern = %d [%t] %-5p %c- %m%n
log4j.appender.LOCALHOST=org.apache.log4j.DailyRollingFileAppender
log4j.appender.LOCALHOST.File=${catalina.base}/logs/localhost.
log4j.appender.LOCALHOST.Append=true
log4j.appender.LOCALHOST.Encoding=UTF-8
log4j.appender.LOCALHOST.DatePattern='.'yyyy-MM-dd'.log'
log4j.appender.LOCALHOST.layout = org.apache.log4j.PatternLayout
log4j.appender.LOCALHOST.layout.ConversionPattern = %d [%t] %-5p %c- %m%n
log4j.appender.MANAGER=org.apache.log4j.DailyRollingFileAppender
log4j.appender.MANAGER.File=${catalina.base}/logs/manager.
log4j.appender.MANAGER.Append=true
log4j.appender.MANAGER.Encoding=UTF-8
log4j.appender.MANAGER.DatePattern='.'yyyy-MM-dd'.log'
log4j.appender.MANAGER.layout = org.apache.log4j.PatternLayout
log4j.appender.MANAGER.layout.ConversionPattern = %d [%t] %-5p %c- %m%n
log4j.appender.HOST-MANAGER=org.apache.log4j.DailyRollingFileAppender
log4j.appender.HOST-MANAGER.File=${catalina.base}/logs/host-manager.
log4j.appender.HOST-MANAGER.Append=true
log4j.appender.HOST-MANAGER.Encoding=UTF-8
log4j.appender.HOST-MANAGER.DatePattern='.'yyyy-MM-dd'.log'
log4j.appender.HOST-MANAGER.layout = org.apache.log4j.PatternLayout
log4j.appender.HOST-MANAGER.layout.ConversionPattern = %d [%t] %-5p %c- %m%n
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
#Configure which loggers log to which appenders
log4j.logger.org.apache.catalina.core.ContainerBase.[Catalina].[localhost]=INFO, LOCALHOST
log4j.logger.org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager]=\INFO, MANAGER
log4j.logger.org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/host-manager]=\INFO, HOST-MANAGER
#You can define your Applog here:
log4j.appender.yourapp=org.apache.log4j.RollingFileAppender
log4j.appender.yourapp.File=${catalina.base}/logs/yourapp.log
log4j.appender.yourapp.MaxFileSize=100MB
log4j.appender.yourapp.MaxBackupIndex=10
log4j.appender.yourapp.layout=org.apache.log4j.PatternLayout
log4j.appender.yourapp.layout.ConversionPattern=%d %p [%c] (%t) - <%m>%n
Hope this helps!

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