Skip to content

Commit

Permalink
No syslog for win32 builds
Browse files Browse the repository at this point in the history
  • Loading branch information
lmangani authored Dec 3, 2024
1 parent ee007cc commit e5de41d
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions src/httpserver_extension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,21 +383,11 @@ void HttpServerStart(DatabaseInstance& db, string_t host, int32_t port, string_t

string host_str = host.GetString();

const char* debug_env = std::getenv("DUCKDB_HTTPSERVER_DEBUG");
#ifndef _WIN32
// Debug and Syslog Events
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) {
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),
req.method.c_str(),
req.path.c_str(),
res.status);
fflush(stdout);
});
} else if (use_syslog != nullptr && std::string(use_syslog) == "1") {
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);
global_state.server->set_logger([](const duckdb_httplib_openssl::Request& req, const duckdb_httplib_openssl::Response& res) {
syslog(LOG_INFO, "%s %s - %d",
Expand All @@ -408,7 +398,19 @@ void HttpServerStart(DatabaseInstance& db, string_t host, int32_t port, string_t
std::atexit([]() {
closelog();
});
}
} else 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) {
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),
req.method.c_str(),
req.path.c_str(),
res.status);
fflush(stdout);
});
}
#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 e5de41d

Please sign in to comment.