Use seperate spdlog loggers for components
Later on base/ might have a function to create loggers for it, but for now using the global logger for base/ components is fine.
This commit is contained in:
parent
919490a8c0
commit
315a3927f3
|
@ -3,7 +3,6 @@
|
|||
#include <boost/asio/read.hpp>
|
||||
#include <boost/asio/write.hpp>
|
||||
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
#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<float>(header.payloadSize) / 1024 / 1024), (static_cast<float>(MAX_PAYLOAD_SIZE) / 1024 / 1024));
|
||||
logger->error("WOAH! Message size {} MB larger than {}MB..", (static_cast<float>(header.payloadSize) / 1024 / 1024), (static_cast<float>(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());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
#pragma once
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
#include <base/types.hpp>
|
||||
#include <deque>
|
||||
#include <impl/asio_config.hpp>
|
||||
|
@ -29,11 +31,12 @@ namespace ls {
|
|||
// internal
|
||||
base::Awaitable<MessagePtr> ReadMessage();
|
||||
|
||||
|
||||
base::Awaitable<void> Run();
|
||||
|
||||
Stream stream;
|
||||
base::Ref<DirtySockServer> server;
|
||||
|
||||
base::Ref<spdlog::logger> logger = spdlog::get("ls_dsock_client");
|
||||
};
|
||||
|
||||
} // namespace ls
|
|
@ -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;
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include <impl/asio_config.hpp>
|
||||
#include <memory>
|
||||
#include <set>
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
namespace ls {
|
||||
struct DirtySockClient;
|
||||
|
@ -38,7 +39,7 @@ namespace ls {
|
|||
|
||||
std::set<base::Ref<DirtySockClient>> clientSet;
|
||||
|
||||
// i'm moving to spdlog fuck this
|
||||
base::Ref<spdlog::logger> logger = spdlog::get("ls_dsock_server");
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -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; });
|
||||
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
#include <impl/asio_config.hpp>
|
||||
#include <set>
|
||||
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
namespace ls {
|
||||
|
||||
struct DirtySockServer;
|
||||
|
@ -32,8 +34,7 @@ namespace ls {
|
|||
|
||||
Config config;
|
||||
|
||||
|
||||
|
||||
base::Ref<spdlog::logger> logger = spdlog::get("ls_server");
|
||||
};
|
||||
|
||||
} // namespace ls
|
10
src/main.cpp
10
src/main.cpp
|
@ -6,8 +6,10 @@
|
|||
#include <toml++/toml.hpp>
|
||||
|
||||
#include <spdlog/spdlog.h>
|
||||
#include <spdlog/cfg/env.h>
|
||||
|
||||
#include "Server.hpp"
|
||||
#include "spdlog/sinks/stdout_color_sinks.h"
|
||||
|
||||
asio::io_context ioc(1);
|
||||
base::Unique<ls::Server> server;
|
||||
|
@ -36,6 +38,14 @@ base::Awaitable<void> CoMain(const ls::Server::Config& config) {
|
|||
}
|
||||
|
||||
int main() {
|
||||
|
||||
// create spdlog loggers
|
||||
spdlog::create<spdlog::sinks::stdout_color_sink_mt>("ls_server");
|
||||
spdlog::create<spdlog::sinks::stdout_color_sink_mt>("ls_dsock_client");
|
||||
spdlog::create<spdlog::sinks::stdout_color_sink_mt>("ls_dsock_server");
|
||||
|
||||
spdlog::cfg::load_env_levels();
|
||||
|
||||
auto config = ls::Server::Config {};
|
||||
|
||||
try {
|
||||
|
|
|
@ -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)
|
Loading…
Reference in New Issue