Skip to content

Commit

Permalink
Fix logging of DEBUG and TRACE messages
Browse files Browse the repository at this point in the history
  • Loading branch information
sean-gilliam committed Mar 12, 2024
1 parent 47049c4 commit 6305d12
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
20 changes: 16 additions & 4 deletions code/clogger.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,20 @@ void CLogger::Initialize()
{
if (spdlog::get("rs") == nullptr)
{
auto level = spdlog::level::trace;
spdlog::set_level(level);

auto console_sink = std::make_shared<spdlog::sinks::stdout_color_sink_mt>();
console_sink->set_level(spdlog::level::info);
console_sink->set_level(level);
console_sink->set_pattern("[%^%l%$] %v");

auto file_sink = std::make_shared<spdlog::sinks::basic_file_sink_mt>(RS_LOG_FILE, true);
file_sink->set_level(spdlog::level::info);
file_sink->set_level(level);

std::vector<spdlog::sink_ptr> sinks{ console_sink, file_sink };
auto logger = std::make_shared<spdlog::logger>("rs", sinks.begin(), sinks.end());
logger->set_level(spdlog::level::info);
logger->flush_on(spdlog::level::info);
logger->set_level(level);
logger->flush_on(level);

spdlog::register_logger(logger);
}
Expand All @@ -41,3 +44,12 @@ void CLogger::Shutdown()
{
spdlog::shutdown();
}

void CLogger::SetLevel(spdlog::level::level_enum level)
{
if (spdlog::get("rs") != nullptr)
{
spdlog::get("rs")->set_level(level);
spdlog::get("rs")->flush_on(level);
}
}
4 changes: 4 additions & 0 deletions code/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@
#include "comm.h"
#include "interp.h"
#include "db.h"
#include "./include/spdlog/spdlog.h"

int main(int argc, char **argv)
{
struct timeval now_time;
int port = 0;
int control;

RS.Logger.SetLevel(spdlog::level::info);

/*
* Memory debugging if needed.
*/
Expand Down Expand Up @@ -51,6 +54,7 @@ int main(int argc, char **argv)
}
else if ((port = atoi(argv[1])) == 666)
{
RS.Logger.SetLevel(spdlog::level::debug);
bDebug = true;
}
else if (port <= 1024)
Expand Down
4 changes: 2 additions & 2 deletions code/recycle.c
Original file line number Diff line number Diff line change
Expand Up @@ -700,8 +700,8 @@ CHAR_DATA *new_char(void)
{
ch = new CHAR_DATA;

if (bDebug)
RS.Logger.Debug("Char free is null. . . . . !");
// if (bDebug)
// RS.Logger.Debug("Char free is null. . . . . !");
}
else
{
Expand Down
6 changes: 6 additions & 0 deletions code/stdlibs/clogger.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
log.Shutdown();
*/

#ifdef SPDLOG_ACTIVE_LEVEL
#undef SPDLOG_ACTIVE_LEVEL
#define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_TRACE
#endif

class CLogger
{
public:
Expand All @@ -23,6 +28,7 @@ class CLogger

void Initialize();
void Shutdown();
void SetLevel(spdlog::level::level_enum level);

template <typename... Args>
void Bug(std::string_view fmt, Args &&...args)
Expand Down

0 comments on commit 6305d12

Please sign in to comment.