diff --git a/src/DirtySockClient.cpp b/src/DirtySockClient.cpp index 701fc56..553bff8 100644 --- a/src/DirtySockClient.cpp +++ b/src/DirtySockClient.cpp @@ -3,7 +3,6 @@ #include #include -#include #include "DirtySockServer.hpp" @@ -32,7 +31,7 @@ namespace ls { // Sanity check. I don't expect game payloa if(header.payloadSize > MAX_PAYLOAD_SIZE) { - spdlog::error("WOAH! Message size {} MB larger than {}MB..", (static_cast(header.payloadSize) / 1024 / 1024), (static_cast(MAX_PAYLOAD_SIZE) / 1024 / 1024)); + logger->error("WOAH! Message size {} MB larger than {}MB..", (static_cast(header.payloadSize) / 1024 / 1024), (static_cast(MAX_PAYLOAD_SIZE) / 1024 / 1024)); co_return nullptr; } @@ -50,7 +49,7 @@ namespace ls { co_return MessageFactory::CreateAndParseMessage(header, propertyBuffer); } catch(bsys::system_error& ec) { if(ec.code() != asio::error::operation_aborted) - spdlog::error("Error in DirtySockClient::WriteMessage(): {}", ec.what()); + logger->error("Error in DirtySockClient::WriteMessage(): {}", ec.what()); co_return nullptr; } } @@ -64,7 +63,7 @@ namespace ls { co_await asio::async_write(stream, asio::buffer(buf), asio::deferred); } catch(bsys::system_error& ec) { if(ec.code() != asio::error::operation_aborted) - spdlog::error("Error in DirtySockClient::WriteMessage(): {}", ec.what()); + logger->error("Error in DirtySockClient::WriteMessage(): {}", ec.what()); } } @@ -78,14 +77,14 @@ namespace ls { co_await message->Process(shared_from_this()); } else { // This will occur if parsing fails or etc. - spdlog::error("Error parsing message, closing connection"); + logger->error("Error parsing message, closing connection"); Close(); co_return; } } } catch(bsys::system_error& ec) { if(ec.code() != asio::error::operation_aborted) - spdlog::error("Error in DirtySockClient::Run(): {}", ec.what()); + logger->error("Error in DirtySockClient::Run(): {}", ec.what()); } } diff --git a/src/DirtySockClient.hpp b/src/DirtySockClient.hpp index d2d2187..90a8f15 100644 --- a/src/DirtySockClient.hpp +++ b/src/DirtySockClient.hpp @@ -1,4 +1,6 @@ #pragma once +#include + #include #include #include @@ -29,11 +31,12 @@ namespace ls { // internal base::Awaitable ReadMessage(); - base::Awaitable Run(); Stream stream; base::Ref server; + + base::Ref logger = spdlog::get("ls_dsock_client"); }; } // namespace ls \ No newline at end of file diff --git a/src/DirtySockServer.cpp b/src/DirtySockServer.cpp index 1430633..5b48afc 100644 --- a/src/DirtySockServer.cpp +++ b/src/DirtySockServer.cpp @@ -11,7 +11,7 @@ namespace ls { } void DirtySockServer::Start(const Protocol::endpoint& ep) { - asio::co_spawn(exec, Listener(ep), base::DefCoroCompletion("EaServer listener")); + asio::co_spawn(exec, Listener(ep), base::DefCoroCompletion("DirtySockServer listener")); } bool DirtySockServer::Listening() const { @@ -34,7 +34,7 @@ namespace ls { acceptor.bind(endpoint); acceptor.listen(asio::socket_base::max_listen_connections); - spdlog::info("DirtySockServer listening on {}:{}", endpoint.address().to_string(), endpoint.port()); + logger->info("DirtySockServer listening on {}:{}", endpoint.address().to_string(), endpoint.port()); while(true) { auto socket = co_await acceptor.async_accept(asio::deferred); @@ -44,7 +44,7 @@ namespace ls { } } catch(bsys::system_error& ec) { if(ec.code() != asio::error::operation_aborted) - spdlog::error("Error in DirtySockServer::Listener(): {}", ec.what()); + logger->error("Error in DirtySockServer::Listener(): {}", ec.what()); } co_return; diff --git a/src/DirtySockServer.hpp b/src/DirtySockServer.hpp index 1d08184..1858e88 100644 --- a/src/DirtySockServer.hpp +++ b/src/DirtySockServer.hpp @@ -4,6 +4,7 @@ #include #include #include +#include namespace ls { struct DirtySockClient; @@ -38,7 +39,7 @@ namespace ls { std::set> clientSet; - // i'm moving to spdlog fuck this + base::Ref logger = spdlog::get("ls_dsock_server"); }; diff --git a/src/Server.cpp b/src/Server.cpp index 823d469..54717ff 100644 --- a/src/Server.cpp +++ b/src/Server.cpp @@ -22,12 +22,14 @@ namespace ls { if(!lobbyServer->Listening()) { // uh oh worm.. - spdlog::error("for some reason lobby server isnt listening.."); + logger->error("for some reason lobby server isnt listening.."); co_return; } // TODO: http server? there's apparently some stuff we can have that uses it + logger->info("SSX3LobbyServer started successfully!"); + // wait to stop co_await stopCv.Wait([&]() { return stopping; }); diff --git a/src/Server.hpp b/src/Server.hpp index 611041d..0d43a22 100644 --- a/src/Server.hpp +++ b/src/Server.hpp @@ -4,6 +4,8 @@ #include #include +#include + namespace ls { struct DirtySockServer; @@ -32,8 +34,7 @@ namespace ls { Config config; - - + base::Ref logger = spdlog::get("ls_server"); }; } // namespace ls \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index e6a1b95..8cffaa8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6,8 +6,10 @@ #include #include +#include #include "Server.hpp" +#include "spdlog/sinks/stdout_color_sinks.h" asio::io_context ioc(1); base::Unique server; @@ -36,6 +38,14 @@ base::Awaitable CoMain(const ls::Server::Config& config) { } int main() { + + // create spdlog loggers + spdlog::create("ls_server"); + spdlog::create("ls_dsock_client"); + spdlog::create("ls_dsock_server"); + + spdlog::cfg::load_env_levels(); + auto config = ls::Server::Config {}; try { diff --git a/third_party/CMakeLists.txt b/third_party/CMakeLists.txt index 0e04357..f3b4534 100644 --- a/third_party/CMakeLists.txt +++ b/third_party/CMakeLists.txt @@ -1,5 +1,5 @@ add_subdirectory(boost) add_subdirectory(tomlplusplus) -#set(SPDLOG_USE_STD_FORMAT ON) +set(SPDLOG_USE_STD_FORMAT ON) add_subdirectory(spdlog) \ No newline at end of file