Skip to content

Commit

Permalink
fix debug output
Browse files Browse the repository at this point in the history
  • Loading branch information
lmangani committed Dec 3, 2024
1 parent e5de41d commit c52f1b5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 19 deletions.
2 changes: 1 addition & 1 deletion duckdb
Submodule duckdb updated 480 files
46 changes: 28 additions & 18 deletions src/httpserver_extension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
#include <thread>
#include <memory>
#include <cstdlib>

#ifndef _WIN32
#include <syslog.h>
#endif

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

string host_str = host.GetString();


#ifndef _WIN32
// Debug and Syslog Events
const char* use_syslog = std::getenv("DUCKDB_HTTPSERVER_SYSLOG");
const char* debug_env = std::getenv("DUCKDB_HTTPSERVER_DEBUG");
if (use_syslog != nullptr && std::string(use_syslog) == "1") {
openlog("duckdb-httpserver", LOG_PID | LOG_NDELAY, LOG_LOCAL0);
const char* use_syslog = std::getenv("DUCKDB_HTTPSERVER_SYSLOG");

if (debug_env != nullptr && std::string(debug_env) == "1") {
global_state.server->set_logger([](const duckdb_httplib_openssl::Request& req, const duckdb_httplib_openssl::Response& res) {
syslog(LOG_INFO, "%s %s - %d",
time_t now_time = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
char timestr[32];
strftime(timestr, sizeof(timestr), "%Y-%m-%d %H:%M:%S", localtime(&now_time));
// Use \r\n for consistent line endings
fprintf(stdout, "[%s] %s %s - %d - from %s:%d\r\n",
timestr,
req.method.c_str(),
req.path.c_str(),
res.status);
});
std::atexit([]() {
closelog();
res.status,
req.remote_addr.c_str(),
req.remote_port);
fflush(stdout);
});
} else if (debug_env != nullptr && std::string(debug_env) == "1") {
} else if (use_syslog != nullptr && std::string(use_syslog) == "1") {
openlog("duckdb-httpserver", LOG_PID | LOG_NDELAY, LOG_LOCAL0);
global_state.server->set_logger([](const duckdb_httplib_openssl::Request& req, const duckdb_httplib_openssl::Response& res) {
auto now = std::chrono::system_clock::now();
auto now_time = std::chrono::system_clock::to_time_t(now);
fprintf(stdout, "[%s] %s %s - %d\n",
std::ctime(&now_time),
syslog(LOG_INFO, "%s %s - %d - from %s:%d",
req.method.c_str(),
req.path.c_str(),
res.status);
fflush(stdout);
res.status,
req.remote_addr.c_str(),
req.remote_port);
});
}
#endif
std::atexit([]() {
closelog();
});
}
#endif

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

0 comments on commit c52f1b5

Please sign in to comment.