| 293 | } |
| 294 | |
| 295 | void cbm_log_http_request(const char *component, const char *method, const char *path, int status, |
| 296 | int64_t duration_ms, size_t request_bytes, size_t response_bytes) { |
| 297 | char safe_path[CBM_SZ_1K]; |
| 298 | char status_buf[CBM_SZ_16]; |
| 299 | char duration_buf[CBM_SZ_32]; |
| 300 | char request_buf[CBM_SZ_32]; |
| 301 | char response_buf[CBM_SZ_32]; |
| 302 | copy_path_without_query(path, safe_path, sizeof(safe_path)); |
| 303 | snprintf(status_buf, sizeof(status_buf), "%d", status); |
| 304 | snprintf(duration_buf, sizeof(duration_buf), "%" PRId64, duration_ms); |
| 305 | snprintf(request_buf, sizeof(request_buf), "%zu", request_bytes); |
| 306 | snprintf(response_buf, sizeof(response_buf), "%zu", response_bytes); |
| 307 | |
| 308 | CBMLogLevel level = CBM_LOG_INFO; |
| 309 | if (status >= 500) { |
| 310 | level = CBM_LOG_ERROR; |
| 311 | } else if (status >= 400) { |
| 312 | level = CBM_LOG_WARN; |
| 313 | } |
| 314 | |
| 315 | cbm_log(level, "http.request", "component", component ? component : "", "method", |
| 316 | method ? method : "", "path", safe_path, "status", status_buf, "duration_ms", |
| 317 | duration_buf, "request_bytes", request_buf, "response_bytes", response_buf, NULL); |
| 318 | } |
no test coverage detected