Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added logging categories #25

Merged
merged 8 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@
[submodule "libs/json"]
path = libs/json
url = https://github.com/nlohmann/json.git
[submodule "libs/spdlog"]
path = libs/spdlog
url = https://github.com/gabime/spdlog.git
1 change: 1 addition & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 11 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@ include_directories(libs/json/include)
add_subdirectory(libs/yaml-cpp)
include_directories(libs/yaml-cpp/include)

# Include AMQP-CPP (RabbitMQ).
add_subdirectory(libs/AMQP-CPP)
include_directories(libs/AMQP-CPP/include)

# Include spdlog.
add_subdirectory(libs/spdlog)
include_directories(libs/spdlog/include)

# Include Prometheus metrics.
find_package(prometheus-cpp CONFIG REQUIRED)

set(ARDOS_WANT_DB_SERVER ON CACHE BOOL "If on, Ardos will be built with the Database Server component.")
if (ARDOS_WANT_DB_SERVER)
# Include MongoDB driver.
Expand All @@ -42,13 +53,6 @@ if (ARDOS_WANT_DB_SERVER)
add_definitions(-DARDOS_WANT_DB_SERVER)
endif ()

# Include AMQP-CPP (RabbitMQ).
add_subdirectory(libs/AMQP-CPP)
include_directories(libs/AMQP-CPP/include)

# Include Prometheus metrics.
find_package(prometheus-cpp CONFIG REQUIRED)

# Optimize windows build.
if (WIN32)
add_definitions(-DNOMINMAX -DWIN32_LEAN_AND_MEAN -D_CRT_SECURE_NO_WARNINGS)
Expand Down
10 changes: 7 additions & 3 deletions config.example.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Console output log level.
# Options are verbose, info, warn, error or none.
log-level: verbose
# Global console output log level.
# Options are debug, info, warn, error or none.
log-level: info

# DC (Distributed Class) file paths.
# These should be kept in-sync globally.
Expand Down Expand Up @@ -42,6 +42,10 @@ uberdogs:
# Web Panel configuration.
# Can be accessed via the Ardos Web panel for debugging.
web-panel:
# Components can have their own individual log level set.
# This will override the global log level set previously.
log-level: debug

name: Ardos # The cluster name to appear in the dashboard.
port: 7781 # Port the WS connection listens on.

Expand Down
1 change: 1 addition & 0 deletions libs/spdlog
Submodule spdlog added at a2b426
19 changes: 14 additions & 5 deletions src/clientagent/client_agent.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "client_agent.h"

#include <spdlog/sinks/stdout_color_sinks.h>

#include "../util/config.h"
#include "../util/globals.h"
#include "../util/logger.h"
Expand All @@ -10,12 +12,19 @@
namespace Ardos {

ClientAgent::ClientAgent() {
Logger::Info("Starting Client Agent component...");
spdlog::info("Starting Client Agent component...");

_listenHandle = g_loop->resource<uvw::tcp_handle>();

auto config = Config::Instance()->GetNode("client-agent");

// Log configuration.
spdlog::stdout_color_mt("ca");
if (auto logLevel = config["log-level"]) {
spdlog::get("ca")->set_level(
Logger::LevelFromString(logLevel.as<std::string>()));
}

// Listen configuration.
if (auto hostParam = config["host"]) {
_host = hostParam.as<std::string>();
Expand Down Expand Up @@ -54,9 +63,9 @@ ClientAgent::ClientAgent() {
DCClass *dcc =
g_dc_file->get_class_by_name(uberdog["class"].as<std::string>());
if (!dcc) {
Logger::Error(std::format(
"[CA] UberDOG: {} Distributed Class: {} does not exist!",
uberdog["id"].as<uint32_t>(), uberdog["class"].as<std::string>()));
spdlog::get("ca")->error(
"UberDOG: {} Distributed Class: {} does not exist!",
uberdog["id"].as<uint32_t>(), uberdog["class"].as<std::string>());
exit(1);
}

Expand Down Expand Up @@ -134,7 +143,7 @@ ClientAgent::ClientAgent() {
_listenHandle->bind(_host, _port);
_listenHandle->listen();

Logger::Info(std::format("[CA] Listening on {}:{}", _host, _port));
spdlog::get("ca")->info("Listening on {}:{}", _host, _port);
}

/**
Expand Down
Loading
Loading