On 04/23/2018 06:07 PM, Paul Querna wrote:
Morning dev@,

I just committed mod_log_json to trunk in r1829898.

Right now, to use it you need something like this:

     LogFormat "%^JS" json
     CustomLog "logs/access_log.json" json

Currently it has a static format of the JSON, and example message is like this:

{
   "log_id": null,
   "vhost": "127.0.0.1",
   "status": "404",
   "proto": "HTTP\/1.1",
   "method": "GET",
   "uri": "\/x",
   "srcip": "127.0.0.1",
   "bytes_sent": 199,
   "hdrs": {
     "user-agent": "curl\/7.54.0"
   }
}
[...]

Is there a real need for this?
E.g. a config like

LogFormat "{ \"req_id\": \"%L\", \"servername\": \"%v\", \"status\": \"%s\", \"proto\": \"%H\", \"method\": \"%m\", \"uri\": \"%U\" }" json
CustomLog "logs/access_log.json" json

ErrorLogFormat "{ \"server\": \"%-v\", \"timestamp\": \"%-{cu}t\", \"module\": \"%-m\", \"loglevel\": \"%-l\", \"req_id\": \"%-L\", \"src_file\": \"%-F\", \"error\": \"%-E\", \"message\": \"%-M\" }"

would do (almost) the same.
With the exception, that there is a problem with double quotes in the error log.
In server/util.c there is a

case '\\':
    *d++ = *s;
    break;
case '"': /* no need for this in error log */
    d[-1] = *s;
    break;


which should be changed to

case '\\':
case '"':
    *d++ = *s;
    break;

After doing this, httpd is writing nice JSON without an extra module.

[...]
- mod_log_json is not configurable right now, the format is static.
Obviously, being able to configure what is logged, what headers, etc
is valuable. I played with some options here, but wasn't happy with
it.  Any ideas?
[...]


If someone is asking me there should be no new module for writing JSON, but the current available implementation should be enabled to let the user config the desired format. (OK, the unicode characters ('\xAA\xBB') are still a problem, but in our environment we fix them by preprocessing.)

Best regards,
Frank


Reply via email to