如何在 wso2 apim 日志中显示用户名和调用的 api 名称? [英] How to display username and invoked api name in wso2 apim log?

查看:26
本文介绍了如何在 wso2 apim 日志中显示用户名和调用的 api 名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试配置 wso2 apim (4.0.0) 的网关访问日志,以便它应该在日志文件中包含 api 用户名和 api 名称.我跟着 this文档.

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:

日期时间 |远程IP |用户名 |被调用的api_name |api_url |请求 |回复

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

感谢任何帮助

推荐答案

invoked_api_nameusername 在访问日志级别不可用.因此,您可以实现自定义 Synapse 处理程序,将相关信息记录到 wso2carbon.log 或根据需要单独的日志.

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.

这是为 API Manager 3.2.0 编写的示例 自定义 API 日志处理程序.也可以参考@Ishara Cooray提到的Handler.

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.

更新依赖项以与 API Manager 4.0.0 环境保持一致.使用 Handlers 的 TOML 配置如下(与 3.2.0 中的配置略有不同)

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>'

例如

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


更新

我已使用 API Manager 4.0.0 依赖项更新了自定义处理程序实现.找到分支和更新的README 这里.

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

这篇关于如何在 wso2 apim 日志中显示用户名和调用的 api 名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