Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c52f1b5

Browse files
committedDec 3, 2024·
fix debug output
1 parent e5de41d commit c52f1b5

File tree

2 files changed

+29
-19
lines changed

2 files changed

+29
-19
lines changed
 

‎duckdb

Submodule duckdb updated 480 files

‎src/httpserver_extension.cpp

+28-18
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212
#include <thread>
1313
#include <memory>
1414
#include <cstdlib>
15+
16+
#ifndef _WIN32
1517
#include <syslog.h>
18+
#endif
1619

1720
#define CPPHTTPLIB_OPENSSL_SUPPORT
1821
#include "httplib.hpp"
@@ -383,34 +386,41 @@ void HttpServerStart(DatabaseInstance& db, string_t host, int32_t port, string_t
383386

384387
string host_str = host.GetString();
385388

389+
386390
#ifndef _WIN32
387-
// Debug and Syslog Events
388-
const char* use_syslog = std::getenv("DUCKDB_HTTPSERVER_SYSLOG");
389391
const char* debug_env = std::getenv("DUCKDB_HTTPSERVER_DEBUG");
390-
if (use_syslog != nullptr && std::string(use_syslog) == "1") {
391-
openlog("duckdb-httpserver", LOG_PID | LOG_NDELAY, LOG_LOCAL0);
392+
const char* use_syslog = std::getenv("DUCKDB_HTTPSERVER_SYSLOG");
393+
394+
if (debug_env != nullptr && std::string(debug_env) == "1") {
392395
global_state.server->set_logger([](const duckdb_httplib_openssl::Request& req, const duckdb_httplib_openssl::Response& res) {
393-
syslog(LOG_INFO, "%s %s - %d",
396+
time_t now_time = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
397+
char timestr[32];
398+
strftime(timestr, sizeof(timestr), "%Y-%m-%d %H:%M:%S", localtime(&now_time));
399+
// Use \r\n for consistent line endings
400+
fprintf(stdout, "[%s] %s %s - %d - from %s:%d\r\n",
401+
timestr,
394402
req.method.c_str(),
395403
req.path.c_str(),
396-
res.status);
397-
});
398-
std::atexit([]() {
399-
closelog();
404+
res.status,
405+
req.remote_addr.c_str(),
406+
req.remote_port);
407+
fflush(stdout);
400408
});
401-
} else if (debug_env != nullptr && std::string(debug_env) == "1") {
409+
} else if (use_syslog != nullptr && std::string(use_syslog) == "1") {
410+
openlog("duckdb-httpserver", LOG_PID | LOG_NDELAY, LOG_LOCAL0);
402411
global_state.server->set_logger([](const duckdb_httplib_openssl::Request& req, const duckdb_httplib_openssl::Response& res) {
403-
auto now = std::chrono::system_clock::now();
404-
auto now_time = std::chrono::system_clock::to_time_t(now);
405-
fprintf(stdout, "[%s] %s %s - %d\n",
406-
std::ctime(&now_time),
412+
syslog(LOG_INFO, "%s %s - %d - from %s:%d",
407413
req.method.c_str(),
408414
req.path.c_str(),
409-
res.status);
410-
fflush(stdout);
415+
res.status,
416+
req.remote_addr.c_str(),
417+
req.remote_port);
411418
});
412-
}
413-
#endif
419+
std::atexit([]() {
420+
closelog();
421+
});
422+
}
423+
#endif
414424

415425
const char* run_in_same_thread_env = std::getenv("DUCKDB_HTTPSERVER_FOREGROUND");
416426
bool run_in_same_thread = (run_in_same_thread_env != nullptr && std::string(run_in_same_thread_env) == "1");

0 commit comments

Comments
 (0)
Please sign in to comment.