drogonframework / drogon

Drogon: A C++14/17/20 based HTTP web application framework running on Linux/macOS/Unix/Windows
MIT License
11.44k stars 1.1k forks source link

Don't log partial access log formats to INFO #1828

Closed BrainStone closed 11 months ago

BrainStone commented 11 months ago

Describe the bug Currently the AccessLogger plugin logs a line to info for every placeholder in the format string.
Now this isn't a huge deal, but fairly annoying regardless.

To Reproduce

  1. Configure a web application with the AccessLogger plugin, for example like this:
    drogon::app().addPlugin("drogon::plugin::AccessLogger", {}, {});
  2. Access any route
  3. Notice the following log output
    20231029 01:19:29.756930 300331 INFO  $request_date $method $url [$body_bytes_received] ($remote_addr - $local_addr) $status $body_bytes_sent $processing_time - AccessLogger.cc:157
    20231029 01:19:29.757006 300331 INFO   $method $url [$body_bytes_received] ($remote_addr - $local_addr) $status $body_bytes_sent $processing_time - AccessLogger.cc:157
    20231029 01:19:29.757022 300331 INFO   $url [$body_bytes_received] ($remote_addr - $local_addr) $status $body_bytes_sent $processing_time - AccessLogger.cc:157
    20231029 01:19:29.757037 300331 INFO   [$body_bytes_received] ($remote_addr - $local_addr) $status $body_bytes_sent $processing_time - AccessLogger.cc:157
    20231029 01:19:29.757054 300331 INFO  ] ($remote_addr - $local_addr) $status $body_bytes_sent $processing_time - AccessLogger.cc:157
    20231029 01:19:29.757070 300331 INFO   - $local_addr) $status $body_bytes_sent $processing_time - AccessLogger.cc:157
    20231029 01:19:29.757085 300331 INFO  ) $status $body_bytes_sent $processing_time - AccessLogger.cc:157
    20231029 01:19:29.757100 300331 INFO   $body_bytes_sent $processing_time - AccessLogger.cc:157
    20231029 01:19:29.757115 300331 INFO   $processing_time - AccessLogger.cc:157

Source: https://github.com/drogonframework/drogon/blob/4323e7b6efc27326b779e239f7a95456ed689ea4/lib/src/AccessLogger.cc#L157

Expected behavior I would expect this log not exist, to be trace or at most debug level. Probably best to log the entire format as debug log and then the splitting can be done as trace.

BrainStone commented 11 months ago

That was quick! Thank you :)