aboutsummaryrefslogtreecommitdiff
path: root/src/server/shared/Logging/Log.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/shared/Logging/Log.h')
-rw-r--r--src/server/shared/Logging/Log.h54
1 files changed, 22 insertions, 32 deletions
diff --git a/src/server/shared/Logging/Log.h b/src/server/shared/Logging/Log.h
index 5fa638e2f40..a118e6e8773 100644
--- a/src/server/shared/Logging/Log.h
+++ b/src/server/shared/Logging/Log.h
@@ -35,7 +35,6 @@ class Log
friend class ACE_Singleton<Log, ACE_Thread_Mutex>;
typedef std::unordered_map<std::string, Logger> LoggerMap;
- typedef std::unordered_map<std::string, Logger const*> CachedLoggerContainer;
private:
Log();
@@ -44,7 +43,7 @@ class Log
public:
void LoadFromConfig();
void Close();
- bool ShouldLog(std::string const& type, LogLevel level);
+ bool ShouldLog(std::string const& type, LogLevel level) const;
bool SetLogLevel(std::string const& name, char const* level, bool isLogger = true);
void outMessage(std::string const& f, LogLevel level, char const* str, ...) ATTR_PRINTF(4, 5);
@@ -57,9 +56,9 @@ class Log
private:
static std::string GetTimestampStr();
void vlog(std::string const& f, LogLevel level, char const* str, va_list argptr);
- void write(LogMessage* msg);
+ void write(LogMessage* msg) const;
- Logger const* GetLoggerByType(std::string const& type);
+ Logger const* GetLoggerByType(std::string const& type) const;
Appender* GetAppenderByName(std::string const& name);
uint8 NextAppenderId();
void CreateAppenderFromConfig(std::string const& name);
@@ -69,7 +68,6 @@ class Log
AppenderMap appenders;
LoggerMap loggers;
- CachedLoggerContainer cachedLoggers;
uint8 AppenderId;
std::string m_logsDir;
@@ -78,37 +76,29 @@ class Log
LogWorker* worker;
};
-inline Logger const* Log::GetLoggerByType(std::string const& originalType)
+inline Logger const* Log::GetLoggerByType(std::string const& type) const
{
- // Check if already cached
- CachedLoggerContainer::const_iterator itCached = cachedLoggers.find(originalType);
- if (itCached != cachedLoggers.end())
- return itCached->second;
-
- Logger const* logger = NULL;
- std::string type(originalType);
-
- do
- {
- // Search for the logger "type.subtype"
- LoggerMap::const_iterator it = loggers.find(type);
- if (it == loggers.end())
- {
- // Search for the logger "type", if our logger contains '.', otherwise search for LOGGER_ROOT
- size_t found = type.find_last_of(".");
- type = found != std::string::npos ? type.substr(0, found) : LOGGER_ROOT;
- }
- else
- logger = &(it->second);
- }
- while (!logger);
-
- cachedLoggers[originalType] = logger;
- return logger;
+ LoggerMap::const_iterator it = loggers.find(type);
+ if (it != loggers.end())
+ return &(it->second);
+
+ if (type == LOGGER_ROOT)
+ return NULL;
+
+ std::string parentLogger = LOGGER_ROOT;
+ size_t found = type.find_last_of(".");
+ if (found != std::string::npos)
+ parentLogger = type.substr(0,found);
+
+ return GetLoggerByType(parentLogger);
}
-inline bool Log::ShouldLog(std::string const& type, LogLevel level)
+inline bool Log::ShouldLog(std::string const& type, LogLevel level) const
{
+ // TODO: Use cache to store "Type.sub1.sub2": "Type" equivalence, should
+ // Speed up in cases where requesting "Type.sub1.sub2" but only configured
+ // Logger "Type"
+
Logger const* logger = GetLoggerByType(type);
if (!logger)
return false;