Frank
Frank

Reputation: 298

How to display username and invoked api name in wso2 apim log?

I am trying to configure gateway access log of wso2 apim (4.0.0) so that it should contain api username and api name in a log file. I followed this documentation.

The log file structure I would like to have as below:

datetime | remoteIp | username | invoked_api_name | api_url | request | response

Any help is appreciated

Upvotes: 0

Views: 478

Answers (2)

Athiththan
Athiththan

Reputation: 2218

The invoked_api_name and username are not available at the Access Log level. Therefore, you can implement a custom Synapse Handler to log the relevant information to either wso2carbon.log or separate logs as per your need.

This is a sample written for API Manager 3.2.0 Custom API Log Handler. You can also refer to the Handler mentioned by @Ishara Cooray.

Update the dependencies to align with the API Manager 4.0.0 environment. The TOML configuration to engage the Handlers will be as following (it is slightly different from the configs in 3.2.0)

[synapse_handlers.<custom_name>]
enabled = true
class = '<package-name.class>'

For example

[synapse_handlers.api_log_handler]
enabled = true
class = 'com.sample.handlers.APILogHandler'

Update

I have updated the custom handler implementation with API Manager 4.0.0 dependencies. Find the branch and updated README here.

Upvotes: 2

Ishara Cooray
Ishara Cooray

Reputation: 123

you are not be able to include username in the access_log as this information is not available at this level. You may write a custom handler to log the required information in a log file. https://github.com/CrowleyRajapakse/CustomLogHandler

Upvotes: 1

Related Questions