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