How do I log records in API Request Log?

How do I log records directly in API Request Logs? similar to Error Logs

I tried frappe.logger(…) but it creates log in logs/ directory instead of the web UI.

Thanks.

frappe.logger() writes logs to the site’s /logs directory, so those entries won’t appear in the Desk UI.

The API Request Log shown in the UI is backed by the API Request Log DocType. Records only appear there when a document is inserted into that DocType.

If you want to log something in API Request Log, you need to create the document manually, for example:

frappe.get_doc({

"doctype": "API Request Log",

"path": frappe.request.path,

"method": frappe.request.method,

"request": frappe.request.data,

"user": frappe.session.user

}).insert(ignore_permissions=True)

This will create a record that becomes visible in API Request Log in the Desk UI.