logger_support.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. // Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // Permission to use, copy, modify, and/or distribute this software for any
  4. // purpose with or without fee is hereby granted, provided that the above
  5. // copyright notice and this permission notice appear in all copies.
  6. //
  7. // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  8. // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  9. // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  10. // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  11. // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  12. // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  13. // PERFORMANCE OF THIS SOFTWARE.
  14. #ifndef __LOGGER_SUPPORT_H
  15. #define __LOGGER_SUPPORT_H
  16. #include <unistd.h>
  17. #include <string>
  18. #include <log/logger.h>
  19. namespace isc {
  20. namespace log {
  21. /// \brief Is logging initialized?
  22. ///
  23. /// As some underlying logging implementations can behave unpredictably if they
  24. /// have not been initialized when a logging function is called, their
  25. /// initialization state is tracked. The logger functions will check this flag
  26. /// and throw an exception if logging is not initialized at that point.
  27. ///
  28. /// \return true if logging has been initialized, false if not
  29. bool isLoggingInitialized();
  30. /// \brief Set "logging initialized" flag
  31. ///
  32. /// Sets the state of the "logging initialized" flag.
  33. ///
  34. /// \param state State to set the flag to. (This is expected to be "true" - the
  35. /// default - for all code apart from specific unit tests.)
  36. void setLoggingInitialized(bool state = true);
  37. /// \brief Run-Time Initialization
  38. ///
  39. /// Performs run-time initialization of the logger in particular supplying:
  40. ///
  41. /// - Name of the root logger
  42. /// - The severity (and if applicable, debug level) for the root logger.
  43. /// - Name of a local message file, containing localisation of message text.
  44. ///
  45. /// This function is likely to change over time as more debugging options are
  46. /// held in the configuration database.
  47. ///
  48. /// \param root Name of the root logger
  49. /// \param severity Severity at which to log
  50. /// \param dbglevel Debug severity (ignored if "severity" is not "DEBUG")
  51. /// \param file Name of the local message file.
  52. void initLogger(const std::string& root,
  53. isc::log::Severity severity = isc::log::INFO,
  54. int dbglevel = 0, const char* file = NULL);
  55. /// \brief Run-Time Initialization from Environment
  56. ///
  57. /// Performs run-time initialization of the logger via the setting of
  58. /// environment variables. These are:
  59. ///
  60. /// B10_LOGGER_ROOT
  61. /// Name of the root logger. If not given, the string "bind10" will be used.
  62. ///
  63. /// B10_LOGGER_SEVERITY
  64. /// Severity of messages that will be logged. This must be one of the strings
  65. /// "DEBUG", "INFO", "WARN", "ERROR", "FATAL" or "NONE". (Must be upper case
  66. /// and must not contain leading or trailing spaces.) If not specified (or if
  67. /// specified but incorrect), the default passed as argument to this function
  68. /// (currently INFO) will be used.
  69. ///
  70. /// B10_LOGGER_DBGLEVEL
  71. /// Ignored if the level is not DEBUG, this should be a number between 0 and
  72. /// 99 indicating the logging severity. The default is 0. If outside these
  73. /// limits or if not a number, The value passed to this function (default
  74. /// of 0) is used.
  75. ///
  76. /// B10_LOGGER_LOCALMSG
  77. /// If defined, the path specification of a file that contains message
  78. /// definitions replacing ones in the default dictionary.
  79. ///
  80. /// Any errors in the settings cause messages to be output to stderr.
  81. ///
  82. /// This function is aimed at test programs, allowing the default settings to
  83. /// be overridden by the tester. It is not intended for use in production
  84. /// code.
  85. void initLogger(isc::log::Severity severity = isc::log::INFO,
  86. int dbglevel = 0);
  87. } // namespace log
  88. } // namespace isc
  89. #endif // __LOGGER_SUPPORT_H