How to log request body data

1. Caddy version (caddy version):

v2.1.1

2. How I run Caddy:

a. System environment:

b. Command:

paste command here

c. Service/unit/compose file:

paste full file contents here

d. My complete Caddyfile or JSON config:

curry.pp.ua {
        root * /usr/share/caddy
         log {
                output file /var/log/caddy/access.log {
                }
                level DEBUG
        }
        reverse_proxy /wx/ 127.0.0.1:8000 {
        }
}

3. The problem I’m having:

how to log request body data, such as, post payload, in access log ?

4. Error messages and/or full log output:

5. What I already tried:

6. Links to relevant resources:

Can anyone answer that?

Hi @curry,

I don’t believe body logging is possible currently.

How do you want this to work? Request bodies can be many hundreds of MBs or GBs large. They can be a binary encoding. They can have malicious content if pasted into the wrong places. It’s inefficient and expensive to read and buffer the body. I’ve never seen a good solution for generalized request body logging. Nor have I ever found it a good idea for the proxy to do this; usually the application should do it if it is needed.

Thanks, i want to record little data, such as first 100 characters, if request bodies is too large.

Bytes or characters? I see you’re from a locale with multi-byte characters, which means we now have to consider the encoding of the body and decode it. Any suggestions how that would be done, and how we can read the body efficiently? It’ll essentially require buffering all the response bodies.

This topic was automatically closed after 30 days. New replies are no longer allowed.