I want to configure my Liferay portlet project with own log4j configurations.I have followed following article and it is working fine for me.
https://web.liferay.com/web/brett.swaim/blog/-/blogs/using-log4j-to-ensure-each-portlet-has-it-s-own-log-file
Now I need to use log4j.properties file instated of log4j.xml file.So I have removed log4j.xml and put a sample log4j.properties file.After putting log4j.properties file, portlet project does not identify the log4j configurations.
My Liferay version is Liferay 6.2 CE GA5.
Sample log4j.properties file is,
log4j.rootLogger=ERROR,console
#Console Appender
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=[%5p] [%t %d{hh:mm:ss}] (%F:%M:%L) %m%n
#Custom assignments
log4j.logger.controller=DEBUG,console
log4j.logger.service=DEBUG,console
log4j.logger.dao=DEBUG,console
#Disable additivity
log4j.additivity.controller=false
log4j.additivity.service=false
log4j.additivity.dao=false
Can anybody help me resolve this issue?
I have finally found the fix.Need to define the log4j properties file path in the web.xml.I have placed my log4j.properties file in the WEB-INF folder.
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/log4j.properties</param-value>
</context-param>
Related
I'm trying to get slf4j 1.7.7 to use log4j 2.0.2 as its implementation. I think I have all the necessary JARs in my WAR and the log4j.xml just gets dropped into the classes directory, but when my webapp starts up, it can't locate the log4j.xml. When I crack open the WAR, I can see it in the WEB-INF/classes, so it should be on the classpath. What am I missing?
meta-inf/manifest.mf
index.html
...
WEB-INF/web.xml
WEB-INF/classes/log4j.xml
...
WEB-INF/lib/log4j-api-2.0.2.jar
...
WEB-INF/lib/slf4j-api-1.7.7.jar
...
WEB-INF/lib/log4j-core-2.0.2.jar
WEB-INF/lib/log4j-slf4j-impl-2.0.2.jar
...
Jetty has this in its stderrout.log file, recording its disappointment...
ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console.
Well that is subtle. log4j-core-2.0.2 isn't looking for log4j.xml, its looking for log4j2.xml. The FAQ page http://logging.apache.org/log4j/2.x/faq.html has, in bold, "By default, Log4j looks for a configuration file named log4j2.xml (not log4j.xml) in the classpath." Renaming my file to log4j2.xml gets it found. Now I've got to make it correct.
2014-10-24 10:34:53,542 ERROR Unknown object "property" of type org.apache.logging.log4j.core.config.Property is ignored.
2014-10-24 10:34:53,545 ERROR Unknown object "logger" of type org.apache.logging.log4j.core.config.LoggerConfig is ignored.
2014-10-24 10:34:53,546 ERROR Unknown object "root" of type org.apache.logging.log4j.core.config.LoggerConfig is ignored.
I have multiple ears,For certain Ears I want log4j details to be picked from Weblogic level and for certain application I have application level log4j.xml bundled with ear.
Copied wllog4j.jar and Log4j-x.x.x.jar to Server classpath
Added the following JAVA_OPTION in
startWebLogic.sh -Dlog4j.Configuration=Mylog4j.xml
and add the "Mylog4j.xml" in the Server Classpath
as :
SAVE_JAVA_OPTIONS="${JAVA_OPTIONS}" -Dlog4j.Configuration=Mylog4j.xml
SAVE_CLASSPATH="${CLASSPATH}:/apps/myfiles/MyLog4j.xml"
For application which have application level log4j.xml ,I have mentioned prefer-application-packages in weblogic-application.xml
<prefer-application-packages>
<package-name>org.apache.log4j.*</package-name>
</prefer-application-packages>
But the logs are not getting generated for those application which has there log4j.xml
Also,Just for info : Applications are using slf4j/commons-logging and log4j
Please suggest !!!
The issue was related to classloading : Below line in weblogic-applicaton.xml does the trick.
<prefer-application-packages>
<package-name>org.apache.log4j.*</package-name>
<package-name>org.apache.*</package-name>
<package-name>org.slf4j.*</package-name>
</prefer-application-packages>
Follow below steps
1) copy log4j.jar and wllog4j.jar in server lib folder
2) copy your log4j.xml in server domain folder
3) change setDomaninEnv.xml to point to your log4j.xml file ex: LOG4J_CONFIG_FILE="${DOMAIN_HOME}/log4j.xml"
This has been asked multiple times but I have not been able to figure out what is wrong from the past questions that have been answered.
my log4j logging was working fine on Dec 31. Today, Jan 2, my first day back to work nothing is being logged. The data that should have been logged is showing up on the console but not in the log file. My log4j.properties is below. Nothing in it was changed between the last time logging was working and today.
My application is servlet based and I see no errors in either catalina or localhost logs.
I have no idea what could have happened. Does anyone have any ideas?
I just realized that I did an SVN update on the project before starting today. I might have gotten newer version of some jar file. Can a jar 'collision' cause log4j to stop logging?
log4j.rootLogger=DEBUG, A1
log4j.appender.A1=org.apache.log4j.ConsoleAppender
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
log4j.logger.AppLogFile=DEBUG,AppLogFile
log4j.appender.AppLogFile.File=../logs/dbconnect.log
log4j.appender.AppLogFile=org.apache.log4j.RollingFileAppender
log4j.appender.AppLogFile.layout=org.apache.log4j.PatternLayout
log4j.appender.AppLogFile.layout.ConversionPattern=DBCONNECT %-22d{dd/MMM/yyyy HH:mm:ss} - %m%n
# manage logging for packages
log4j.category.org.springframework=ERROR
log4j.category.org.hibernate=ERROR
log4j.category.com.mchange.v2=ERROR
I'm answering my own question here. After four hours of searching I found the answer.
The problem was a third party jar that came down from SubVersion when I did an update. This jar was added yesterday by a developer working on a different part of the application.
Log4j looks for 'log4j.xml' before it looks for 'log4j.properties'. The third party jar contained a log4j.xml so that one was loaded and my log4j.properties was ignored.
This was pretty easy to find once I added the log4j debug command.
So, here is how to do it if you find yourself in this situation.
Stop Tomcat
In %CATALINA_HOME%/bin create a file called setenv.bat. Add these lines to the file:
REM Use this file to set either or both JAVA_OPTS, CATALINA_OPTS
REM Don't change startup.bat
set JAVA_OPTS=-Dlog4j.debug
Save and Restart Tomcat
Log4j will now log useful information, including what config file it is using, to the console.
When Tomcat starts the app Log4j logs the search for a config file. Here are two excerpts; the first showing what was happening to me the second showing what is normal behavior for my situation.
Case 1: Log4j is looking in the right place, /WEB-APPS/emscribe/WEB-INF/classes, but for log4j.xml not log4j.properties
log4j: Trying to find [log4j.xml] using context classloader WebappClassLoader
context: /emscribe
delegate: false
repositories:
/WEB-INF/classes/
----------> Parent Classloader: org.apache.catalina.loader.StandardClassLoader#1f7fd168
log4j: Using URL [jar:file:/C:/Program%20Files/Apache%20Software%20Foundation/apache-tomcat-7.0.26/webapps/emscribe/WEB-INF/lib/dynamicreports-examples-3.0.0.jar!/log4j.xml] for automatic log4j configuration.
So, here Log4j found log4j.xml in the recently added third party jar and looked no further.
Case 2: With the third party jar removed log4j found the correct config file:
log4j: Trying to find [log4j.xml] using context classloader WebappClassLoader
context: /emscribe
delegate: false
repositories:
/WEB-INF/classes/
----------> Parent Classloader:org.apache.catalina.loader.StandardClassLoader#8b10bd5
log4j: Trying to find [log4j.xml] using WebappClassLoader
context: /emscribe
delegate: false
repositories:
/WEB-INF/classes/
----------> Parent Classloader:org.apache.catalina.loader.StandardClassLoader#8b10bd5class loader.
log4j: Trying to find [log4j.xml] using ClassLoader.getSystemResource().
log4j: Trying to find [log4j.properties] using context classloader WebappClassLoader
context: /emscribe
delegate: false
repositories:
/WEB-INF/classes/
----------> Parent Classloader:
org.apache.catalina.loader.StandardClassLoader#8b10bd5
.
log4j: Using URL [file:/C:/Program%20Files/Apache%20Software%20Foundation/apache-tomcat-7.0.26/webapps/emscribe/WEB-INF/classes/log4j.properties] for automaticlog4j configuration.
log4j: Reading configuration from URL file:/C:/Program%20Files/Apache%20Software%20Foundation/apache-tomcat-7.0.26/webapps/emscribe/WEB-INF/classes/log4j.properties
I eventually replaced log4j.properties with an equivalent log4j.xml, replaced the third-party jar and my log4j.xml was found before the one in the jar.
I had a different issue. I imported a project where log4j.properties was there with everything configured. There was a log file name too in the properties file, but it did not write a log file during running the project in eclipse.
Putting -Dlog4j.debug in the VM arguments in run configuration helped me to analyze, it printed all the configuration log4j doing during initialization of itself, found what I had to change in my properties file.
i am new to log4j and i have the following log4j.properties file in my java application
i am working on this in websphere 6.1
log4j.properties file
log4j.rootLogger=info, console
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.package_name=debug
However this is working if i am using only one project as part of my application.If there are multiple projects and i want to use logging facility,logger.isDebugEnabled() always return false.. can anybody suggest a solution for this?
Thanks in advance
Websphere use a classloader for default for each EAR. If you have several Web modules or EJB modules and several files for log4j, only one is loaded by the classloader.
See A Powerful, Easy-to-Use Logging System for configure log4j with several projects in a EAR.
# Set root logger level to INFO and appender to STDOUT.
log4j.rootLogger=INFO, STDOUT
#------------------------------------STDOUT-----------------------------------#
# STDOUT is set to be a ConsoleAppender.
log4j.appender.STDOUT=org.apache.log4j.ConsoleAppender
# STDOUT uses PatternLayout.
log4j.appender.STDOUT.layout=org.apache.log4j.PatternLayout
log4j.appender.STDOUT.layout.ConversionPattern=%d %-5p (%c.java:%L).%M - %m%n
log4j.appender.STDOUT.Encoding=UTF-8
#-----------------------------------------------------------------------------#
# Specify the logging level for loggers from other libraries
log4j.logger.org.apache.commons.beanutils.BeanUtils=DEBUG
log4j.logger.org.apache.struts.action=DEBUG
log4j.logger.org.apache.struts.tiles=DEBUG
log4j.logger.org.apache.struts.util.ModuleUtils=DEBUG
log4j.logger.org.apache.struts.util.RequestUtils=DEBUG
log4j.logger.org.apache.struts.util.PropertyMessageResources=ERROR
log4j.logger.com.ibm._jsp=DEBUG
May you are missing the log4j.logger. prefix for each particular package.
See more of log4j in http://logging.apache.org/log4j/1.2/manual.html
I'm trying to configure slf4j with log4j in my java application and I get no success.
My log4j file looks like this:
log4j.rootLogger=DEBUG,stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d [%t] %-5p %X{file} %c{1} - %m%n
log4j.logger.lt.hltech.tools.webcrawler=DEBUG,webcrawler
log4j.additivity.lt.hltech.ws.webcrawler=false
log4j.logger.webcrawler=DEBUG,webcrawler
log4j.additivity.webcrawler=false
log4j.appender.webcrawler=org.apache.log4j.DailyRollingFileAppender
log4j.appender.webcrawler.File=D:\\Projects\\IntellijIdeaProjects\\hltech_tools\\WebCrawler\\crawling.log
log4j.appender.webcrawler.DatePattern='.'yyyy-MM-dd
log4j.appender.webcrawler.layout=org.apache.log4j.PatternLayout
log4j.appender.webcrawler.layout.ConversionPattern=%d [%t] %-5p %X{file} %c{1} %m%n
log4j.appender.webcrawler.ImmediateFlush=true
MANIFEST.MF in jar file looks like this:
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.2
Created-By: 1.5.0_20-b02 (Sun Microsystems Inc.)
Main-Class: lt.hltech.tools.webcrawler.main.TopicalCrawler
Class-Path: ../../lib/antlr-2.7.6.jar ../../lib/asm-attrs.jar ../../li
b/asm.jar ../../lib/axis-1.4.jar ../../lib/axis-ant-1.4.jar ../../lib
/axis-spring-provider-0.1.0.jar ../../lib/cglib-2.1.3.jar ../../lib/c
heckstyle-5.4-all.jar ../../lib/checkstyle-5.4.jar ../../lib/commons-
collections-2.1.1.jar ../../lib/commons-logging-1.1.1.jar ../../lib/c
ommons-logging-adapters-1.1.1.jar ../../lib/commons-logging-api-1.1.1
.jar ../../lib/dom4j-1.6.1.jar ../../lib/ehcache-1.2.3.jar ../../lib/
hibernate-annotations.jar ../../lib/hibernate-commons-annotations.jar
../../lib/hibernate-entitymanager.jar ../../lib/hibernate-tools.jar
../../lib/hibernate3.jar ../../lib/javassist.jar ../../lib/jaxen-1.1.
1.jar ../../lib/jaxrpc-1.1-axis14.jar ../../lib/jdbc2_0-stdext.jar ..
/../lib/jericho-html-3.1.jar ../../lib/jing.jar ../../lib/jta.jar ../
../lib/junit.jar ../../lib/log4j-1.2.9.jar ../../lib/mysql-connector-
java-5.1.6-bin.jar ../../lib/ontopia-vizlet.jar ../../lib/ontopia.jar
../../lib/pmd-4.2.6.jar ../../lib/signed-vizlet.jar ../../lib/slf4j-
api-1.5.11.jar ../../lib/slf4j-log4j12-1.5.11.jar ../../lib/xercesImp
l-2.6.2.jar ../../src/main/config/log4j.properties
I have added slf4j-log4j12-1.5.11.jar, log4j-1.2.9.jar, slf4j-
api-1.5.11.jar and even log4j.properties in my classpath. But the logging doesnt work.
Any ideas how to solve it?
Thanks
Try out with slf4j-api-1.7.5 , log4j-1.2.17 and slf4j-log4j12-1.7.5 and make sure U have one binder jar (only slf4j-log4j12-1.7.5.jar) in your class path. Then add log4j.properties file into src/main/resources . Just try out with this log4j.properties example.
At the end of your classpath there's:
../../src/main/config/log4j.properties
As far as I know, classpath can only contain jars, zips or directories. Adding other files has no effect.
Try packing your properties into a jar file or include the directory that contains it.