Skip to content
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 include/godzilla/Logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#pragma once

#include "godzilla/String.h"
#include "spdlog/spdlog.h"
#include "spdlog/details/periodic_worker.h"
#include <filesystem>
Expand All @@ -15,6 +16,7 @@ namespace godzilla {
class Logger {
public:
Logger();
Logger(String name);
~Logger();

/// Set log file name
Expand Down Expand Up @@ -52,6 +54,7 @@ class Logger {
}

private:
std::string logger_name;
std::shared_ptr<spdlog::logger> spdlgr;
std::mutex flusher_mutex;
std::unique_ptr<spdlog::details::periodic_worker> periodic_flusher;
Expand Down
2 changes: 1 addition & 1 deletion src/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ App::App(mpi::Communicator comm, Registry & registry, String name) :
name(name),
mpi_comm(comm),
registry(registry),
logger(Qtr<Logger>::alloc()),
logger(Qtr<Logger>::alloc(name)),
verbosity_level(1),
cout_buf_(nullptr),
cerr_buf_(nullptr),
Expand Down
16 changes: 11 additions & 5 deletions src/Logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,29 @@

namespace godzilla {

Logger::Logger()
Logger::Logger() : logger_name("file_logger")
{
CALL_STACK_MSG();
this->spdlgr = spdlog::null_logger_mt("file_logger");
this->spdlgr = spdlog::null_logger_mt(this->logger_name);
}

Logger::Logger(String name) : logger_name(fmt::format("file_logger:{}", name))
{
CALL_STACK_MSG();
this->spdlgr = spdlog::null_logger_mt(logger_name);
}

Logger::~Logger()
{
spdlog::drop("file_logger");
spdlog::drop(this->logger_name);
}

void
Logger::set_log_file_name(fs::path file_name)
{
CALL_STACK_MSG();
spdlog::drop("file_logger");
this->spdlgr = spdlog::basic_logger_mt("file_logger", file_name, true);
spdlog::drop(this->logger_name);
this->spdlgr = spdlog::basic_logger_mt(this->logger_name, file_name, true);
this->spdlgr->set_pattern("[%Y %b %d %H:%M:%S.%e] [%l] %v");
}

Expand Down
Loading