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