summaryrefslogtreecommitdiff
path: root/src/common/Logging/Logger.cpp
diff options
context:
space:
mode:
authorKargatum <dowlandtop@yandex.com>2021-04-17 16:20:07 +0700
committerGitHub <noreply@github.com>2021-04-17 11:20:07 +0200
commit4af4cbd3d966a05c584f4b6c63f69517dad0677d (patch)
tree1c4329a0c64233aaa033ac3788c1e4ddc9422eb9 /src/common/Logging/Logger.cpp
parentb2861be1cd623182fd9e900c9ccfe8e063f28d8e (diff)
feat(Core/Logging): rework logging (#4692)
* feat(Core/Logging): rework logging * correct level for sql.sql * del unused config options * Correct build * correct after merge * whitespace 20:29:37 1. 'Player.cpp'. Replace (1) 20:29:37 2. 'ObjectMgr.cpp'. Replace (3) * 1 * correct logging * correct affter merge * 1 * 2 * LOG_LEVEL_WARN * #include "AppenderDB.h" * 3 * 4 * 5 * 1. 'WorldSocket.cpp'. Replace (1) * 6 * 1
Diffstat (limited to 'src/common/Logging/Logger.cpp')
-rw-r--r--src/common/Logging/Logger.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/common/Logging/Logger.cpp b/src/common/Logging/Logger.cpp
new file mode 100644
index 0000000000..c70431c5e7
--- /dev/null
+++ b/src/common/Logging/Logger.cpp
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, released under GNU AGPL v3 license: https://github.com/azerothcore/azerothcore-wotlk/blob/master/LICENSE-AGPL3
+ * Copyright (C) 2008-2021 TrinityCore <http://www.trinitycore.org/>
+ */
+
+#include "Logger.h"
+#include "Appender.h"
+#include "LogMessage.h"
+
+Logger::Logger(std::string const& _name, LogLevel _level): name(_name), level(_level) { }
+
+std::string const& Logger::getName() const
+{
+ return name;
+}
+
+LogLevel Logger::getLogLevel() const
+{
+ return level;
+}
+
+void Logger::addAppender(uint8 id, Appender* appender)
+{
+ appenders[id] = appender;
+}
+
+void Logger::delAppender(uint8 id)
+{
+ appenders.erase(id);
+}
+
+void Logger::setLogLevel(LogLevel _level)
+{
+ level = _level;
+}
+
+void Logger::write(LogMessage* message) const
+{
+ if (!level || level < message->level || message->text.empty())
+ {
+ //fprintf(stderr, "Logger::write: Logger %s, Level %u. Msg %s Level %u WRONG LEVEL MASK OR EMPTY MSG\n", getName().c_str(), getLogLevel(), message.text.c_str(), message.level);
+ return;
+ }
+
+ for (std::pair<uint8 const, Appender*> const& appender : appenders)
+ if (appender.second)
+ appender.second->write(message);
+}