llerrorcontrol.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /**
  2. * @file llerrorcontrol.h
  3. * @brief Error message system control functions declarations
  4. *
  5. * $LicenseInfo:firstyear=2007&license=viewergpl$
  6. *
  7. * Copyright (c) 2007-2009, Linden Research, Inc.
  8. * Copyright (c) 2009-2023, Henri Beauchamp.
  9. *
  10. * Second Life Viewer Source Code
  11. * The source code in this file ("Source Code") is provided by Linden Lab
  12. * to you under the terms of the GNU General Public License, version 2.0
  13. * ("GPL"), unless you have obtained a separate licensing agreement
  14. * ("Other License"), formally executed by you and Linden Lab. Terms of
  15. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  16. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  17. *
  18. * There are special exceptions to the terms and conditions of the GPL as
  19. * it is applied to this Source Code. View the full text of the exception
  20. * in the file doc/FLOSS-exception.txt in this software distribution, or
  21. * online at
  22. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  23. *
  24. * By copying, modifying or distributing this software, you acknowledge
  25. * that you have read and understood your obligations described above,
  26. * and agree to abide by those obligations.
  27. *
  28. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  29. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  30. * COMPLETENESS OR PERFORMANCE.
  31. * $/LicenseInfo$
  32. */
  33. #ifndef LL_LLERRORCONTROL_H
  34. #define LL_LLERRORCONTROL_H
  35. #include "llerror.h"
  36. #include <set>
  37. #include <string>
  38. class LLSD;
  39. // Note: the abort() call is normally redundant, but better safe than sorry. HB
  40. #if LL_MSVC
  41. # define LL_ERROR_CRASH __debugbreak(); abort()
  42. #else
  43. # define LL_ERROR_CRASH __builtin_trap(); abort()
  44. #endif
  45. // This is the part of the LLError namespace that manages the messages produced
  46. // by the logging. The logging support is defined in llerror.h. Most files do
  47. // not need to include this. These implementations are in llerror.cpp.
  48. // Line buffer interface
  49. class LLLineBuffer
  50. {
  51. public:
  52. LLLineBuffer() = default;
  53. virtual ~LLLineBuffer() = default;
  54. virtual void clear() = 0; // Clear the buffer, and reset it.
  55. virtual void addLine(const std::string& utf8line) = 0;
  56. };
  57. namespace LLError
  58. {
  59. // Resets all logging settings to defaults needed by application logs to
  60. // stderr and windows debug log sets up log configuration from the file
  61. // logcontrol.xml in dir
  62. void initForApplication(const std::string& dir);
  63. //
  64. // Settings that control what is logged.
  65. // Setting a level means log messages at that level or above.
  66. //
  67. void setPrintLocation(bool print);
  68. void setDefaultLevel(ELevel level);
  69. void setFunctionLevel(const std::string& function_name, ELevel level);
  70. void setClassLevel(const std::string& class_name, ELevel level);
  71. void setFileLevel(const std::string& file_name, ELevel level);
  72. void setTagLevel(const std::string& file_name, ELevel level);
  73. ELevel getTagLevel(const std::string& tag_name);
  74. std::set<std::string> getTagsForLevel(ELevel level);
  75. // The LLSD can configure all of the settings usually read automatically
  76. // from the live errorlog.xml file
  77. void configure(const LLSD&);
  78. //
  79. // Control functions.
  80. //
  81. // The fatal function will be called when an message of LEVEL_ERROR is
  82. // logged. Note: supressing a LEVEL_ERROR message from being logged (by,
  83. // for example, setting a class level to LEVEL_NONE), will keep the that
  84. // message from causing the fatal funciton to be invoked.
  85. typedef void (*fatal_func_t)(const std::string& message);
  86. void setFatalFunction(fatal_func_t func);
  87. // Returns the UTC time stamp with milliseconds when 'print_ms' is true. HB
  88. std::string utcTime(bool print_ms);
  89. // This function is used to return the current time, formatted for display
  90. // by those error recorders that want the time included.
  91. // Note: 'print_ms' must be true to get milliseconds in time stamp, false
  92. // otherwise. HB
  93. typedef std::string (*time_func_t)(bool print_ms);
  94. void setTimeFunction(time_func_t);
  95. // An object that handles the actual output or error messages.
  96. class Recorder
  97. {
  98. public:
  99. virtual ~Recorder();
  100. // Uses the level for better display, not for filtering
  101. virtual void recordMessage(ELevel,
  102. const std::string& message) = 0;
  103. // Overrides and returns true if the recorder wants the time string
  104. // included in the text of the message
  105. virtual bool wantsTime(); // default returns false
  106. };
  107. // Each error message is passed to each recorder via recordMessage()
  108. void addRecorder(Recorder*);
  109. void removeRecorder(Recorder*);
  110. // Utilities to add recorders for logging to a file or a fixed buffer.
  111. // A second call to the same function will remove the logger added with
  112. // the first. Passing the empty string or NULL to just removes any prior.
  113. void logToFile(const std::string& filename);
  114. void logToFixedBuffer(LLLineBuffer*);
  115. // Returns name of current logging file, empty string if none
  116. std::string logFileName();
  117. // Sets the name of current logging file (used in llappviewer.cpp to keep
  118. // track of which log is in use, depending on other running instances).
  119. void setLogFileName(std::string filename);
  120. void logToFile(const std::string& filename);
  121. //
  122. // Utilities for use by the unit tests of LLError itself.
  123. //
  124. class Settings;
  125. Settings* saveAndResetSettings();
  126. void restoreSettings(Settings*);
  127. std::string abbreviateFile(const std::string& filePath);
  128. };
  129. #endif // LL_LLERRORCONTROL_H