LoggingRegistry.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. //
  2. // LoggingRegistry.cpp
  3. //
  4. // $Id: //poco/1.4/Foundation/src/LoggingRegistry.cpp#1 $
  5. //
  6. // Library: Foundation
  7. // Package: Logging
  8. // Module: LoggingRegistry
  9. //
  10. // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
  11. // and Contributors.
  12. //
  13. // SPDX-License-Identifier: BSL-1.0
  14. //
  15. #include "Poco/LoggingRegistry.h"
  16. #include "Poco/SingletonHolder.h"
  17. namespace Poco {
  18. LoggingRegistry::LoggingRegistry()
  19. {
  20. }
  21. LoggingRegistry::~LoggingRegistry()
  22. {
  23. }
  24. Channel* LoggingRegistry::channelForName(const std::string& name) const
  25. {
  26. FastMutex::ScopedLock lock(_mutex);
  27. ChannelMap::const_iterator it = _channelMap.find(name);
  28. if (it != _channelMap.end())
  29. return const_cast<Channel*>(it->second.get());
  30. else
  31. throw NotFoundException("logging channel", name);
  32. }
  33. Formatter* LoggingRegistry::formatterForName(const std::string& name) const
  34. {
  35. FastMutex::ScopedLock lock(_mutex);
  36. FormatterMap::const_iterator it = _formatterMap.find(name);
  37. if (it != _formatterMap.end())
  38. return const_cast<Formatter*>(it->second.get());
  39. else
  40. throw NotFoundException("logging formatter", name);
  41. }
  42. void LoggingRegistry::registerChannel(const std::string& name, Channel* pChannel)
  43. {
  44. FastMutex::ScopedLock lock(_mutex);
  45. _channelMap[name] = ChannelPtr(pChannel, true);
  46. }
  47. void LoggingRegistry::registerFormatter(const std::string& name, Formatter* pFormatter)
  48. {
  49. FastMutex::ScopedLock lock(_mutex);
  50. _formatterMap[name] = FormatterPtr(pFormatter, true);
  51. }
  52. void LoggingRegistry::unregisterChannel(const std::string& name)
  53. {
  54. FastMutex::ScopedLock lock(_mutex);
  55. ChannelMap::iterator it = _channelMap.find(name);
  56. if (it != _channelMap.end())
  57. _channelMap.erase(it);
  58. else
  59. throw NotFoundException("logging channel", name);
  60. }
  61. void LoggingRegistry::unregisterFormatter(const std::string& name)
  62. {
  63. FastMutex::ScopedLock lock(_mutex);
  64. FormatterMap::iterator it = _formatterMap.find(name);
  65. if (it != _formatterMap.end())
  66. _formatterMap.erase(it);
  67. else
  68. throw NotFoundException("logging formatter", name);
  69. }
  70. void LoggingRegistry::clear()
  71. {
  72. FastMutex::ScopedLock lock(_mutex);
  73. _channelMap.clear();
  74. _formatterMap.clear();
  75. }
  76. namespace
  77. {
  78. static SingletonHolder<LoggingRegistry> sh;
  79. }
  80. LoggingRegistry& LoggingRegistry::defaultRegistry()
  81. {
  82. return *sh.get();
  83. }
  84. } // namespace Poco