You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

145 lines
4.6 KiB

  1. // -*- C++ -*-
  2. // Module: Log4CPLUS
  3. // File: loglog.h
  4. // Created: 6/2001
  5. // Author: Tad E. Smith
  6. //
  7. //
  8. // Copyright 2001-2010 Tad E. Smith
  9. //
  10. // Licensed under the Apache License, Version 2.0 (the "License");
  11. // you may not use this file except in compliance with the License.
  12. // You may obtain a copy of the License at
  13. //
  14. // http://www.apache.org/licenses/LICENSE-2.0
  15. //
  16. // Unless required by applicable law or agreed to in writing, software
  17. // distributed under the License is distributed on an "AS IS" BASIS,
  18. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  19. // See the License for the specific language governing permissions and
  20. // limitations under the License.
  21. /** @file */
  22. #ifndef LOG4CPLUS_HELPERS_LOGLOG
  23. #define LOG4CPLUS_HELPERS_LOGLOG
  24. #include <log4cplus/config.hxx>
  25. #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE)
  26. #pragma once
  27. #endif
  28. #include <log4cplus/tstring.h>
  29. #include <log4cplus/streams.h>
  30. #include <log4cplus/thread/syncprims.h>
  31. namespace log4cplus {
  32. namespace helpers {
  33. /**
  34. * This class used to output log statements from within the log4cplus package.
  35. *
  36. * Log4cplus components cannot make log4cplus logging calls. However, it is
  37. * sometimes useful for the user to learn about what log4cplus is
  38. * doing. You can enable log4cplus internal logging by defining the
  39. * <b>log4cplus.configDebug</b> variable.
  40. *
  41. * All log4cplus internal debug calls go to <code>cout</code>
  42. * where as internal error messages are sent to
  43. * <code>cerr</code>. All internal messages are prepended with
  44. * the string "log4clus: ".
  45. */
  46. class LOG4CPLUS_EXPORT LogLog
  47. {
  48. public:
  49. //! Return type of getLogLog().
  50. typedef LogLog * Ptr;
  51. /**
  52. * Returns a reference to the <code>LogLog</code> singleton.
  53. */
  54. static Ptr getLogLog();
  55. /**
  56. * Allows to enable/disable log4cplus internal logging.
  57. */
  58. void setInternalDebugging(bool enabled);
  59. /**
  60. * In quite mode no LogLog generates strictly no output, not even
  61. * for errors.
  62. *
  63. * @param quietMode A true for not
  64. */
  65. void setQuietMode(bool quietMode);
  66. /**
  67. * This method is used to output log4cplus internal debug
  68. * statements. Output goes to <code>std::cout</code>.
  69. */
  70. void debug(const log4cplus::tstring& msg) const;
  71. void debug(tchar const * msg) const;
  72. /**
  73. * This method is used to output log4cplus internal error
  74. * statements. There is no way to disable error
  75. * statements. Output goes to
  76. * <code>std::cerr</code>. Optionally, this method can
  77. * throw std::runtime_error exception too.
  78. */
  79. void error(const log4cplus::tstring& msg, bool throw_flag = false) const;
  80. void error(tchar const * msg, bool throw_flag = false) const;
  81. /**
  82. * This method is used to output log4cplus internal warning
  83. * statements. There is no way to disable warning statements.
  84. * Output goes to <code>std::cerr</code>.
  85. */
  86. void warn(const log4cplus::tstring& msg) const;
  87. void warn(tchar const * msg) const;
  88. // Public ctor and dtor to be used only by internal::DefaultContext.
  89. LogLog();
  90. virtual ~LogLog();
  91. private:
  92. enum TriState
  93. {
  94. TriUndef = -1,
  95. TriFalse,
  96. TriTrue
  97. };
  98. template <typename StringType>
  99. LOG4CPLUS_PRIVATE
  100. void logging_worker (tostream & os,
  101. bool (LogLog:: * cond) () const, tchar const *,
  102. StringType const &, bool throw_flag = false) const;
  103. LOG4CPLUS_PRIVATE static void set_tristate_from_env (TriState *,
  104. tchar const * envvar);
  105. LOG4CPLUS_PRIVATE bool get_quiet_mode () const;
  106. LOG4CPLUS_PRIVATE bool get_not_quiet_mode () const;
  107. LOG4CPLUS_PRIVATE bool get_debug_mode () const;
  108. // Data
  109. mutable TriState debugEnabled;
  110. mutable TriState quietMode;
  111. thread::Mutex mutex;
  112. LOG4CPLUS_PRIVATE LogLog(const LogLog&);
  113. LOG4CPLUS_PRIVATE LogLog & operator = (LogLog const &);
  114. };
  115. LOG4CPLUS_EXPORT LogLog & getLogLog ();
  116. } // end namespace helpers
  117. } // end namespace log4cplus
  118. #endif // LOG4CPLUS_HELPERS_LOGLOG