Skip to content

Commit

Permalink
Revamp logging structure to clean up server starting
Browse files Browse the repository at this point in the history
  • Loading branch information
Segfaultd committed Jan 24, 2024
1 parent 03156d7 commit a8fc4e4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
1 change: 0 additions & 1 deletion code/framework/src/http/webserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ namespace Framework::HTTP {
void Webserver::RegisterRequest(const char *path, const RequestCallback &callback) {
if (strlen(path) > 0 && callback) {
_registeredRequestCallback.insert({path, callback});
Logging::GetLogger(FRAMEWORK_INNER_HTTP)->debug("[Webserver] Registered request callback for path: {}", path);
}
}

Expand Down
24 changes: 11 additions & 13 deletions code/framework/src/integrations/server/instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ namespace Framework::Integrations::Server {

// Initialize mod subsystems
PostInit();
Logging::GetLogger(FRAMEWORK_INNER_SERVER)->info("Mod subsystems initialized");

// Init the signals handlers if enabled
if (_opts.enableSignals) {
Expand All @@ -151,24 +150,23 @@ namespace Framework::Integrations::Server {
}

_alive = true;
Logging::GetLogger(FRAMEWORK_INNER_SERVER)->info("{} Server successfully started", _opts.modName);
Logging::GetLogger(FRAMEWORK_INNER_SERVER)->info("Name:\t{}", _opts.bindName);
Logging::GetLogger(FRAMEWORK_INNER_SERVER)->info("Host:\t{}", _opts.bindHost);
Logging::GetLogger(FRAMEWORK_INNER_SERVER)->info("Port:\t{}", _opts.bindPort);
Logging::GetLogger(FRAMEWORK_INNER_SERVER)->info("Max Players:\t{}", _opts.maxPlayers);
Logging::GetLogger(FRAMEWORK_INNER_SERVER)->flush();

// Load the scripting gamemode when everything is ready
Logging::GetLogger(FRAMEWORK_INNER_SERVER)->info("Loading scripting gamemode...");
Logging::GetLogger(FRAMEWORK_INNER_SERVER)->debug("Loading scripting gamemode...");
if(!_scriptingEngine->LoadGamemode()){
return ServerError::SERVER_SCRIPTING_INIT_FAILED;
Logging::GetLogger(FRAMEWORK_INNER_SERVER)->debug("Failed to load the scripting gamemode. Starting without gamemode.");
}

Logging::GetLogger(FRAMEWORK_INNER_SERVER)->info("{} Server successfully started", _opts.modName);
return ServerError::SERVER_NONE;
}

void Instance::InitEndpoints() {
_webServer->RegisterRequest("/networking/status", [this](struct mg_connection *c, void *ev_data, const Framework::HTTP::ResponseCallback &cb) {
_webServer->RegisterRequest("/", [this](struct mg_connection *c, void *ev_data, const Framework::HTTP::ResponseCallback &cb) {
(void)ev_data;
(void)c;
nlohmann::json root;
Expand All @@ -182,7 +180,7 @@ namespace Framework::Integrations::Server {
cb(200, root.dump(4));
});

Logging::GetLogger(FRAMEWORK_INNER_HTTP)->info("All core endpoints have been registered!");
Logging::GetLogger(FRAMEWORK_INNER_HTTP)->debug("All core endpoints have been registered!");
}

void Instance::InitModules() {
Expand All @@ -192,14 +190,14 @@ namespace Framework::Integrations::Server {
world->import <Integrations::Shared::Modules::Mod>();
}

Logging::GetLogger(FRAMEWORK_INNER_SERVER)->info("Core ecs modules have been imported!");
Logging::GetLogger(FRAMEWORK_INNER_SERVER)->debug("Core ecs modules have been imported!");
}

bool Instance::LoadConfigFromJSON() {
auto configHandle = cppfs::fs::open(_opts.modConfigFile);

if (!configHandle.exists()) {
Logging::GetLogger(FRAMEWORK_INNER_SERVER)->info("JSON config file is not present, skipping load...");
Logging::GetLogger(FRAMEWORK_INNER_SERVER)->debug("JSON config file is not present, skipping load...");
return true;
}

Expand Down Expand Up @@ -316,7 +314,7 @@ namespace Framework::Integrations::Server {

Framework::World::Modules::Base::SetupServerReceivers(net, _worldEngine.get());

Logging::GetLogger(FRAMEWORK_INNER_SERVER)->info("Game sync networking messages registered");
Logging::GetLogger(FRAMEWORK_INNER_SERVER)->debug("Game sync networking messages registered");
}

ServerError Instance::Shutdown() {
Expand Down Expand Up @@ -382,7 +380,7 @@ namespace Framework::Integrations::Server {
return;
}

Logging::GetLogger(FRAMEWORK_INNER_SERVER)->info("Received shutdown signal. In progress...");
Logging::GetLogger(FRAMEWORK_INNER_SERVER)->debug("Received shutdown signal. In progress...");

PreShutdown();
Shutdown();
Expand All @@ -395,10 +393,10 @@ namespace Framework::Integrations::Server {
Framework::Integrations::Scripting::Entity::Register(nodeSDK->GetIsolate(), nodeSDK->GetModule());
} break;
}
Logging::GetLogger(FRAMEWORK_INNER_SCRIPTING)->info("Native bindings are set up!");
Logging::GetLogger(FRAMEWORK_INNER_SCRIPTING)->debug("Native bindings are set up!");

// mod-specific builtins
ModuleRegister(sdk);
Logging::GetLogger(FRAMEWORK_INNER_SCRIPTING)->info("Mod bindings are set up!");
Logging::GetLogger(FRAMEWORK_INNER_SCRIPTING)->debug("Mod bindings are set up!");
}
} // namespace Framework::Integrations::Server
2 changes: 1 addition & 1 deletion code/framework/src/scripting/module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ namespace Framework::Scripting {
bool Module::LoadGamemode(){
cppfs::FileHandle dir = cppfs::fs::open("gamemode");
if (!dir.exists() || !dir.isDirectory()) {
Logging::GetLogger(FRAMEWORK_INNER_SCRIPTING)->debug("Failed to find the gamemode directory");
Logging::GetLogger(FRAMEWORK_INNER_SCRIPTING)->error("Failed to find the gamemode directory");
return false;
}

Expand Down

0 comments on commit a8fc4e4

Please sign in to comment.