Search code examples
loggingwso2wso2-api-managerapim

Is there a way to add username in API Log in WSO2 APIM?


I use wso2 api manager apilog with this url: https://apim.docs.wso2.com/en/latest/observe/api-manager/monitoring-api-logs/

I need to log username of user that calls the api too. Is there any solution without using CustomLogHandler ? What is the easiest way?


Solution

  • You could use API Policy feature and add a policy to the request path to log the username. Following is a sample .j2 file content that can be used for this

    <log level="custom">
        <property name="USER_NAME" expression="$ctx:api.ut.userName"/>
    </log>
    

    After deploying this, you will see a log similar to following when you invoke an API

    [2024-05-27 14:50:56,043]  INFO - LogMediator {api:PizzaShackAPI:v1.0.0} USER_NAME = [email protected]