PageRenderTime 24ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llcommon/lllog.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 111 lines | 67 code | 15 blank | 29 comment | 7 complexity | 10b9d7048d5ce255f9fe8dad6e01333d MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file lllog.cpp
  3. * @author Don
  4. * @date 2007-11-27
  5. * @brief Class to log messages to syslog for streambase to process.
  6. *
  7. * $LicenseInfo:firstyear=2007&license=viewerlgpl$
  8. * Second Life Viewer Source Code
  9. * Copyright (C) 2010, Linden Research, Inc.
  10. *
  11. * This library is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU Lesser General Public
  13. * License as published by the Free Software Foundation;
  14. * version 2.1 of the License only.
  15. *
  16. * This library is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  19. * Lesser General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Lesser General Public
  22. * License along with this library; if not, write to the Free Software
  23. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  24. *
  25. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  26. * $/LicenseInfo$
  27. */
  28. #include "linden_common.h"
  29. #include "lllog.h"
  30. #include "llapp.h"
  31. #include "llsd.h"
  32. #include "llsdserialize.h"
  33. class LLLogImpl
  34. {
  35. public:
  36. LLLogImpl(LLApp* app) : mApp(app) {}
  37. ~LLLogImpl() {}
  38. void log(const std::string &message, LLSD& info);
  39. bool useLegacyLogMessage(const std::string &message);
  40. private:
  41. LLApp* mApp;
  42. };
  43. //@brief Function to log a message to syslog for streambase to collect.
  44. void LLLogImpl::log(const std::string &message, LLSD& info)
  45. {
  46. static S32 sequence = 0;
  47. LLSD log_config = mApp->getOption("log-messages");
  48. if (log_config.has(message))
  49. {
  50. LLSD message_config = log_config[message];
  51. if (message_config.has("use-syslog"))
  52. {
  53. if (! message_config["use-syslog"].asBoolean())
  54. {
  55. return;
  56. }
  57. }
  58. }
  59. llinfos << "LLLOGMESSAGE (" << (sequence++) << ") " << message
  60. << " " << LLSDNotationStreamer(info) << llendl;
  61. }
  62. //@brief Function to check if specified legacy log message should be sent.
  63. bool LLLogImpl::useLegacyLogMessage(const std::string &message)
  64. {
  65. LLSD log_config = mApp->getOption("log-messages");
  66. if (log_config.has(message))
  67. {
  68. LLSD message_config = log_config[message];
  69. if (message_config.has("use-legacy"))
  70. {
  71. return message_config["use-legacy"].asBoolean();
  72. }
  73. }
  74. return true;
  75. }
  76. LLLog::LLLog(LLApp* app)
  77. {
  78. mImpl = new LLLogImpl(app);
  79. }
  80. LLLog::~LLLog()
  81. {
  82. delete mImpl;
  83. mImpl = NULL;
  84. }
  85. void LLLog::log(const std::string &message, LLSD& info)
  86. {
  87. if (mImpl) mImpl->log(message, info);
  88. }
  89. bool LLLog::useLegacyLogMessage(const std::string &message)
  90. {
  91. if (mImpl)
  92. {
  93. return mImpl->useLegacyLogMessage(message);
  94. }
  95. return true;
  96. }