-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
175 additions
and
63 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 |
---|---|---|
@@ -1,4 +1,3 @@ | ||
- examples of configuration (nginx, cron) | ||
- make cross compilation work again | ||
- consider removing ECB namespace | ||
- consider using 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
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,62 @@ | ||
#include "Log.hpp" | ||
|
||
#include "spdlog/sinks/basic_file_sink.h" | ||
#include "spdlog/sinks/stdout_color_sinks.h" | ||
|
||
namespace ECB | ||
{ | ||
// static members | ||
std::shared_ptr<spdlog::logger> Log::logger_ = nullptr; | ||
|
||
void Log::init(const std::string &logFile) | ||
{ | ||
std::vector<spdlog::sink_ptr> sinks; | ||
|
||
auto consoleLogger = std::make_shared<spdlog::sinks::stderr_color_sink_mt>(); | ||
// timestamp with ms, colored log level, message | ||
consoleLogger->set_pattern("[%Y-%m-%d %H:%M:%S.%e] [%^%l%$] %v"); | ||
sinks.push_back(consoleLogger); | ||
|
||
if (!logFile.empty()) | ||
{ | ||
constexpr bool TRUNCATE = true; | ||
try | ||
{ | ||
auto fileLogger = std::make_shared<spdlog::sinks::basic_file_sink_mt>(logFile, TRUNCATE); | ||
// timestamp with ms, log level, message | ||
fileLogger->set_pattern("[%Y-%m-%d %H:%M:%S.%e] [%l] %v"); | ||
sinks.push_back(fileLogger); | ||
} | ||
catch (const spdlog::spdlog_ex &ex) | ||
{ | ||
spdlog::error("Failed to create file logger: {}", ex.what()); | ||
} | ||
} | ||
|
||
logger_ = std::make_shared<spdlog::logger>("logger", sinks.begin(), sinks.end()); | ||
spdlog::register_logger(logger_); | ||
} | ||
|
||
void Log::setLevel(const std::string &level) | ||
{ | ||
constexpr auto DEFAULT_LEVEL = spdlog::level::info; | ||
spdlog::level::level_enum finalLevel = DEFAULT_LEVEL; | ||
|
||
if (level == "off") | ||
finalLevel = spdlog::level::off; | ||
else if (level == "error") | ||
finalLevel = spdlog::level::err; | ||
else if (level == "warning") | ||
finalLevel = spdlog::level::warn; | ||
else if (level == "info") | ||
finalLevel = spdlog::level::info; | ||
|
||
setLevel(finalLevel); | ||
} | ||
|
||
void Log::setLevel(spdlog::level::level_enum level) | ||
{ | ||
if (logger_ != nullptr) | ||
logger_->set_level(level); | ||
} | ||
} // namespace ECB |
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,46 @@ | ||
#pragma once | ||
|
||
#include "spdlog/spdlog.h" | ||
|
||
namespace ECB | ||
{ | ||
class Log | ||
{ | ||
public: | ||
Log() = delete; | ||
|
||
static void init(const std::string &logFile = ""); | ||
|
||
static void setLevel(const std::string &level); | ||
static void setLevel(spdlog::level::level_enum level); | ||
|
||
// convenient aliases | ||
template <typename... Args> | ||
static void info(const char *format, Args... args) | ||
{ | ||
log(spdlog::level::level_enum::info, format, args...); | ||
} | ||
|
||
template <typename... Args> | ||
static void warn(const char *format, Args... args) | ||
{ | ||
log(spdlog::level::level_enum::warn, format, args...); | ||
} | ||
|
||
template <typename... Args> | ||
static void error(const char *format, Args... args) | ||
{ | ||
log(spdlog::level::level_enum::err, format, args...); | ||
} | ||
|
||
private: | ||
template <typename... Args> | ||
static void log(spdlog::level::level_enum level, const char *format, Args... args) | ||
{ | ||
if (logger_ != nullptr) | ||
logger_->log(level, format, args...); | ||
} | ||
|
||
static std::shared_ptr<spdlog::logger> logger_; | ||
}; | ||
} // namespace ECB |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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.