-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added logging functionality (spdlog)
spdlog was added as a submodule All previous logging statements replaced with new logger .github/workflows/ci.yml was updated to initialise submodules recursively
- Loading branch information
1 parent
f5bb448
commit f036e9d
Showing
27 changed files
with
257 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "submodules/spdlog"] | ||
path = submodules/spdlog | ||
url = https://github.com/gabime/spdlog.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../submodules/spdlog/include/spdlog |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#include "MessageBase.h" | ||
|
||
#include "spdlog/spdlog.h" | ||
|
||
void MessageBase::log_init(const std::string& classname, | ||
const spdlog::level::level_enum& level) { | ||
// Initialise sink list | ||
spdlog::sinks_init_list s_list = {c_sink, f_sink}; | ||
|
||
// Use the sink list to create multi sink logger | ||
logger = | ||
std::make_shared<spdlog::logger>(classname, s_list.begin(), s_list.end()); | ||
log_level = level; | ||
set_log_level(level); | ||
logger->flush_on(level); | ||
spdlog::register_logger(logger); | ||
info(classname + " logger initialised!"); | ||
} | ||
|
||
void MessageBase::set_log_level(const spdlog::level::level_enum& level) { | ||
log_level = level; | ||
logger->set_level(level); | ||
logger->flush_on(level); | ||
} | ||
void MessageBase::debug(const std::string& message) { logger->debug(message); } | ||
void MessageBase::info(const std::string& message) { logger->info(message); } | ||
void MessageBase::warning(const std::string& message) { logger->warn(message); } | ||
void MessageBase::error(const std::string& message) { logger->error(message); } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#ifndef PRMON_MESSAGEBASE_H | ||
#define PRMON_MESSAGEBASE_H 1 | ||
|
||
#include "spdlog/sinks/basic_file_sink.h" | ||
#include "spdlog/sinks/stdout_color_sinks.h" | ||
#include "spdlog/spdlog.h" | ||
|
||
// Global sinks | ||
|
||
static const std::shared_ptr<spdlog::sinks::stdout_color_sink_st> c_sink{ | ||
std::make_shared<spdlog::sinks::stdout_color_sink_st>()}; | ||
static const std::shared_ptr<spdlog::sinks::basic_file_sink_st> f_sink{ | ||
std::make_shared<spdlog::sinks::basic_file_sink_st>("prmon.log", true)}; | ||
|
||
class MessageBase { | ||
std::shared_ptr<spdlog::logger> logger; | ||
|
||
protected: | ||
spdlog::level::level_enum log_level; | ||
void log_init(const std::string& classname, | ||
const spdlog::level::level_enum& level = spdlog::level::warn); | ||
|
||
public: | ||
void set_log_level(const spdlog::level::level_enum& level); | ||
void debug(const std::string& message); | ||
void info(const std::string& message); | ||
void warning(const std::string& message); | ||
void error(const std::string& message); | ||
}; | ||
|
||
#endif // PRMON_MESSAGEBASE_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#include "spdlog/sinks/basic_file_sink.h" | ||
#include "spdlog/sinks/stdout_color_sinks.h" | ||
#include "spdlog/spdlog.h" | ||
|
||
int main() { | ||
auto sink = std::make_shared<spdlog::sinks::stdout_color_sink_st>(); | ||
auto fsink = | ||
std::make_shared<spdlog::sinks::basic_file_sink_mt>("sample.log", true); | ||
spdlog::sinks_init_list sink_list = {sink, fsink}; | ||
auto logger = std::make_shared<spdlog::logger>("benchmark", sink_list.begin(), | ||
sink_list.end()); | ||
logger->set_level(spdlog::level::warn); | ||
const int maxN = 1e6; | ||
for (int i = 0; i < maxN; ++i) { | ||
logger->warn("Hello, benchmarking currently"); | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.