DIFF 360
Logging By SkyFire on 11th August 2018 10:01:28 PM
  1.  src/server/game/AI/SmartScripts/SmartScriptMgr.cpp |   2 +-
  2.  .../game/Entities/AreaTrigger/AreaTrigger.cpp      |   2 +-
  3.  src/server/shared/Logging/Appender.h               |   2 +-
  4.  src/server/shared/Logging/AppenderConsole.cpp      |  58 +++----
  5.  src/server/shared/Logging/AppenderFile.cpp         |   6 +-
  6.  src/server/shared/Logging/Log.cpp                  | 180 +++++++--------------
  7.  src/server/shared/Logging/Log.h                    |  55 ++++---
  8.  src/server/shared/Logging/Logger.cpp               |  14 +-
  9.  src/server/shared/Logging/Logger.h                 |   3 +-
  10.  9 files changed, 130 insertions(+), 192 deletions(-)
  11.  
  12. diff --git a/src/server/game/AI/SmartScripts/SmartScriptMgr.cpp b/src/server/game/AI/SmartScripts/SmartScriptMgr.cpp
  13. index 725d637740..8f6b840847 100644
  14. --- a/src/server/game/AI/SmartScripts/SmartScriptMgr.cpp
  15. +++ b/src/server/game/AI/SmartScripts/SmartScriptMgr.cpp
  16. @@ -443,7 +443,7 @@ bool SmartAIMgr::IsEventValid(SmartScriptHolder& e)
  17.              case SMART_EVENT_VICTIM_CASTING:
  18.                  if (e.event.targetCasting.spellId > 0 && !sSpellMgr->GetSpellInfo(e.event.targetCasting.spellId))
  19.                  {
  20. -                    sLog->outError("sql.sql", "SmartAIMgr: Entry %d SourceType %u Event %u Action %u uses non-existent Spell entry %u, skipped.", e.entryOrGuid, e.GetScriptType(), e.event_id, e.GetActionType(), e.event.spellHit.spell);
  21. +                    SF_LOG_ERROR("sql.sql", "SmartAIMgr: Entry %d SourceType %u Event %u Action %u uses non-existent Spell entry %u, skipped.", e.entryOrGuid, e.GetScriptType(), e.event_id, e.GetActionType(), e.event.spellHit.spell);
  22.                      return false;
  23.                  }
  24.  
  25. diff --git a/src/server/game/Entities/AreaTrigger/AreaTrigger.cpp b/src/server/game/Entities/AreaTrigger/AreaTrigger.cpp
  26. index 79ed5af70d..9250678045 100644
  27. --- a/src/server/game/Entities/AreaTrigger/AreaTrigger.cpp
  28. +++ b/src/server/game/Entities/AreaTrigger/AreaTrigger.cpp
  29. @@ -66,7 +66,7 @@ bool AreaTrigger::CreateAreaTrigger(uint32 guidlow, uint32 triggerEntry, Unit* c
  30.      Relocate(pos);
  31.      if (!IsPositionValid())
  32.      {
  33. -        sLog->outError("misc", "AreaTrigger (spell %u) not created. Invalid coordinates (X: %f Y: %f)", spell->Id, GetPositionX(), GetPositionY());
  34. +        SF_LOG_ERROR("sql.sql", "AreaTrigger (spell %u) not created. Invalid coordinates (X: %f Y: %f)", spell->Id, GetPositionX(), GetPositionY());
  35.          return false;
  36.      }
  37.  
  38. diff --git a/src/server/shared/Logging/Appender.h b/src/server/shared/Logging/Appender.h
  39. index ceb0fdf0c8..97c0d1fb75 100644
  40. --- a/src/server/shared/Logging/Appender.h
  41. +++ b/src/server/shared/Logging/Appender.h
  42. @@ -77,7 +77,7 @@ struct LogMessage
  43.      ///@ Returns size of the log message content in bytes
  44.      uint32 Size() const
  45.      {
  46. -        return prefix.size() + text.size();
  47. +        return static_cast<uint32>(prefix.size() + text.size());
  48.      }
  49.  };
  50.  
  51. diff --git a/src/server/shared/Logging/AppenderConsole.cpp b/src/server/shared/Logging/AppenderConsole.cpp
  52. index 28ec1b5ba1..03d04900bb 100644
  53. --- a/src/server/shared/Logging/AppenderConsole.cpp
  54. +++ b/src/server/shared/Logging/AppenderConsole.cpp
  55. @@ -23,8 +23,8 @@
  56.  
  57.  #include <sstream>
  58.  
  59. -AppenderConsole::AppenderConsole(uint8 id, std::string const& name, LogLevel level, AppenderFlags flags):
  60. -Appender(id, name, APPENDER_CONSOLE, level, flags), _colored(false)
  61. +AppenderConsole::AppenderConsole(uint8 id, std::string const& name, LogLevel level, AppenderFlags flags) :
  62. +    Appender(id, name, APPENDER_CONSOLE, level, flags), _colored(false)
  63.  {
  64.      for (uint8 i = 0; i < MaxLogLevels; ++i)
  65.          _colors[i] = ColorTypes(MaxColors);
  66. @@ -89,7 +89,7 @@ void AppenderConsole::SetColor(bool stdout_stream, ColorTypes color)
  67.  
  68.      HANDLE hConsole = GetStdHandle(stdout_stream ? STD_OUTPUT_HANDLE : STD_ERROR_HANDLE);
  69.      SetConsoleTextAttribute(hConsole, WinColorFG[color]);
  70. -    #else
  71. +#else
  72.      enum ANSITextAttr
  73.      {
  74.          TA_NORMAL                                = 0,
  75. @@ -113,7 +113,7 @@ void AppenderConsole::SetColor(bool stdout_stream, ColorTypes color)
  76.  
  77.      enum ANSIBgTextAttr
  78.      {
  79. -        BG_BLACK                                 = 40,
  80. +        BG_BLACK = 40,
  81.          BG_RED,
  82.          BG_GREEN,
  83.          BG_BROWN,
  84. @@ -142,48 +142,48 @@ void AppenderConsole::SetColor(bool stdout_stream, ColorTypes color)
  85.          FG_WHITE                                           // LWHITE
  86.      };
  87.  
  88. -    fprintf((stdout_stream? stdout : stderr), "\x1b[%d%sm", UnixColorFG[color], (color >= YELLOW && color < MaxColors ? ";1" : ""));
  89. -    #endif
  90. +    fprintf((stdout_stream ? stdout : stderr), "\x1b[%d%sm", UnixColorFG[color], (color >= YELLOW && color < MaxColors ? ";1" : ""));
  91. +#endif
  92.  }
  93.  
  94.  void AppenderConsole::ResetColor(bool stdout_stream)
  95.  {
  96. -    #if PLATFORM == PLATFORM_WINDOWS
  97. +#if PLATFORM == PLATFORM_WINDOWS
  98.      HANDLE hConsole = GetStdHandle(stdout_stream ? STD_OUTPUT_HANDLE : STD_ERROR_HANDLE);
  99.      SetConsoleTextAttribute(hConsole, FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED);
  100. -    #else
  101. +#else
  102.      fprintf((stdout_stream ? stdout : stderr), "\x1b[0m");
  103. -    #endif
  104. +#endif
  105.  }
  106.  
  107.  void AppenderConsole::_write(LogMessage const& message)
  108.  {
  109. -    bool stdout_stream = message.level == LOG_LEVEL_ERROR || message.level == LOG_LEVEL_FATAL;
  110. +    bool stdout_stream = !(message.level == LOG_LEVEL_ERROR || message.level == LOG_LEVEL_FATAL);
  111.  
  112.      if (_colored)
  113.      {
  114.          uint8 index;
  115.          switch (message.level)
  116.          {
  117. -            case LOG_LEVEL_TRACE:
  118. -               index = 5;
  119. -               break;
  120. -            case LOG_LEVEL_DEBUG:
  121. -               index = 4;
  122. -               break;
  123. -            case LOG_LEVEL_INFO:
  124. -               index = 3;
  125. -               break;
  126. -            case LOG_LEVEL_WARN:
  127. -               index = 2;
  128. -               break;
  129. -            case LOG_LEVEL_FATAL:
  130. -               index = 0;
  131. -               break;
  132. -            case LOG_LEVEL_ERROR: // No break on purpose
  133. -            default:
  134. -               index = 1;
  135. -               break;
  136. +        case LOG_LEVEL_TRACE:
  137. +            index = 5;
  138. +            break;
  139. +        case LOG_LEVEL_DEBUG:
  140. +            index = 4;
  141. +            break;
  142. +        case LOG_LEVEL_INFO:
  143. +            index = 3;
  144. +            break;
  145. +        case LOG_LEVEL_WARN:
  146. +            index = 2;
  147. +            break;
  148. +        case LOG_LEVEL_FATAL:
  149. +            index = 0;
  150. +            break;
  151. +        case LOG_LEVEL_ERROR: // No break on purpose
  152. +        default:
  153. +            index = 1;
  154. +            break;
  155.          }
  156.  
  157.          SetColor(stdout_stream, _colors[index]);
  158. diff --git a/src/server/shared/Logging/AppenderFile.cpp b/src/server/shared/Logging/AppenderFile.cpp
  159. index 6ff82cfbc5..08078c0557 100644
  160. --- a/src/server/shared/Logging/AppenderFile.cpp
  161. +++ b/src/server/shared/Logging/AppenderFile.cpp
  162. @@ -20,6 +20,10 @@
  163.  #include "AppenderFile.h"
  164.  #include "Common.h"
  165.  
  166. +#if PLATFORM == PLATFORM_WINDOWS
  167. +# include <Windows.h>
  168. +#endif
  169. +
  170.  AppenderFile::AppenderFile(uint8 id, std::string const& name, LogLevel level, const char* _filename, const char* _logDir, const char* _mode, AppenderFlags _flags, uint64 fileSize):
  171.      Appender(id, name, APPENDER_FILE, level, _flags),
  172.      logfile(NULL),
  173. @@ -30,7 +34,7 @@ AppenderFile::AppenderFile(uint8 id, std::string const& name, LogLevel level, co
  174.      fileSize(0)
  175.  {
  176.      dynamicName = std::string::npos != filename.find("%s");
  177. -    backup = _flags & APPENDER_FLAGS_MAKE_FILE_BACKUP;
  178. +    backup = (_flags & APPENDER_FLAGS_MAKE_FILE_BACKUP) != 0;
  179.  
  180.      logfile = !dynamicName ? OpenFile(_filename, _mode, mode == "w" && backup) : NULL;
  181.  }
  182. diff --git a/src/server/shared/Logging/Log.cpp b/src/server/shared/Logging/Log.cpp
  183. index 3419598d17..d7a494e991 100644
  184. --- a/src/server/shared/Logging/Log.cpp
  185. +++ b/src/server/shared/Logging/Log.cpp
  186. @@ -76,9 +76,11 @@ void Log::CreateAppenderFromConfig(std::string const& appenderName)
  187.      // if type = File. optional1 = file and option2 = mode
  188.      // if type = Console. optional1 = Color
  189.      std::string options = sConfigMgr->GetStringDefault(appenderName.c_str(), "");
  190. +
  191.      Tokenizer tokens(options, ',');
  192.      Tokenizer::const_iterator iter = tokens.begin();
  193. -    uint8 size = tokens.size();
  194. +
  195. +    size_t size = tokens.size();
  196.      std::string name = appenderName.substr(9);
  197.  
  198.      if (size < 2)
  199. @@ -88,8 +90,9 @@ void Log::CreateAppenderFromConfig(std::string const& appenderName)
  200.      }
  201.  
  202.      AppenderFlags flags = APPENDER_FLAGS_NONE;
  203. -    AppenderType type = AppenderType(atoi(*iter));
  204. -    LogLevel level = LogLevel(atoi(*(++iter)));
  205. +    AppenderType type = AppenderType(atoi(*iter++));
  206. +    LogLevel level = LogLevel(atoi(*iter++));
  207. +
  208.      if (level > LOG_LEVEL_FATAL)
  209.      {
  210.          fprintf(stderr, "Log::CreateAppenderFromConfig: Wrong Log Level %d for appender %s\n", level, name.c_str());
  211. @@ -97,62 +100,62 @@ void Log::CreateAppenderFromConfig(std::string const& appenderName)
  212.      }
  213.  
  214.      if (size > 2)
  215. -        flags = AppenderFlags(atoi(*(++iter)));
  216. +        flags = AppenderFlags(atoi(*iter++));
  217.  
  218.      switch (type)
  219.      {
  220. -        case APPENDER_CONSOLE:
  221. -        {
  222. -            AppenderConsole* appender = new AppenderConsole(NextAppenderId(), name, level, flags);
  223. -            appenders[appender->getId()] = appender;
  224. -            if (size > 3)
  225. -                appender->InitColors(*(++iter));
  226. -            //fprintf(stdout, "Log::CreateAppenderFromConfig: Created Appender %s (%u), Type CONSOLE, Mask %u\n", appender->getName().c_str(), appender->getId(), appender->getLogLevel());
  227. -            break;
  228. -        }
  229. -        case APPENDER_FILE:
  230. +    case APPENDER_CONSOLE:
  231. +    {
  232. +        AppenderConsole* appender = new AppenderConsole(NextAppenderId(), name, level, flags);
  233. +        appenders[appender->getId()] = appender;
  234. +        if (size > 3)
  235. +            appender->InitColors(*iter++);
  236. +        //fprintf(stdout, "Log::CreateAppenderFromConfig: Created Appender %s (%u), Type CONSOLE, Mask %u\n", appender->getName().c_str(), appender->getId(), appender->getLogLevel());
  237. +        break;
  238. +    }
  239. +    case APPENDER_FILE:
  240. +    {
  241. +        std::string filename;
  242. +        std::string mode = "a";
  243. +
  244. +        if (size < 4)
  245.          {
  246. -            std::string filename;
  247. -            std::string mode = "a";
  248. -
  249. -            if (size < 4)
  250. -            {
  251. -                fprintf(stderr, "Log::CreateAppenderFromConfig: Missing file name for appender %s\n", name.c_str());
  252. -                return;
  253. -            }
  254. -
  255. -            filename = *(++iter);
  256. -
  257. -            if (size > 4)
  258. -                mode = *(++iter);
  259. -
  260. -            if (flags & APPENDER_FLAGS_USE_TIMESTAMP)
  261. -            {
  262. -                size_t dot_pos = filename.find_last_of(".");
  263. -                if (dot_pos != filename.npos)
  264. -                    filename.insert(dot_pos, m_logsTimestamp);
  265. -                else
  266. -                    filename += m_logsTimestamp;
  267. -            }
  268. -
  269. -            uint64 maxFileSize = 0;
  270. -            if (size > 5)
  271. -                maxFileSize = atoi(*(++iter));
  272. -
  273. -            uint8 id = NextAppenderId();
  274. -            appenders[id] = new AppenderFile(id, name, level, filename.c_str(), m_logsDir.c_str(), mode.c_str(), flags, maxFileSize);
  275. -            //fprintf(stdout, "Log::CreateAppenderFromConfig: Created Appender %s (%u), Type FILE, Mask %u, File %s, Mode %s\n", name.c_str(), id, level, filename.c_str(), mode.c_str());
  276. -            break;
  277. +            fprintf(stderr, "Log::CreateAppenderFromConfig: Missing file name for appender %s\n", name.c_str());
  278. +            return;
  279.          }
  280. -        case APPENDER_DB:
  281. +
  282. +        filename = *iter++;
  283. +
  284. +        if (size > 4)
  285. +            mode = *iter++;
  286. +
  287. +        if (flags & APPENDER_FLAGS_USE_TIMESTAMP)
  288.          {
  289. -            uint8 id = NextAppenderId();
  290. -            appenders[id] = new AppenderDB(id, name, level);
  291. -            break;
  292. +            size_t dot_pos = filename.find_last_of(".");
  293. +            if (dot_pos != filename.npos)
  294. +                filename.insert(dot_pos, m_logsTimestamp);
  295. +            else
  296. +                filename += m_logsTimestamp;
  297.          }
  298. -        default:
  299. -            fprintf(stderr, "Log::CreateAppenderFromConfig: Unknown type %d for appender %s\n", type, name.c_str());
  300. -            break;
  301. +
  302. +        uint64 maxFileSize = 0;
  303. +        if (size > 5)
  304. +            maxFileSize = atoi(*iter++);
  305. +
  306. +        uint8 id = NextAppenderId();
  307. +        appenders[id] = new AppenderFile(id, name, level, filename.c_str(), m_logsDir.c_str(), mode.c_str(), flags, maxFileSize);
  308. +        //fprintf(stdout, "Log::CreateAppenderFromConfig: Created Appender %s (%u), Type FILE, Mask %u, File %s, Mode %s\n", name.c_str(), id, level, filename.c_str(), mode.c_str());
  309. +        break;
  310. +    }
  311. +    case APPENDER_DB:
  312. +    {
  313. +        uint8 id = NextAppenderId();
  314. +        appenders[id] = new AppenderDB(id, name, level);
  315. +        break;
  316. +    }
  317. +    default:
  318. +        fprintf(stderr, "Log::CreateAppenderFromConfig: Unknown type %d for appender %s\n", type, name.c_str());
  319. +        break;
  320.      }
  321.  }
  322.  
  323. @@ -189,7 +192,7 @@ void Log::CreateLoggerFromConfig(std::string const& appenderName)
  324.          return;
  325.      }
  326.  
  327. -    level = LogLevel(atoi(*iter));
  328. +    level = LogLevel(atoi(*iter++));
  329.      if (level > LOG_LEVEL_FATAL)
  330.      {
  331.          fprintf(stderr, "Log::CreateLoggerFromConfig: Wrong Log Level %u for logger %s\n", type, name.c_str());
  332. @@ -199,7 +202,6 @@ void Log::CreateLoggerFromConfig(std::string const& appenderName)
  333.      logger.Create(name, level);
  334.      //fprintf(stdout, "Log::CreateLoggerFromConfig: Created Logger %s, Level %u\n", name.c_str(), level);
  335.  
  336. -    ++iter;
  337.      std::istringstream ss(*iter);
  338.      std::string str;
  339.  
  340. @@ -242,7 +244,7 @@ void Log::ReadLoggersFromConfig()
  341.      if (loggers.find(LOGGER_ROOT) == loggers.end())
  342.      {
  343.          fprintf(stderr, "Wrong Loggers configuration. Review your Logger config section.\n"
  344. -                        "Creating default loggers [root (Error), server (Info)] to console\n");
  345. +            "Creating default loggers [root (Error), server (Info)] to console\n");
  346.  
  347.          Close(); // Clean any Logger or Appender created
  348.  
  349. @@ -291,8 +293,8 @@ std::string Log::GetTimestampStr()
  350.      //       HH     hour (2 digits 00-23)
  351.      //       MM     minutes (2 digits 00-59)
  352.      //       SS     seconds (2 digits 00-59)
  353. -    char buf[72];
  354. -    snprintf(buf, sizeof(buf), "%04d-%02d-%02d_%02d-%02d-%02d", aTm.tm_year+1900, aTm.tm_mon+1, aTm.tm_mday, aTm.tm_hour, aTm.tm_min, aTm.tm_sec);
  355. +    char buf[20];
  356. +    snprintf(buf, 20, "%04d-%02d-%02d_%02d-%02d-%02d", aTm.tm_year + 1900, aTm.tm_mon + 1, aTm.tm_mday, aTm.tm_hour, aTm.tm_min, aTm.tm_sec);
  357.      return std::string(buf);
  358.  }
  359.  
  360. @@ -321,67 +323,8 @@ bool Log::SetLogLevel(std::string const& name, const char* newLevelc, bool isLog
  361.  
  362.          appender->setLogLevel(newLevel);
  363.      }
  364. -    return true;
  365. -}
  366. -
  367. -void Log::outTrace(std::string const& filter, const char * str, ...)
  368. -{
  369. -    va_list ap;
  370. -    va_start(ap, str);
  371. -
  372. -    vlog(filter, LOG_LEVEL_TRACE, str, ap);
  373. -
  374. -    va_end(ap);
  375. -}
  376. -
  377. -void Log::outDebug(std::string const& filter, const char * str, ...)
  378. -{
  379. -    va_list ap;
  380. -    va_start(ap, str);
  381. -
  382. -    vlog(filter, LOG_LEVEL_DEBUG, str, ap);
  383. -
  384. -    va_end(ap);
  385. -}
  386. -
  387. -void Log::outInfo(std::string const& filter, const char * str, ...)
  388. -{
  389. -    va_list ap;
  390. -    va_start(ap, str);
  391. -
  392. -    vlog(filter, LOG_LEVEL_INFO, str, ap);
  393. -
  394. -    va_end(ap);
  395. -}
  396. -
  397. -void Log::outWarn(std::string const& filter, const char * str, ...)
  398. -{
  399. -    va_list ap;
  400. -    va_start(ap, str);
  401. -
  402. -    vlog(filter, LOG_LEVEL_WARN, str, ap);
  403. -
  404. -    va_end(ap);
  405. -}
  406. -
  407. -void Log::outError(std::string const& filter, const char * str, ...)
  408. -{
  409. -    va_list ap;
  410. -    va_start(ap, str);
  411. -
  412. -    vlog(filter, LOG_LEVEL_ERROR, str, ap);
  413. -
  414. -    va_end(ap);
  415. -}
  416.  
  417. -void Log::outFatal(std::string const& filter, const char * str, ...)
  418. -{
  419. -    va_list ap;
  420. -    va_start(ap, str);
  421. -
  422. -    vlog(filter, LOG_LEVEL_FATAL, str, ap);
  423. -
  424. -    va_end(ap);
  425. +    return true;
  426.  }
  427.  
  428.  void Log::outCharDump(char const* str, uint32 accountId, uint32 guid, char const* name)
  429. @@ -391,7 +334,7 @@ void Log::outCharDump(char const* str, uint32 accountId, uint32 guid, char const
  430.  
  431.      std::ostringstream ss;
  432.      ss << "== START DUMP == (account: " << accountId << " guid: " << guid << " name: " << name
  433. -       << ")\n" << str << "\n== END DUMP ==\n";
  434. +        << ")\n" << str << "\n== END DUMP ==\n";
  435.  
  436.      LogMessage* msg = new LogMessage(LOG_LEVEL_INFO, "entities.player.dump", ss.str());
  437.      std::ostringstream param;
  438. @@ -454,6 +397,7 @@ void Log::LoadFromConfig()
  439.      if (!m_logsDir.empty())
  440.          if ((m_logsDir.at(m_logsDir.length() - 1) != '/') && (m_logsDir.at(m_logsDir.length() - 1) != '\\'))
  441.              m_logsDir.push_back('/');
  442. +
  443.      ReadAppendersFromConfig();
  444.      ReadLoggersFromConfig();
  445.  }
  446. diff --git a/src/server/shared/Logging/Log.h b/src/server/shared/Logging/Log.h
  447. index 07d968cd13..8321dfec18 100644
  448. --- a/src/server/shared/Logging/Log.h
  449. +++ b/src/server/shared/Logging/Log.h
  450. @@ -22,8 +22,8 @@
  451.  
  452.  #include "Define.h"
  453.  #include "Appender.h"
  454. -#include "LogWorker.h"
  455.  #include "Logger.h"
  456. +#include "LogWorker.h"
  457.  #include "Dynamic/UnorderedMap.h"
  458.  
  459.  #include <string>
  460. @@ -47,20 +47,15 @@ class Log
  461.          bool ShouldLog(std::string const& type, LogLevel level) const;
  462.          bool SetLogLevel(std::string const& name, char const* level, bool isLogger = true);
  463.  
  464. -        void outTrace(std::string const& f, char const* str, ...) ATTR_PRINTF(3, 4);
  465. -        void outDebug(std::string const& f, char const* str, ...) ATTR_PRINTF(3, 4);
  466. -        void outInfo(std::string const& f, char const* str, ...) ATTR_PRINTF(3, 4);
  467. -        void outWarn(std::string const& f, char const* str, ...) ATTR_PRINTF(3, 4);
  468. -        void outError(std::string const& f, char const* str, ...) ATTR_PRINTF(3, 4);
  469. -        void outFatal(std::string const& f, char const* str, ...) ATTR_PRINTF(3, 4);
  470. +        void outMessage(std::string const& f, LogLevel level, char const* str, ...) ATTR_PRINTF(4, 5);
  471.  
  472.          void outCommand(uint32 account, const char * str, ...) ATTR_PRINTF(3, 4);
  473.          void outCharDump(char const* str, uint32 account_id, uint32 guid, char const* name);
  474. -        static std::string GetTimestampStr();
  475. -
  476. +        
  477.          void SetRealmId(uint32 id);
  478.  
  479.      private:
  480. +        static std::string GetTimestampStr();
  481.          void vlog(std::string const& f, LogLevel level, char const* str, va_list argptr);
  482.          void write(LogMessage* msg) const;
  483.  
  484. @@ -113,41 +108,49 @@ inline bool Log::ShouldLog(std::string const& type, LogLevel level) const
  485.      return logLevel != LOG_LEVEL_DISABLED && logLevel <= level;
  486.  }
  487.  
  488. +inline void Log::outMessage(std::string const& filter, LogLevel level, const char * str, ...)
  489. +{
  490. +    va_list ap;
  491. +    va_start(ap, str);
  492. +    vlog(filter, level, str, ap);
  493. +    va_end(ap);
  494. +}
  495. +
  496.  #define sLog ACE_Singleton<Log, ACE_Thread_Mutex>::instance()
  497.  
  498.  #if COMPILER != COMPILER_MICROSOFT
  499. -#define SF_LOG_MESSAGE_BODY(level__, call__, filterType__, ...)     \
  500. -        do {                                                        \
  501. -            if (sLog->ShouldLog(filterType__, level__))             \
  502. -                sLog->call__(filterType__, __VA_ARGS__);            \
  503. +#define SF_LOG_MESSAGE_BODY(filterType__, level__, ...)                 \
  504. +        do {                                                            \
  505. +            if (sLog->ShouldLog(filterType__, level__))                 \
  506. +                sLog->outMessage(filterType__, level__, __VA_ARGS__);   \
  507.          } while (0)
  508.  #else
  509. -#define SF_LOG_MESSAGE_BODY(level__, call__, filterType__, ...)     \
  510. -        __pragma(warning(push))                                     \
  511. -        __pragma(warning(disable:4127))                             \
  512. -        do {                                                        \
  513. -            if (sLog->ShouldLog(filterType__, level__))             \
  514. -                sLog->call__(filterType__, __VA_ARGS__);            \
  515. -        } while (0)                                                 \
  516. +#define SF_LOG_MESSAGE_BODY(filterType__, level__, ...)                 \
  517. +        __pragma(warning(push))                                         \
  518. +        __pragma(warning(disable:4127))                                 \
  519. +        do {                                                            \
  520. +            if (sLog->ShouldLog(filterType__, level__))                 \
  521. +                sLog->outMessage(filterType__, level__, __VA_ARGS__);   \
  522. +        } while (0)                                                     \
  523.          __pragma(warning(pop))
  524.  #endif
  525.  
  526.  #define SF_LOG_TRACE(filterType__, ...) \
  527. -    SF_LOG_MESSAGE_BODY(LOG_LEVEL_TRACE, outTrace, filterType__, __VA_ARGS__)
  528. +    SF_LOG_MESSAGE_BODY(filterType__, LOG_LEVEL_TRACE, __VA_ARGS__)
  529.  
  530.  #define SF_LOG_DEBUG(filterType__, ...) \
  531. -    SF_LOG_MESSAGE_BODY(LOG_LEVEL_DEBUG, outDebug, filterType__, __VA_ARGS__)
  532. +    SF_LOG_MESSAGE_BODY(filterType__, LOG_LEVEL_DEBUG, __VA_ARGS__)
  533.  
  534.  #define SF_LOG_INFO(filterType__, ...)  \
  535. -    SF_LOG_MESSAGE_BODY(LOG_LEVEL_INFO, outInfo, filterType__, __VA_ARGS__)
  536. +    SF_LOG_MESSAGE_BODY(filterType__, LOG_LEVEL_INFO, __VA_ARGS__)
  537.  
  538.  #define SF_LOG_WARN(filterType__, ...)  \
  539. -    SF_LOG_MESSAGE_BODY(LOG_LEVEL_WARN, outWarn, filterType__, __VA_ARGS__)
  540. +    SF_LOG_MESSAGE_BODY(filterType__, LOG_LEVEL_WARN, __VA_ARGS__)
  541.  
  542.  #define SF_LOG_ERROR(filterType__, ...) \
  543. -    SF_LOG_MESSAGE_BODY(LOG_LEVEL_ERROR, outError, filterType__, __VA_ARGS__)
  544. +    SF_LOG_MESSAGE_BODY(filterType__, LOG_LEVEL_ERROR, __VA_ARGS__)
  545.  
  546.  #define SF_LOG_FATAL(filterType__, ...) \
  547. -    SF_LOG_MESSAGE_BODY(LOG_LEVEL_FATAL, outFatal, filterType__, __VA_ARGS__)
  548. +    SF_LOG_MESSAGE_BODY(filterType__, LOG_LEVEL_FATAL, __VA_ARGS__)
  549.  
  550.  #endif
  551. diff --git a/src/server/shared/Logging/Logger.cpp b/src/server/shared/Logging/Logger.cpp
  552. index 498a1fa0bb..1b708d29a8 100644
  553. --- a/src/server/shared/Logging/Logger.cpp
  554. +++ b/src/server/shared/Logging/Logger.cpp
  555. @@ -27,13 +27,6 @@ void Logger::Create(std::string const& _name, LogLevel _level)
  556.      level = _level;
  557.  }
  558.  
  559. -Logger::~Logger()
  560. -{
  561. -    for (AppenderMap::iterator it = appenders.begin(); it != appenders.end(); ++it)
  562. -        it->second = NULL;
  563. -    appenders.clear();
  564. -}
  565. -
  566.  std::string const& Logger::getName() const
  567.  {
  568.      return name;
  569. @@ -51,12 +44,7 @@ void Logger::addAppender(uint8 id, Appender* appender)
  570.  
  571.  void Logger::delAppender(uint8 id)
  572.  {
  573. -    AppenderMap::iterator it = appenders.find(id);
  574. -    if (it != appenders.end())
  575. -    {
  576. -        it->second = NULL;
  577. -        appenders.erase(it);
  578. -    }
  579. +    appenders.erase(id);
  580.  }
  581.  
  582.  void Logger::setLogLevel(LogLevel _level)
  583. diff --git a/src/server/shared/Logging/Logger.h b/src/server/shared/Logging/Logger.h
  584. index 7d92dede79..f782897036 100644
  585. --- a/src/server/shared/Logging/Logger.h
  586. +++ b/src/server/shared/Logging/Logger.h
  587. @@ -26,8 +26,7 @@ class Logger
  588.  {
  589.      public:
  590.          Logger();
  591. -        ~Logger();
  592. -
  593. +        
  594.          void Create(std::string const& name, LogLevel level);
  595.          void addAppender(uint8 type, Appender *);
  596.          void delAppender(uint8 type);

Yourpaste is for source code and general debugging text.

Login or Register to edit, delete and keep track of your pastes and more.

Raw Paste

Login or Register to edit or fork this paste. It's free.