|
9 | 9 | #include "duckdb/common/exception/http_exception.hpp"
|
10 | 10 | #include "duckdb/common/allocator.hpp"
|
11 | 11 | #include <chrono>
|
| 12 | +#include <thread> |
| 13 | +#include <memory> |
| 14 | +#include <cstdlib> |
| 15 | + |
| 16 | +#ifndef _WIN32 |
| 17 | +#include <syslog.h> |
| 18 | +#endif |
12 | 19 |
|
13 | 20 | #define CPPHTTPLIB_OPENSSL_SUPPORT
|
14 | 21 | #include "httplib.hpp"
|
15 |
| - |
16 |
| -// Include yyjson for JSON handling |
17 | 22 | #include "yyjson.hpp"
|
18 | 23 |
|
19 |
| -#include <thread> |
20 |
| -#include <memory> |
21 |
| -#include <cstdlib> |
22 | 24 | #include "play.h"
|
23 | 25 |
|
24 | 26 | using namespace duckdb_yyjson; // NOLINT
|
@@ -384,6 +386,42 @@ void HttpServerStart(DatabaseInstance& db, string_t host, int32_t port, string_t
|
384 | 386 |
|
385 | 387 | string host_str = host.GetString();
|
386 | 388 |
|
| 389 | + |
| 390 | +#ifndef _WIN32 |
| 391 | + const char* debug_env = std::getenv("DUCKDB_HTTPSERVER_DEBUG"); |
| 392 | + const char* use_syslog = std::getenv("DUCKDB_HTTPSERVER_SYSLOG"); |
| 393 | + |
| 394 | + if (debug_env != nullptr && std::string(debug_env) == "1") { |
| 395 | + global_state.server->set_logger([](const duckdb_httplib_openssl::Request& req, const duckdb_httplib_openssl::Response& res) { |
| 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, |
| 402 | + req.method.c_str(), |
| 403 | + req.path.c_str(), |
| 404 | + res.status, |
| 405 | + req.remote_addr.c_str(), |
| 406 | + req.remote_port); |
| 407 | + fflush(stdout); |
| 408 | + }); |
| 409 | + } else if (use_syslog != nullptr && std::string(use_syslog) == "1") { |
| 410 | + openlog("duckdb-httpserver", LOG_PID | LOG_NDELAY, LOG_LOCAL0); |
| 411 | + global_state.server->set_logger([](const duckdb_httplib_openssl::Request& req, const duckdb_httplib_openssl::Response& res) { |
| 412 | + syslog(LOG_INFO, "%s %s - %d - from %s:%d", |
| 413 | + req.method.c_str(), |
| 414 | + req.path.c_str(), |
| 415 | + res.status, |
| 416 | + req.remote_addr.c_str(), |
| 417 | + req.remote_port); |
| 418 | + }); |
| 419 | + std::atexit([]() { |
| 420 | + closelog(); |
| 421 | + }); |
| 422 | + } |
| 423 | +#endif |
| 424 | + |
387 | 425 | const char* run_in_same_thread_env = std::getenv("DUCKDB_HTTPSERVER_FOREGROUND");
|
388 | 426 | bool run_in_same_thread = (run_in_same_thread_env != nullptr && std::string(run_in_same_thread_env) == "1");
|
389 | 427 |
|
|
0 commit comments