@@ -366,28 +366,64 @@ void HttpServerStart(DatabaseInstance& db, string_t host, int32_t port, string_t
366
366
367
367
if (debug_env != nullptr && std::string (debug_env) == " 1" ) {
368
368
global_state.server ->set_logger ([](const duckdb_httplib_openssl::Request& req, const duckdb_httplib_openssl::Response& res) {
369
+ // Get current time with timezone offset
369
370
time_t now_time = std::chrono::system_clock::to_time_t (std::chrono::system_clock::now ());
371
+ struct tm * tm_info = localtime (&now_time);
370
372
char timestr[32 ];
371
- strftime (timestr, sizeof (timestr), " %Y-%m-%d %H:%M:%S" , localtime (&now_time));
372
- // Use \r\n for consistent line endings
373
- fprintf (stdout, " [%s] %s %s - %d - from %s:%d\r\n " ,
374
- timestr,
375
- req.method .c_str (),
376
- req.path .c_str (),
377
- res.status ,
378
- req.remote_addr .c_str (),
379
- req.remote_port );
373
+ char timezone[8 ];
374
+ strftime (timestr, sizeof (timestr), " %d/%b/%Y:%H:%M:%S" , tm_info);
375
+ strftime (timezone, sizeof (timezone), " %z" , tm_info);
376
+
377
+ size_t response_size = 0 ;
378
+ if (!res.body .empty ()) {
379
+ response_size = res.body .size ();
380
+ }
381
+ std::string user_agent = req.has_header (" User-Agent" ) ?
382
+ req.get_header_value (" User-Agent" ) : " -" ;
383
+ std::string referer = req.has_header (" Referer" ) ?
384
+ req.get_header_value (" Referer" ) : " -" ;
385
+ std::string forwarded_for = req.has_header (" X-Forwarded-For" ) ?
386
+ req.get_header_value (" X-Forwarded-For" ) : " -" ;
387
+ fprintf (stdout, " %s - - [%s %s] \" %s %s HTTP/%s\" %d %zu \" %s\" \" %s\" \" %s\"\r\n " ,
388
+ req.remote_addr .c_str (), // IP address
389
+ timestr, // Timestamp
390
+ timezone, // Timezone offset
391
+ req.method .c_str (), // HTTP method
392
+ req.path .c_str (), // Request path
393
+ req.version .c_str (), // HTTP version
394
+ res.status , // Status code
395
+ response_size, // Response size
396
+ referer.c_str (), // Referer
397
+ user_agent.c_str (), // User Agent
398
+ forwarded_for.c_str () // X-Forwarded-For
399
+ );
380
400
fflush (stdout);
381
401
});
382
402
} else if (use_syslog != nullptr && std::string (use_syslog) == " 1" ) {
383
403
openlog (" duckdb-httpserver" , LOG_PID | LOG_NDELAY, LOG_LOCAL0);
384
404
global_state.server ->set_logger ([](const duckdb_httplib_openssl::Request& req, const duckdb_httplib_openssl::Response& res) {
385
- syslog (LOG_INFO, " %s %s - %d - from %s:%d" ,
405
+ size_t response_size = 0 ;
406
+ if (!res.body .empty ()) {
407
+ response_size = res.body .size ();
408
+ }
409
+ std::string user_agent = req.has_header (" User-Agent" ) ?
410
+ req.get_header_value (" User-Agent" ) : " -" ;
411
+ std::string referer = req.has_header (" Referer" ) ?
412
+ req.get_header_value (" Referer" ) : " -" ;
413
+ std::string forwarded_for = req.has_header (" X-Forwarded-For" ) ?
414
+ req.get_header_value (" X-Forwarded-For" ) : " -" ;
415
+
416
+ syslog (LOG_INFO, " %s - - \" %s %s HTTP/%s\" %d %zu \" %s\" \" %s\" \" %s\" " ,
417
+ req.remote_addr .c_str (),
386
418
req.method .c_str (),
387
419
req.path .c_str (),
420
+ req.version .c_str (),
388
421
res.status ,
389
- req.remote_addr .c_str (),
390
- req.remote_port );
422
+ response_size,
423
+ referer.c_str (),
424
+ user_agent.c_str (),
425
+ forwarded_for.c_str ()
426
+ );
391
427
});
392
428
std::atexit ([]() {
393
429
closelog ();
0 commit comments