-
-
Notifications
You must be signed in to change notification settings - Fork 614
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
16 changed files
with
173 additions
and
88 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,6 @@ | |
#pragma once | ||
|
||
#include <iostream> | ||
#include "lib/logging/logger.hpp" | ||
|
||
class SoftSingleton { | ||
public: | ||
|
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,61 @@ | ||
/** | ||
* Canary - A free and open-source MMORPG server emulator | ||
* Copyright (©) 2019-2024 OpenTibiaBR <[email protected]> | ||
* Repository: https://github.com/opentibiabr/canary | ||
* License: https://github.com/opentibiabr/canary/blob/main/LICENSE | ||
* Contributors: https://github.com/opentibiabr/canary/graphs/contributors | ||
* Website: https://docs.opentibiabr.com/ | ||
*/ | ||
|
||
#include <spdlog/spdlog.h> | ||
#include "lib/di/container.hpp" | ||
|
||
LogWithSpdLog::LogWithSpdLog() { | ||
setLevel("info"); | ||
spdlog::set_pattern("[%Y-%d-%m %H:%M:%S.%e] [%^%l%$] %v "); | ||
|
||
#ifdef DEBUG_LOG | ||
spdlog::set_pattern("[%Y-%d-%m %H:%M:%S.%e] [thread %t] [%^%l%$] %v "); | ||
#endif | ||
} | ||
|
||
Logger &LogWithSpdLog::getInstance() { | ||
return inject<Logger>(); | ||
} | ||
|
||
void LogWithSpdLog::setLevel(const std::string &name) const { | ||
debug("Setting log level to: {}.", name); | ||
const auto level = spdlog::level::from_str(name); | ||
spdlog::set_level(level); | ||
} | ||
|
||
std::string LogWithSpdLog::getLevel() const { | ||
const auto level = spdlog::level::to_string_view(spdlog::get_level()); | ||
return std::string { level.begin(), level.end() }; | ||
} | ||
|
||
void LogWithSpdLog::info(const std::string &msg) const { | ||
SPDLOG_INFO(msg); | ||
} | ||
|
||
void LogWithSpdLog::warn(const std::string &msg) const { | ||
SPDLOG_WARN(msg); | ||
} | ||
|
||
void LogWithSpdLog::error(const std::string &msg) const { | ||
SPDLOG_WARN(msg); | ||
} | ||
|
||
void LogWithSpdLog::critical(const std::string &msg) const { | ||
SPDLOG_WARN(msg); | ||
} | ||
|
||
#if defined(DEBUG_LOG) | ||
void LogWithSpdLog::debug(const std::string &msg) const { | ||
SPDLOG_DEBUG(msg); | ||
} | ||
|
||
void LogWithSpdLog::trace(const std::string &msg) const { | ||
SPDLOG_TRACE(msg); | ||
} | ||
#endif |
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,53 @@ | ||
/** | ||
* Canary - A free and open-source MMORPG server emulator | ||
* Copyright (©) 2019-2024 OpenTibiaBR <[email protected]> | ||
* Repository: https://github.com/opentibiabr/canary | ||
* License: https://github.com/opentibiabr/canary/blob/main/LICENSE | ||
* Contributors: https://github.com/opentibiabr/canary/graphs/contributors | ||
* Website: https://docs.opentibiabr.com/ | ||
*/ | ||
#pragma once | ||
|
||
#include "logger.hpp" | ||
|
||
class LogWithSpdLog final : public Logger { | ||
public: | ||
LogWithSpdLog(); | ||
~LogWithSpdLog() override = default; | ||
|
||
static Logger &getInstance(); | ||
|
||
void setLevel(const std::string &name) const override; | ||
std::string getLevel() const override; | ||
|
||
void info(const std::string &msg) const override; | ||
void warn(const std::string &msg) const override; | ||
void error(const std::string &msg) const override; | ||
void critical(const std::string &msg) const override; | ||
|
||
#if defined(DEBUG_LOG) | ||
void debug(const std::string &msg) const override; | ||
void trace(const std::string &msg) const override; | ||
|
||
template <typename... Args> | ||
void debug(const fmt::format_string<Args...> &fmt, Args &&... args) const { | ||
debug(fmt::format(fmt, std::forward<Args>(args)...)); | ||
} | ||
|
||
template <typename... Args> | ||
void trace(const fmt::format_string<Args...> &fmt, Args &&... args) const { | ||
trace(fmt::format(fmt, std::forward<Args>(args)...)); | ||
} | ||
#else | ||
void debug(const std::string &) const override { } | ||
void trace(const std::string &) const override { } | ||
|
||
template <typename... Args> | ||
void debug(const fmt::format_string<Args...> &, Args &&...) const { } | ||
|
||
template <typename... Args> | ||
void trace(const fmt::format_string<Args...> &, Args &&...) const { } | ||
#endif | ||
}; | ||
|
||
constexpr auto g_logger = LogWithSpdLog::getInstance; |
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.