Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 312
m.feyzollahi Avatar asked Dec 28 '25 14:12

m.feyzollahi


1 Answers

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]
like image 90
Chamila Adhikarinayake Avatar answered Dec 31 '25 17:12

Chamila Adhikarinayake



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!