0

How can I enable my application logs (API published in WSO2) in APIM_HOME>/repository/conf/log4j2.properties file? I went through the 3.0.0 documentation (https://apim.docs.wso2.com/en/latest/Administer/ProductAdministration/Monitoring/Logging/setting-up-logging/#setting-up-logging-in-api-manager) and tried to configure logging for my app component, but I'm unable to see the application specific logs in wso2carbon.log.

By using custom mediators I am able to log the complete request/response but I am looking to log all the "log.xxx()" lines I have in my code, based on the log level I set in the log4j2.properties file in WSO2. I use slf4j logger in code so I tried enabling logging for "org.slf4j" package and also tried enabling for my application's specific package, but neither worked (the "applogger" below was added to list of comma separated loggers in the same file:

# application logs
logger.applogger.name = org.slf4j
logger.applogger.level = DEBUG

logger.applogger.name = my.application.package
logger.applogger.level = DEBUG

I also checked these (1, 2) logging related questions on SO but couldn't find a definitive answer that solved my problem. When I tried following this link to enable message tracing from carbon console I get the below error:

error
Cannot set eventing configuration. Backend server may be unavailable.; nested exception is:
org.apache.axis2.AxisFault: unknown - An error has occurred. Please refer the logs for more details.

in logs:

TID: [-1234] [] [2020-02-11 04:56:48,913] ERROR {org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver} - Exception occurred while trying to invoke service method configureEventing java.lang.NullPointerException
        at org.wso2.carbon.analytics.message.tracer.handler.conf.RegistryPersistenceManager.updateConfigurationProperty(RegistryPersistenceManager.java:84)
.............................
TID: [-1234] [] [2020-02-11 04:56:48,922] ERROR {org.wso2.carbon.analytics.message.tracer.handler.ui.MessageTracerHandlerAdminClient} - Cannot set eventing configuration. Backend server may be unavailable. org.apache.axis2.AxisFault: unknown
        at org.apache.axis2.util.Utils.getInboundFaultFromMessageContext(Utils.java:531)
  • What is the log4j version used in your custom mediator? – Vithursa Mahendrarajah Feb 11 '20 at 05:19
  • I did not specify a log4j version in my custom mediator. only this was added to the sequence: ` ` I only added this temporarily in custom mediator to test if I could log the entire response. As a permanent measure, following the documentation, I am looking to add logging via the log4j2.properties file. – Sanjeev Rayaprolu Feb 11 '20 at 06:02
  • Sorry. I thought that you are using a custom class mediator. So your requirement is to log the request and response and achieved it via adding custom mediators. Can you explain the application you are talking about? I'm not quite clear on what you are trying with log4j2.properties? – Vithursa Mahendrarajah Feb 11 '20 at 06:13
  • **Application**: My Backend API that I have published in WSO2 API-M. **Requirement**: I have log.info(), log.debug() statements in my API code which I would like to see printed in some logs (ex: wso2carbon.log) and I am unable to get that. This is where log4j2.properties comes in. I just mentioned as a side note that complete request/response logging is happening via custom mediators, but this is separate from my actual requirement of logging INFO/DEBUG/ALL statements within my code. Hope that helps. – Sanjeev Rayaprolu Feb 11 '20 at 07:54

1 Answers1

0

By using custom mediators I am able to log the complete request/response but I am looking to log all the "log.xxx()" lines I have in my code, based on the log level I set in the log4j2.properties file in WSO2. I use slf4j logger in code so I tried enabling logging for "org.slf4j" package and also tried enabling for my application's specific package, but neither worked (the "applogger" below was added to list of comma separated loggers in the same file:

logger.applogger.name = org.slf4j

logger.applogger.level = DEBUG

logger.applogger.name = my.application.package

logger.applogger.level = DEBUG

Seems like you have added same name repetitively. Add following your application logger as follows:

logger.applogger.name = my.application.package 
logger.applogger.level = DEBUG

and set it to the loggers configuration:

loggers = AUDIT_LOG, trace-messages, org-apache-coyote, com-hazelcast, Owasp-CsrfGuard, org-apache-axis2-wsdl-codegen-writer-PrettyPrinter.... org-wso2-carbon-apimgt-gateway-mediators-BotDetectionMediator,correlation, JAGGERY_LOG, applogger

You do not need to set the logger name as org.slf4j. You should only specify the package name the component. Check whether the back-end implementation is using log4J2 for logging. If not, there might be issues due to dependency version mismtach.

Community
  • 1
  • 1
Vithursa Mahendrarajah
  • 1,194
  • 2
  • 15
  • 28
  • I did not add the applogger name repetitively. They were both added separately to try both ways to see if anything worked (_I use slf4j logger in code so I tried enabling logging for "org.slf4j" package and also tried enabling for my application's specific package, but neither worked_). If my backend implementation doesn't use log4j2, what can I do to get logs? – Sanjeev Rayaprolu Feb 11 '20 at 09:19
  • Since we are not using log4j2 in our backend implementation what can be done to generate log statements in wso2 logs? – Sanjeev Rayaprolu Feb 12 '20 at 06:36