Configuring Reportportal with Java +TestNG or Java + Log4j - 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

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!

Log4j log custom level for specific user(s) in production

In production environment I'm only logging WARN and ERROR log messages.
I need to implement a mechanism that logs ALL log levels for (a) specific user(s).
I'm handling requests coming in from outside (not necessarily a servlet) and from the beginning I can retrieve the users name, so I'm able to put users name in MDC and it will go to the log messages.
However, I need to check if users name is in a predefined list of users (this list can actually dynamically be updated during runtime) and if the users name is in this list then I need to enable (for this user only) logging to be from fx. TRACE level (meaning all TRACE, DEBUG, INFO, WARN and ERROR).
Is this possible?
UPDATE #1: We're using Spring Boot Log4j
UPDATE #2: Log4j config
LOG_PATTERN=%d{yyyy-MM-dd HH:mm:ss.SSS} %X{context} ${PID} %5p %-10X{username} [%t] - %c{1}(%L): %m%n
log4j.rootCategory=INFO, amqp
log4j.category.org.springframework=WARN
log4j.category.com.acme=DEBUG
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=logs/app.log
log4j.appender.file.MaxFileSize=100MB
log4j.appender.file.MaxBackupIndex=10
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=${LOG_PATTERN}
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=${LOG_PATTERN}
log4j.appender.amqp=org.springframework.amqp.rabbit.log4j.AmqpAppender
log4j.appender.amqp.host=localhost
log4j.appender.amqp.port=5671
log4j.appender.amqp.username=username
log4j.appender.amqp.password=password
log4j.appender.amqp.virtualHost=vhost
log4j.appender.amqp.exchangeName=logging.pub
log4j.appender.amqp.exchangeType=topic
log4j.appender.amqp.routingKeyPattern=%c.%p
log4j.appender.amqp.declareExchange=false
log4j.appender.amqp.durable=true
log4j.appender.amqp.autoDelete=false
log4j.appender.amqp.contentType=text/plain
log4j.appender.amqp.generateId=false
log4j.appender.amqp.senderPoolSize=2
log4j.appender.amqp.maxSenderRetries=30
log4j.appender.amqp.layout=org.apache.log4j.PatternLayout
log4j.appender.amqp.layout.ConversionPattern=${LOG_PATTERN}
After all the clarifications, the short answer is: no.
The very first check that is done by log4j's trace/debug/.../error methods is the logger level. If the log event level is below the logger configured level -- nothing else is done, the logging method returns. Message formatting, processing the diagnostic context, triggering appenders -- all come later, provided that there is anything to process. In log4j 1 it cannot be changed by configuration.
In log4j 2 we have global filters, which are checked prior to the logger level test -- although I don't know if they'd be fit for this kind of task, I'd definitely start looking there. If you can upgrade to log4j 2, check them.

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.

Spring WS with webServiceTemplate.marshalSendAndReceive returns Received error for request, Service Unavailable : Not Found [404]

