LoggingRegistry.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. //
  2. // LoggingRegistry.h
  3. //
  4. // $Id: //poco/1.4/Foundation/include/Poco/LoggingRegistry.h#1 $
  5. //
  6. // Library: Foundation
  7. // Package: Logging
  8. // Module: LoggingRegistry
  9. //
  10. // Definition of the LoggingRegistry class.
  11. //
  12. // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
  13. // and Contributors.
  14. //
  15. // SPDX-License-Identifier: BSL-1.0
  16. //
  17. #ifndef Foundation_LoggingRegistry_INCLUDED
  18. #define Foundation_LoggingRegistry_INCLUDED
  19. #include "Poco/Foundation.h"
  20. #include "Poco/AutoPtr.h"
  21. #include "Poco/Channel.h"
  22. #include "Poco/Formatter.h"
  23. #include "Poco/Mutex.h"
  24. #include <map>
  25. namespace Poco {
  26. class Foundation_API LoggingRegistry
  27. /// A registry for channels and formatters.
  28. ///
  29. /// The LoggingRegistry class is used for configuring
  30. /// the logging framework.
  31. {
  32. public:
  33. LoggingRegistry();
  34. /// Creates the LoggingRegistry.
  35. ~LoggingRegistry();
  36. /// Destroys the LoggingRegistry.
  37. Channel* channelForName(const std::string& name) const;
  38. /// Returns the Channel object which has been registered
  39. /// under the given name.
  40. ///
  41. /// Throws a NotFoundException if the name is unknown.
  42. Formatter* formatterForName(const std::string& name) const;
  43. /// Returns the Formatter object which has been registered
  44. /// under the given name.
  45. ///
  46. /// Throws a NotFoundException if the name is unknown.
  47. void registerChannel(const std::string& name, Channel* pChannel);
  48. /// Registers a channel under a given name.
  49. /// It is okay to re-register a different channel under an
  50. /// already existing name.
  51. void registerFormatter(const std::string& name, Formatter* pFormatter);
  52. /// Registers a formatter under a given name.
  53. /// It is okay to re-register a different formatter under an
  54. /// already existing name.
  55. void unregisterChannel(const std::string& name);
  56. /// Unregisters the given channel.
  57. ///
  58. /// Throws a NotFoundException if the name is unknown.
  59. void unregisterFormatter(const std::string& name);
  60. /// Unregisters the given formatter.
  61. ///
  62. /// Throws a NotFoundException if the name is unknown.
  63. void clear();
  64. /// Unregisters all registered channels and formatters.
  65. static LoggingRegistry& defaultRegistry();
  66. /// Returns a reference to the default
  67. /// LoggingRegistry.
  68. private:
  69. typedef AutoPtr<Channel> ChannelPtr;
  70. typedef AutoPtr<Formatter> FormatterPtr;
  71. typedef std::map<std::string, ChannelPtr> ChannelMap;
  72. typedef std::map<std::string, FormatterPtr> FormatterMap;
  73. ChannelMap _channelMap;
  74. FormatterMap _formatterMap;
  75. mutable FastMutex _mutex;
  76. };
  77. } // namespace Poco
  78. #endif // Foundation_LoggingRegistry_INCLUDED