How to append logs to STDOUT in WSO2? - wso2

I have a requirement where I want to publish the WSO2 API Manager(3.1.0) and Identity server(IS-KM - 5.1.0) logs to STDOUT. Can someone let me know how to configure it in log4j2.properties file?

By default, WSO2 has a log appender named CARBON_CONSOLE which appends all the logs to stdout (Console) and you don't want to specifically use stdout (log4j.appender.stdout=org.apache.log4j.ConsoleAppender) property to pipe logs to standard output

Related

Log Configuration in WSO2

So i'm working on PER-API log configuration in WSO2, in order to log REQUEST/RESPONSE for an API call, we need to
Modify the file log4j.properties in < APIM HOME >\repository\conf by adding the following lines to it
log4j.appender.TestAPI_APPENDER=org.apache.log4j.RollingFileAppender
log4j.appender.TestAPI_APPENDER.File=${carbon.home}/repository/logs/PerAPI/${instance.log}/wso2-APILogs-service${instance.log}.log
log4j.appender.TestAPI_APPENDER.MaxFileSize=1000KB
log4j.appender.TestAPI_APPENDER.MaxBackupIndex=10
log4j.appender.TestAPI_APPENDER.layout=org.apache.log4j.PatternLayout
log4j.appender.TestAPI_APPENDER.layout.ConversionPattern=%d{ISO8601}
[%X{ip}-%X{host}] [%t] %5p %c{1} %m%n%n
log4j.category.API_LOGGER.admin--APINAME= TRACE,
TestAPI_APPENDER
It logs the following details to a .txt file which is pretty comprehensive and cool
However i do have some questions that i'm stuck in and would like help in, here are they
The HTTP Status Code for the response is not being logged here which i badly need, I've looked here and it says to use %s - HTTP status code of the response however when i put the character %s in the log4j.properties ConversionPattern, those characters are printed as they are, how can i achieve this?
Secondly, does wso2 has some sort of portal in order to visualize these custom logs?
Thirdly, i need to put a line at the end of request/response (4 entries per API CALL) log lines and i'm unable to find any solution, if i hardcode a line into the log4j.properties ConversionPattern, i suppose it would print after each entry, please help?!
Thank you
Please find the below answers for your questions
By enabling wire logs settings you can easily track the HTTP Status Code for the response. You can enable the header and wirelogs by un-commenting following lines in log4j.properties file (located at: \repository\conf)
log4j.logger.org.apache.synapse.transport.http.headers=DEBUG
log4j.logger.org.apache.synapse.transport.http.wire=DEBUG
The third Question, you can achieve this by using log mediator in In-sequence(print a line in request) and out-sequence(print a line in response).For an example you can use custom log in your api synapse configuration file as follows (here I use this custom log in in sequence)
<sequence xmlns="http://ws.apache.org/ns/synapse" name="admin--TwitterSearch:v1.0.0--In">
<log level="custom">
<property name="test" value="your value goes here……….” />
</log>
</sequence>
You can enable wirelogs to track the request and responses of the API when it is getting invoked. To do that uncomment following line in log4j.properties file.
log4j.logger.org.apache.synapse.transport.http.wire=DEBUG
Furthermore if you want to log the http messages you can uncomment following line as well.
log4j.logger.org.apache.synapse.transport.http.headers=DEBUG
In WSO2 API Manager Analytics, a log Analyzer is included. You need to configure WSO2 API Manager Analytics with WSO2 API Manager to get that.
If you want to print a customized log for the API, you can use the Log mediator and add a Log mediator as a mediation extension per API with the required log to be printed in the synapse configuration of the API.

Setting the external proxy which requires authentication for Postman

I am setting up the native windows Postman and trying to run the "Request Header" api provided in Postman Echo collection. I get the following error.
"Error: tunneling socket could not be established, statusCode=407"
I can see in the postman console that it is picking up the correct proxy server from environment. My proxy server requires authentication, how do I provide credential information. I tried to start Postman using the following command but it did not help.
postman.exe --proxy-server=userName:password#myproxy:8090
Unfortunately the proxy tab in Settings does not allow authenticated proxies.
Entering proxy info in the format "userName:password#myproxy" will cause everything before the '#' symbol to be removed.
You may already know, but since version 5.2, Postman includes a "Proxy" tab into the "Settings" section.
You should be able to configure your proxy on your system (if you are using Windows you can do it in Internet Options>>Connections>>LAN Settings) and then enable the "Use system proxy" in this tab.
After testing this method is helpful:
Windows- create a postman.bat file with the following content:
set HTTP_PROXY=http://USER:PASS#host:port
set HTTPS_PROXY=https://USER:PASS#host:port
start C:\path\to\Postman.exe
as I get this from here
In the "Global Proxy Configuration" section of the Proxy tab, setting the "Proxy Server" value to -
userName:password#proxyHost:proxyPort resolves the issue.
I could solve this problem for Postman and also for other local tools that are not capable of NTLM authentication against a proxy.
The solution is the open source proxy service/demon CNTLM that runs under Linux, macOS and Windows. The project has not been updated for a while but I could easily install and run it under Windows 10.
Best part is that it is able to check your proxy's capabilities and automatically find the latest NTLM version that the proxy supports.
http://cntlm.sourceforge.net/
You can add Proxy-Authorization header with value Basic base64encode($user:$password)
launch postman through :
vagrant#localhost:~/Downloads/Postman-linux-x64-7.6.0/Postman/app$ ./Postman
and set/unset proxy values

