Skip to content

Conversation

@TaeyeongKwak
Copy link
Contributor

@TaeyeongKwak TaeyeongKwak commented Oct 24, 2025

Description

This PR adds support for nested log format in logger plugins. Previously, the log_format configuration only supported flat key-value structures. This feature allows users to more efficiently organize and group log fields by defining hierarchical/overlapping log structures.

For example, user can set log_format as below:

{
    "log_format": {
        "host": "$host",
        "client_ip": "$remote_addr",
        "request": {
            "method": "$request_method",
            "uri": "$request_uri",
            "headers": {
                "user_agent": "$http_user_agent"
            }
        },
        "response": {
            "status": "$status"
        }
    }
}

Output Example:

{
    "response": {
        "status": 200
    },
    "route_id": "1",
    "client_ip": "127.0.0.1",
    "request": {
        "method": "GET",
        "uri": "/",
        "headers": {
            "user_agent": "curl/8.5.0"
        }
    },
    "host": "127.0.0.1"
}

Which issue(s) this PR fixes:

Fixes #

Checklist

  • I have explained the need for this PR and the problem it solves
  • I have explained the changes or the new features added to this PR
  • I have added tests corresponding to this change
  • I have updated the documentation to reflect this change
  • I have verified that this change is backward compatible (If not, please discuss on the APISIX mailing list first)

@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. enhancement New feature or request labels Oct 24, 2025
@Baoyuantop
Copy link
Contributor

Hi @TaeyeongKwak, do we need to limit the maximum nesting level? In addition, you need to add the corresponding documentation content.

@TaeyeongKwak
Copy link
Contributor Author

TaeyeongKwak commented Oct 28, 2025

Hi @TaeyeongKwak, do we need to limit the maximum nesting level? In addition, you need to add the corresponding documentation content.

Hi @Baoyuantop, Thank you for your comment.
Come to think of it, I agree that we should set a maximum depth as you mentioned.
Considering typical use cases, I think allowing a maximum depth of five levels would be sufficient.
I'll apply this change and update the documentation accordingly.

And currently, I've only added test cases to some plugins. Should I add test cases for the other plugins too?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants