/indra/llcommon/llerrorcontrol.h

https://bitbucket.org/lindenlab/viewer-beta/ · C Header · 176 lines · 67 code · 37 blank · 72 comment · 0 complexity · 2e55a2d9e11c56c2d90b08e8fc4bb2f9 MD5 · raw file

  1. /**
  2. * @file llerrorcontrol.h
  3. * @date December 2006
  4. * @brief error message system control
  5. *
  6. * $LicenseInfo:firstyear=2007&license=viewerlgpl$
  7. * Second Life Viewer Source Code
  8. * Copyright (C) 2010, Linden Research, Inc.
  9. *
  10. * This library is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU Lesser General Public
  12. * License as published by the Free Software Foundation;
  13. * version 2.1 of the License only.
  14. *
  15. * This library is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * Lesser General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Lesser General Public
  21. * License along with this library; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  23. *
  24. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  25. * $/LicenseInfo$
  26. */
  27. #ifndef LL_LLERRORCONTROL_H
  28. #define LL_LLERRORCONTROL_H
  29. #include "llerror.h"
  30. #include "boost/function.hpp"
  31. #include <string>
  32. class LLSD;
  33. /*
  34. This is the part of the LLError namespace that manages the messages
  35. produced by the logging. The logging support is defined in llerror.h.
  36. Most files do not need to include this.
  37. These implementations are in llerror.cpp.
  38. */
  39. // Line buffer interface
  40. class LLLineBuffer
  41. {
  42. public:
  43. LLLineBuffer() {};
  44. virtual ~LLLineBuffer() {};
  45. virtual void clear() = 0; // Clear the buffer, and reset it.
  46. virtual void addLine(const std::string& utf8line) = 0;
  47. };
  48. namespace LLError
  49. {
  50. LL_COMMON_API void initForServer(const std::string& identity);
  51. // resets all logging settings to defaults needed by server processes
  52. // logs to stderr, syslog, and windows debug log
  53. // the identity string is used for in the syslog
  54. LL_COMMON_API void initForApplication(const std::string& dir);
  55. // resets all logging settings to defaults needed by applicaitons
  56. // logs to stderr and windows debug log
  57. // sets up log configuration from the file logcontrol.xml in dir
  58. /*
  59. Settings that control what is logged.
  60. Setting a level means log messages at that level or above.
  61. */
  62. LL_COMMON_API void setPrintLocation(bool);
  63. LL_COMMON_API void setDefaultLevel(LLError::ELevel);
  64. LL_COMMON_API ELevel getDefaultLevel();
  65. LL_COMMON_API void setFunctionLevel(const std::string& function_name, LLError::ELevel);
  66. LL_COMMON_API void setClassLevel(const std::string& class_name, LLError::ELevel);
  67. LL_COMMON_API void setFileLevel(const std::string& file_name, LLError::ELevel);
  68. LL_COMMON_API void setTagLevel(const std::string& file_name, LLError::ELevel);
  69. LL_COMMON_API void configure(const LLSD&);
  70. // the LLSD can configure all of the settings
  71. // usually read automatically from the live errorlog.xml file
  72. /*
  73. Control functions.
  74. */
  75. typedef boost::function<void(const std::string&)> FatalFunction;
  76. LL_COMMON_API void crashAndLoop(const std::string& message);
  77. // Default fatal function: access null pointer and loops forever
  78. LL_COMMON_API void setFatalFunction(const FatalFunction&);
  79. // The fatal function will be called when an message of LEVEL_ERROR
  80. // is logged. Note: supressing a LEVEL_ERROR message from being logged
  81. // (by, for example, setting a class level to LEVEL_NONE), will keep
  82. // the that message from causing the fatal funciton to be invoked.
  83. LL_COMMON_API FatalFunction getFatalFunction();
  84. // Retrieve the previously-set FatalFunction
  85. /// temporarily override the FatalFunction for the duration of a
  86. /// particular scope, e.g. for unit tests
  87. class LL_COMMON_API OverrideFatalFunction
  88. {
  89. public:
  90. OverrideFatalFunction(const FatalFunction& func):
  91. mPrev(getFatalFunction())
  92. {
  93. setFatalFunction(func);
  94. }
  95. ~OverrideFatalFunction()
  96. {
  97. setFatalFunction(mPrev);
  98. }
  99. private:
  100. FatalFunction mPrev;
  101. };
  102. typedef std::string (*TimeFunction)();
  103. LL_COMMON_API std::string utcTime();
  104. LL_COMMON_API void setTimeFunction(TimeFunction);
  105. // The function is use to return the current time, formatted for
  106. // display by those error recorders that want the time included.
  107. class LL_COMMON_API Recorder
  108. {
  109. // An object that handles the actual output or error messages.
  110. public:
  111. virtual ~Recorder();
  112. virtual void recordMessage(LLError::ELevel, const std::string& message) = 0;
  113. // use the level for better display, not for filtering
  114. virtual bool wantsTime(); // default returns false
  115. // override and return true if the recorder wants the time string
  116. // included in the text of the message
  117. };
  118. LL_COMMON_API void addRecorder(Recorder*);
  119. LL_COMMON_API void removeRecorder(Recorder*);
  120. // each error message is passed to each recorder via recordMessage()
  121. LL_COMMON_API void logToFile(const std::string& filename);
  122. LL_COMMON_API void logToFixedBuffer(LLLineBuffer*);
  123. // Utilities to add recorders for logging to a file or a fixed buffer
  124. // A second call to the same function will remove the logger added
  125. // with the first.
  126. // Passing the empty string or NULL to just removes any prior.
  127. LL_COMMON_API std::string logFileName();
  128. // returns name of current logging file, empty string if none
  129. /*
  130. Utilities for use by the unit tests of LLError itself.
  131. */
  132. class Settings;
  133. LL_COMMON_API Settings* saveAndResetSettings();
  134. LL_COMMON_API void restoreSettings(Settings *);
  135. LL_COMMON_API std::string abbreviateFile(const std::string& filePath);
  136. LL_COMMON_API int shouldLogCallCount();
  137. };
  138. #endif // LL_LLERRORCONTROL_H