log4j with liferay and tomcat - log4j

I have a Liferay setup on the Tomcat6. I used Log4j initially for portlets/webapps by adding log4j.properties file in the classes folder and log4j.jar file in the web-inf/lib.
Now we have few quartz jobs which are available in the tomcat/lib folder and I want to enable log4j logging for these jobs as well.
For these quartz jobs I have copied same log4j.properties file in the tomcat/lib.
With the new configuration I keep getting the following error:
Could not instantiate appender named "JOBS"
A "org.apache.log4j.RollingFileAppender" is not assignable a "org.apache.log4j.Appender" variable.
The class "org.apache.log4j.Appender" was loaded by ...
How to remove this error?
Is there any way I can keep a single log4j.properties file which can be used by both shared/lib as well as portlet/webapps.

According to this post the problem is that you have configured your log4j twice.
My solution would be that you create the logger instance like this
private static Logger logger = Logger.getLogger(FooBar.class.getName());
and not to have log4j.properties under any lib or class folder but having it under a folder named resources.
AFAIK this should be a place where the both parts of your application may have access to.

Known issue in Liferay: http://issues.liferay.com/browse/LPS-9376
In my case, the problem occurred once I started to use ServiceBuilder services, and added Log4J Logger to one of my ...LocalServiceImpl classes.
Once I removed Log4J logging from there everything got back to norm - exception disappeared.
(I made service methods throw exceptions, and was catching them in a code not related to ServiceBuilder read/generated classes, but it could also be done by changing Log4J logger calls to Liferay's LogUtil calls).

Related

Log4j2 NoSQL Cassandra configuration in .properties file

I'm trying to add an appender to Karaf 4.2, to log exceptions to Cassandra (DSE). My "org.ops4j.pax.logging.cfg" file looks like this:
log4j2.rootLogger.appenderRef.cassandrass.ref = Cassandra
# Cassandra Appender
log4j2.appender.cass.type=NoSql
log4j2.appender.cass.name=Cassandra
but it fails with
org.ops4j.pax.logging.pax-logging-api [log4j2] ERROR : NoSQL provider not specified for appender [Cassandra]. Ignored FQCN: org.apache.logging.log4j.spi.AbstractLogger
Null object returned for NoSql in Appenders. Ignored FQCN: org.apache.logging.log4j.spi.AbstractLogger
Unable to locate appender "Cassandra" for logger config "root" Ignored FQCN: org.apache.logging.log4j.spi.AbstractLogger
Almost every configuration example I find is in the xml format. Does anyone have a working example they can share? It is complaining "NoSQL provider not specified" which makes perfect sense. I just don't know how to configure the provider to be Cassandra
This is the guide I'm following: https://logging.apache.org/log4j/2.x/manual/appenders.html#CassandraAppender
It isn't clear in your post what you're trying to achieve. If you're attempting to configure logging for Cassandra, it won't work with Log4j.
Cassandra uses SLF4J with logback so you need to configure it accordingly. For details, see Configuring logging in Cassandra.
If you're using Log4j in your app, have a look at Configuring Log4j with a properties file. Cheers!

Configuring Reportportal with Java +TestNG or Java + Log4j

Have been trying to configure Reportportal withe a sample project. The following steps have been done:
1.Start a Docker and get the reportporal page up and running.
2.In the Java project, added the bintray repository, java-agent-testng, logger-java-log4j dependencies.
3.Included log4j.properties file in the project and also the log4j.appender line for reprortportal
log4j.appender.reportportal=com.epam.ta.reportportal.log4j.appender.ReportPortalAppender
log4j.appender.reportportal.layout=org.apache.log4j.PatternLayout
log4j.appender.reportportal.layout.ConversionPattern=[%d{HH:mm:ss}] %-5p (%F:%L) - %m%n
4.Included log4j info lines for one of the #Test methods.
5.Ran the Test script and made sure the log info line is seen on the console.
6.However, the reportportal dashboard still shows "No Results Found"
7.Also, added the following line for the Test Method.
#Listeners({ReportPortalTestNGListener.class})
8. This threw an exception with Jackson.
A few questions running in my mind:
1.Do we need both TestNG and Log4j to integrate with reportportal or just one of them is fine.
2. With the above steps carried out, is there anything that has been missed. Why am I not seeing data on my reportportal dashboard.
I only did this using the testNG integration. We do have log4j but didn't needed that to post the tests in RP.
I do not however, have any screenshots or attachments.I think that is log4j integration.
#Chethan Swaroop
TestNG integration will send events as testStarted, testEnded into ReportPortal.
This will help to represent structure of test cases and statuses in RP.
Log4J integration (logger appender) will forward logs output into RP server, associating log line with active test case at the moment.
You can have only testNG integration, without logs (log4j), but you can't have log4j, without testing engine integration (testNG in you case)
Please try examples with you local ReportPortal instance:
https://github.com/reportportal/example-java-TestNG/tree/master/logback/src/main/java/com/epam/rp/tests

Hazelcast exception in logging

Using:
Hazelcast 3.6.1
Log4j 2.5
slf4j 1.7.13
Hazelcast client using Log4j cannot log the Membership 'printout'
Member [localhost]:19325
This client is being initialized programmatically (not via spring).
Instead, exception is thrown by logging infrastructure
2016-03-09 15:49:34,195 hz.client_0_qv-core.event-4 ERROR An exception occurred processing Appender STDOUT java.lang.IllegalArgumentException: can't parse argument number:
Member [localhost]:19325
at java.text.MessageFormat.makeFormat(MessageFormat.java:1429)
at java.text.MessageFormat.applyPattern(MessageFormat.java:479)
at java.text.MessageFormat.<init>(MessageFormat.java:362)
at java.text.MessageFormat.format(MessageFormat.java:840)
at org.apache.logging.log4j.message.MessageFormatMessage.formatMessage(MessageFormatMessage.java:94)
The error isn't related to the number of cluster members.
Server is able to print the message just fine using the same codebase.
I can provide the full stack trace if needed.
Defining logging configuration with system property: -Dhazelcast.logging.type solved the issue.
Have you tried to bind Hazelcast logging directly to log4j?
http://docs.hazelcast.org/docs/3.6/manual/html-single/index.html#logging-configuration

2 instance of Log4Net in same process parallel logging issue

I've read this question: log4net-and-logging-from-parallel-instances
I have written a DLL that uses log4net for logging.
I have a process that uses my DLL with 2 instances (same process)
The first instance of the class has access to the log. the second instance doesn't log at all.
I can't use the processID in the file name - as it works only with 2 different instance of the app, not from the same app.
how can I make all calls to log from both instance to write to the log file ?
(I get the logger using Ilog log = LogManager.GetLogger("ClassName") )
and in the Ctor I read the configuration file...
The only solution I thought is to get the log from the external app in the ctor but I don't want to external app to do anything with my own logging.
The problem was using the configurator at the constructor.
You can't call the configurator more than once.

Web application using log4j logs tons of severe error messages

I'm written an application which uses a library (Jabber stream objects) which internally uses log4j. When I deploy the application, there are no errors. However after some time, I could see lots of error message which look like this:
[#|2013-02-26T12:48:56.147+0000|SEVERE|oracle-glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=365;_ThreadName=SelectWorker 1;|java.lang.IllegalStateException: WEB9031: WebappClassLoader unable to load resource [org.apache.log4j.spi.NOPLoggerRepository], because it has not yet been started, or was already stopped
at org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1401)
at org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1359)
at org.apache.log4j.LogManager.getLoggerRepository(LogManager.java:197)
at org.apache.log4j.LogManager.getLogger(LogManager.java:228)
at org.apache.log4j.Logger.getLogger(Logger.java:117)
I have log4j.jar inside the WEB-INF/lib directory of my application, along with the external library (JSO.jar)
The issue [1] looked similar, but doesn't seem to be the same.
[1] Web service is not working on GlassFish
I've found that this happens when I redeploy a Servlet and went away when I overridden destroy() for my Servlet and did some cleanup there.

Resources