I'm trying to ammend an existing SOAP Webservice that uses Spring-WS and JAXB on Tomcat. I've created the new WAR file with my changes and deployed it in the webapps foder under Tomcat installation.
When calling the original (already existing) methods of the service, the service SOAP request and response is fine. But when calling the service on the new method, I get service SOAP response of service unavailable and not found [404]
2011-07-25 12:58:23,365 DEBUG [org.springframework.ws.client.core.WebServiceTemplate] - Opening [org.springframework.ws.transport.http.HttpUrlConnection#12b9f14] to [http://<service URL>]
2011-07-25 12:58:23,521 DEBUG [org.springframework.ws.soap.saaj.support.SaajUtils] - SOAPElement [com.sun.xml.internal.messaging.saaj.soap.ver1_1.Envelope1_1Impl] implements SAAJ 1.3
2011-07-25 12:58:23,552 DEBUG [org.springframework.ws.soap.saaj.support.SaajUtils] - SOAPElement [com.sun.xml.internal.messaging.saaj.soap.ver1_1.Body1_1Impl] implements SAAJ 1.3
2011-07-25 12:58:23,896 DEBUG [org.springframework.ws.client.MessageTracing.sent] - Sent request [<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header/><SOAP-ENV:Body><ns2:DelRequest xmlns:ns2="http://<changed_address>"><ns2:userId>ncc1#%</ns2:userId><ns2:dateFromMillis>1308956400000</ns2:dateFromMillis><ns2:dateToMillis>1311634800000</ns2:dateToMillis></ns2:DelRequest></SOAP-ENV:Body></SOAP-ENV:Envelope>]
2011-07-25 12:58:25,318 DEBUG [org.springframework.ws.client.core.WebServiceTemplate] - Received error for request [SaajSoapMessage {http://<changed_address>}DelRequest]
2011-07-25 12:58:25,318 ERROR [net.msgplugin.controller.DeleteController] - Conversation service unavailable at: http://, Not Found [404] , null
I've imported the project into Eclipse and have made the following changes to the project properties:
1) With in Project Facets, I've checked the 'Dynamic Web Module' and 'Java' Facets.
2) In Java EE Module Dependencies, I've checked Maven Dependencies.
Two things which are to be noted here are:
a) The developer was using JBoss when developing the Webservice but recently the project was chagned to Tomcat.
b) The project has a MAVEN folder structure, hence the web.xml file is in src/main/webapp/WEB-INF folder rather than WebContent/WEB-INF, taht got created when I selected the 'Dynamic Web Module' facet.
Any suggestions wld be hugely appreciated?
Thanks
========================================================================
HI
I managed to fix the Not Found [404] error but am now getting another error.
Upon further investigation and debuggin into WebServiceTemplate and MessageDispatcher classes, I found that following output on the console:
DEBUG [org.springframework.ws.transport.http.WebServiceMessageReceiverHandlerAdapter] - Accepting incoming [org.springframework.ws.transport.http.HttpServletConnection#11f05a1] to [http://<Service_URL>]
TRACE [org.springframework.ws.server.MessageTracing.received] - Received request [<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header/><SOAP-ENV:Body><ns2:DelRequest xmlns:ns2="http://<changed_address>"><ns2:userId>ncc1#%</ns2:userId><ns2:dateFromMillis>1309042800000</ns2:dateFromMillis><ns2:dateToMillis>1311721200000</ns2:dateToMillis></ns2:DelRequest></SOAP-ENV:Body></SOAP-ENV:Envelope>]
DEBUG [org.springframework.ws.server.endpoint.mapping.PayloadRootAnnotationMethodEndpointMapping] - Looking up endpoint for [{<changed_address>}DelRequest]
DEBUG [org.springframework.ws.soap.server.SoapMessageDispatcher] - Endpoint mapping [org.springframework.ws.server.endpoint.mapping.PayloadRootAnnotationMethodEndpointMapping#6ee035] maps request to endpoint [public final net.org.messagehistory.schema.GetDelResponse net.org.messagehistory.service.endpoint.MessageHistoryEndpoint.delHistory(net.org.messagehistory.schema.GetListRequest) throws javax.xml.datatype.DatatypeConfigurationException]
DEBUG [org.springframework.ws.soap.server.SoapMessageDispatcher] - Testing endpoint adapter [org.springframework.ws.server.endpoint.adapter.GenericMarshallingMethodEndpointAdapter#1a23f67]
DEBUG [org.springframework.ws.server.endpoint.adapter.GenericMarshallingMethodEndpointAdapter] - Unmarshalled payload request to [net.org.messagehistory.schema.DelRequest#c76003]
The end error message is now 'Argument type Mismatch' which I found was generated from one of the methods from within WebServiceTemplate.class
Can somebody suggest what coudl be the problem here?
Managed to get this sorted. So, just wanted to share the solution that somebody might find helpful.
Make sure that the Endpoint method is annotated with the following
#PayloadRoot(localPart = MESSAGES_TO_DELETE, namespace = MESSAGE_NAMESPACE)
where localpart is the same as the your payload request in the schema.xsd
Thanks

log4j with liferay and tomcat

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).

Resources