@@ -273,28 +273,64 @@ void HttpServerStart(DatabaseInstance& db, string_t host, int32_t port, string_t
273
273
274
274
if (debug_env != nullptr && std::string (debug_env) == " 1" ) {
275
275
global_state.server ->set_logger ([](const duckdb_httplib_openssl::Request& req, const duckdb_httplib_openssl::Response& res) {
276
+ // Get current time with timezone offset
276
277
time_t now_time = std::chrono::system_clock::to_time_t (std::chrono::system_clock::now ());
278
+ struct tm * tm_info = localtime (&now_time);
277
279
char timestr[32 ];
278
- strftime (timestr, sizeof (timestr), " %Y-%m-%d %H:%M:%S" , localtime (&now_time));
279
- // Use \r\n for consistent line endings
280
- fprintf (stdout, " [%s] %s %s - %d - from %s:%d\r\n " ,
281
- timestr,
282
- req.method .c_str (),
283
- req.path .c_str (),
284
- res.status ,
285
- req.remote_addr .c_str (),
286
- req.remote_port );
280
+ char timezone[8 ];
281
+ strftime (timestr, sizeof (timestr), " %d/%b/%Y:%H:%M:%S" , tm_info);
282
+ strftime (timezone, sizeof (timezone), " %z" , tm_info);
283
+
284
+ size_t response_size = 0 ;
285
+ if (!res.body .empty ()) {
286
+ response_size = res.body .size ();
287
+ }
288
+ std::string user_agent = req.has_header (" User-Agent" ) ?
289
+ req.get_header_value (" User-Agent" ) : " -" ;
290
+ std::string referer = req.has_header (" Referer" ) ?
291
+ req.get_header_value (" Referer" ) : " -" ;
292
+ std::string forwarded_for = req.has_header (" X-Forwarded-For" ) ?
293
+ req.get_header_value (" X-Forwarded-For" ) : " -" ;
294
+ fprintf (stdout, " %s - - [%s %s] \" %s %s HTTP/%s\" %d %zu \" %s\" \" %s\" \" %s\"\r\n " ,
295
+ req.remote_addr .c_str (), // IP address
296
+ timestr, // Timestamp
297
+ timezone, // Timezone offset
298
+ req.method .c_str (), // HTTP method
299
+ req.path .c_str (), // Request path
300
+ req.version .c_str (), // HTTP version
301
+ res.status , // Status code
302
+ response_size, // Response size
303
+ referer.c_str (), // Referer
304
+ user_agent.c_str (), // User Agent
305
+ forwarded_for.c_str () // X-Forwarded-For
306
+ );
287
307
fflush (stdout);
288
308
});
289
309
} else if (use_syslog != nullptr && std::string (use_syslog) == " 1" ) {
290
310
openlog (" duckdb-httpserver" , LOG_PID | LOG_NDELAY, LOG_LOCAL0);
291
311
global_state.server ->set_logger ([](const duckdb_httplib_openssl::Request& req, const duckdb_httplib_openssl::Response& res) {
292
- syslog (LOG_INFO, " %s %s - %d - from %s:%d" ,
312
+ size_t response_size = 0 ;
313
+ if (!res.body .empty ()) {
314
+ response_size = res.body .size ();
315
+ }
316
+ std::string user_agent = req.has_header (" User-Agent" ) ?
317
+ req.get_header_value (" User-Agent" ) : " -" ;
318
+ std::string referer = req.has_header (" Referer" ) ?
319
+ req.get_header_value (" Referer" ) : " -" ;
320
+ std::string forwarded_for = req.has_header (" X-Forwarded-For" ) ?
321
+ req.get_header_value (" X-Forwarded-For" ) : " -" ;
322
+
323
+ syslog (LOG_INFO, " %s - - \" %s %s HTTP/%s\" %d %zu \" %s\" \" %s\" \" %s\" " ,
324
+ req.remote_addr .c_str (),
293
325
req.method .c_str (),
294
326
req.path .c_str (),
327
+ req.version .c_str (),
295
328
res.status ,
296
- req.remote_addr .c_str (),
297
- req.remote_port );
329
+ response_size,
330
+ referer.c_str (),
331
+ user_agent.c_str (),
332
+ forwarded_for.c_str ()
333
+ );
298
334
});
299
335
std::atexit ([]() {
300
336
closelog ();
0 commit comments