diff --git a/src/handlers.cpp b/src/handlers.cpp index e415e38..181cd43 100644 --- a/src/handlers.cpp +++ b/src/handlers.cpp @@ -87,7 +87,7 @@ handleTorrents(http::request const& req) // get or post if (req.method() == verb::post) { - LOG_DEBUG << " post clen " << req.find(http::field::content_length)->value() << " bytes\n"; + PLOGD_(WebLog) << " post clen " << req.find(http::field::content_length)->value() << " bytes\n"; std::string dir(shth_->dir_store.string()); auto savePath = req.find("x-save-path"); if (savePath != req.end()) @@ -106,7 +106,7 @@ handleTorrents(http::request const& req) // get or post } const char* buf = req.body().data(); const int size = req.body().size(); - LOG_DEBUG << "post metainfo " << size << " bytes with save-path: '" << dir << "'\n"; + PLOGD_(WebLog) << "post metainfo " << size << " bytes with save-path: '" << dir << "'\n"; if (shth_->add_torrent(buf, size, dir)) { return make_resp_204(req); @@ -190,7 +190,7 @@ join(websocket_session* wss) ,{"id", qid} ,{"body", curr_stats} }); - LOG_DEBUG << "ws joinning " << sync_ver.load(); + PLOGD_(WebLog) << "ws joinning " << sync_ver.load(); wss->send(std::make_shared(json::serialize(jv))); } @@ -200,7 +200,7 @@ leave(websocket_session* wss) { std::lock_guard lock(mutex_); sessions_.erase(wss); - LOG_DEBUG << "ws leaved"; + PLOGD_(WebLog) << "ws leaved"; } // Broadcast a message to all websocket client sessions diff --git a/src/http_session.cpp b/src/http_session.cpp index d654f51..df850aa 100644 --- a/src/http_session.cpp +++ b/src/http_session.cpp @@ -118,7 +118,7 @@ fail(beast::error_code ec, char const* what) if(ec == net::error::operation_aborted) return; - std::cerr << what << ": " << ec.message() << "\n"; + PLOGI_(WebLog) << what << ": " << ec.message() << "\n"; } void diff --git a/src/http_websocket.cpp b/src/http_websocket.cpp index 1566925..5e6dbf3 100644 --- a/src/http_websocket.cpp +++ b/src/http_websocket.cpp @@ -31,7 +31,7 @@ websocket_session:: ~websocket_session() { closed = true; - LOG_DEBUG << "ws destroying"; + PLOGD_(WebLog) << "ws destroying"; // Remove this session from the list of active sessions caller_->leave(this); } @@ -143,12 +143,13 @@ on_write(beast::error_code ec, std::size_t) queue_.erase(queue_.begin()); // Send the next message if any - if(! queue_.empty()) + if(! queue_.empty()) { ws_.async_write( net::buffer(*queue_.front()), beast::bind_front_handler( &websocket_session::on_write, shared_from_this())); + } } void diff --git a/src/http_websocket.hpp b/src/http_websocket.hpp index 9308b92..353ace2 100644 --- a/src/http_websocket.hpp +++ b/src/http_websocket.hpp @@ -74,7 +74,7 @@ run(http::request> const& req) { uri_ = {req.target().data(), req.target().size()}; qid_ = url_decode(query_arg_one(uri_, "id=")); - LOG_DEBUG << "ws run: '" << uri_ << "' qid: " << qid_; + PLOGD_(WebLog) << "ws run: '" << uri_ << "' qid: " << qid_; // Set suggested timeout settings for the websocket ws_.set_option( websocket::stream_base::timeout::suggested( @@ -88,7 +88,7 @@ run(http::request> const& req) })); ws_.control_callback([](auto kind, auto payload){ - LOG_DEBUG << "ws ctl kind " << asValue(kind) << " payload " << payload; + PLOGD_(WebLog) << "ws ctl kind " << asValue(kind) << " payload " << payload; }); // Accept the websocket handshake diff --git a/src/listener.cpp b/src/listener.cpp index 84538dd..4541e74 100644 --- a/src/listener.cpp +++ b/src/listener.cpp @@ -1,8 +1,9 @@ -#include "listener.hpp" -#include "http_session.hpp" #include +#include "listener.hpp" +#include "http_session.hpp" +#include "log.hpp" namespace btd { @@ -71,7 +72,7 @@ fail(beast::error_code ec, char const* what) // Don't report on canceled operations if(ec == net::error::operation_aborted) return; - std::cerr << what << ": " << ec.message() << "\n"; + PLOGW_(WebLog) << what << ": " << ec.message() << "\n"; } // Handle a connection diff --git a/src/log.hpp b/src/log.hpp index f21cc2f..84adda6 100644 --- a/src/log.hpp +++ b/src/log.hpp @@ -4,5 +4,7 @@ enum // Define log instanceIds. Default is 0 and is omitted from this enum. { - AlertLog = 1 + MainLog = 0, // default + AlertLog = 1, + WebLog = 2 }; diff --git a/src/main.cpp b/src/main.cpp index 20d904e..681f846 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -21,8 +21,17 @@ int main(int argc, char* argv[]) { const std::string logMain(getLogsDir()+"/kedge-main.log"); const std::string logAlert(getLogsDir()+"/kedge-alert.log"); - plog::init(plog::debug, logMain.c_str(), 1024*1024*32, 2); // Initialize the default logger instance. - plog::init(plog::debug, logAlert.c_str(), 1024*1024*64, 2); // Initialize the 2nd logger instance. + const std::string logWeb(getLogsDir()+"/kedge-web.log"); + plog::init(plog::debug, logMain.c_str(), 1024*1024*32, 2); + plog::init(plog::debug, logAlert.c_str(), 1024*1024*64, 2); + plog::init(plog::debug, logWeb.c_str(), 1024*1024*64, 2); + + LOG_DEBUG << "init log " << logMain; + LOG_DEBUG << "init log " << logAlert; + LOG_DEBUG << "init log " << logWeb; + + PLOGD_(AlertLog) << "log start"; + PLOGD_(WebLog) << "log start"; option opt; if (!opt.init_from(argc, argv)) { return EXIT_FAILURE; }