wso2 truncates the jms destination path

I'm running the example from http://wso2.com/library/tutorials/2011/11/configuring-wso2-esb-with-oracle-as-messaging-media/
Once the proxy is defined it works as intended, i.e. it reads a messages from the queue and places the SOAP call.
However, if the proxy is re-opened and saved wso2 starts spinning spitting out errors:
java.naming.security.credentials=tromanow}
javax.naming.AuthenticationException: [LDAP: error code 49 - INVALID_CREDENTIALS: Bind failed: ERR_229 Cannot authenticate user ]
at com.sun.jndi.ldap.LdapCtx.mapErrorCode(LdapCtx.java:3087)
at com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:3033)
at com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:2835)
at com.sun.jndi.ldap.LdapCtx.connect(LdapCtx.java:2749)
at com.sun.jndi.ldap.LdapCtx.<init>(LdapCtx.java:316)
The problem is that the JMS destination LDAP path gets truncated.
From:
<parameter name="transport.jms.Destination">cn=tro_Q_JMS1,cn=OracleDBQueues,cn=ORCL,cn=OracleContext,ou=Services, o=sgi,c=us</parameter>
To:
<parameter name="transport.jms.Destination">cn=tro_Q_JMS1</parameter>
The workaround is to re-append the rest of the LDAP path to the JMS destination whenever saving the proxy. Is there a better solution to this?
This looks like a UI bug related to the UI editor library used by WSO2 ESB management console. You can do the changes in the file system using the xml file and save. Then it will saved successfully. If you are using developer studio, then you can deploy artifacts as CAR (Composite Archive) files and you do not need to change them from the UI.

WSO2 BAM 2.5.0 output adapters are missing

I would like to use email output event adapter in WSO2 BAM 2.5.0. So according to documentation I should go to Configure --> Output Event Adapters --> Add Output Event Adapter, but there is no email adapter in select list.
Why?
Where are output adaptors?
According to documentation there should be email, mysql, websocket etc. adapters.
Should I enable something in BAM configs files?
Or it just a bug, if yes, is there any patch?
Here is link to documentation: Output Event Adapters
The SOAP output event adaptor does not get loaded properly and this is a bug in this version. So you would need to remove the "org.wso2.carbon.event.output.adaptor.soap_1.0.2.jar" file from "repository/components/plugins" directory and restart the server. You should get the email output event adapter to work after doing this.

WSO2 ESB - How to enable trace for endpoint

In the documentation for WSO2 4.0.2 ESB it says following
The endpoints also have a trace attribute, which turns on detailed
trace information for messages being sent to the endpoint. These are
available in the trace.log configured via the log4j.properties file
(which can be found within lib folder once you unzip wso2 ESB ZIP).
Setting the trace log level to TRACE will dump detailed trace
information including message payloads.
Can you please share sample log4j snippet to start tracing the just the endpoint. Do I have to enable tracing for proxy service also to enable tracing for end point?
Can you please elaborate?
thanks
Abhijit
You can add namespaces of classes to the log4j.properties (in the lib folder of WSO2) that should be traced. With the following line you will enable the tracing of endpoints:
log4j.category.org.apache.synapse.endpoints=TRACE
This enables the tracing for all enpoints (so unfortunately not only for your specific endpoint).
By the way this configuration is also crusial to anable tracing or logging for your own classes:
log4j.logger.com.yourCompany=DEBUG
The above enabling of the endpoint tracing will result in logs like this (endpoint pointing to a JMS queue):
[2012-08-17 09:22:13,855] DEBUG - AddressEndpoint Sending message through endpoint : endpoint_9b9ef24d0d136e3e709a6c21cac87806d5d547bc5ba68dc6 resolving to address = jms:/myJMS?transport.jms.DestinationType=topic&transport.jms.ConnectionFactoryJNDIName=QueueConnectionFactory&java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory
As FiveO said, you can edit log4j file to see what is going on..But there is another way to enable trace attribute for endpoints..
You simply need to add trace="enable" attribute to your endpoint configuration..
<address uri="http://abc.com" trace="enable">