1 | // |
2 | // FormattingChannel.h |
3 | // |
4 | // Library: Foundation |
5 | // Package: Logging |
6 | // Module: Formatter |
7 | // |
8 | // Definition of the FormattingChannel 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_FormattingChannel_INCLUDED |
18 | #define Foundation_FormattingChannel_INCLUDED |
19 | |
20 | |
21 | #include "Poco/Foundation.h" |
22 | #include "Poco/Channel.h" |
23 | |
24 | |
25 | namespace Poco { |
26 | |
27 | |
28 | class Formatter; |
29 | |
30 | |
31 | class Foundation_API FormattingChannel: public Channel |
32 | /// The FormattingChannel is a filter channel that routes |
33 | /// a Message through a Formatter before passing it on |
34 | /// to the destination channel. |
35 | { |
36 | public: |
37 | FormattingChannel(); |
38 | /// Creates a FormattingChannel. |
39 | |
40 | FormattingChannel(Formatter* pFormatter); |
41 | /// Creates a FormattingChannel and attaches a Formatter. |
42 | |
43 | FormattingChannel(Formatter* pFormatter, Channel* pChannel); |
44 | /// Creates a FormattingChannel and attaches a Formatter |
45 | /// and a Channel. |
46 | |
47 | void setFormatter(Formatter* pFormatter); |
48 | /// Sets the Formatter used to format the messages |
49 | /// before they are passed on. If null, the message |
50 | /// is passed on unmodified. |
51 | |
52 | Formatter* getFormatter() const; |
53 | /// Returns the Formatter used to format messages, |
54 | /// which may be null. |
55 | |
56 | void setChannel(Channel* pChannel); |
57 | /// Sets the destination channel to which the formatted |
58 | /// messages are passed on. |
59 | |
60 | Channel* getChannel() const; |
61 | /// Returns the channel to which the formatted |
62 | /// messages are passed on. |
63 | |
64 | void log(const Message& msg); |
65 | /// Formats the given Message using the Formatter and |
66 | /// passes the formatted message on to the destination |
67 | /// Channel. |
68 | |
69 | void setProperty(const std::string& name, const std::string& value); |
70 | /// Sets or changes a configuration property. |
71 | /// |
72 | /// Only the "channel" and "formatter" properties are supported, which allow |
73 | /// setting the target channel and formatter, respectively, via the LoggingRegistry. |
74 | /// The "channel" and "formatter" properties are set-only. |
75 | /// |
76 | /// Unsupported properties are passed to the attached Channel. |
77 | |
78 | void open(); |
79 | /// Opens the attached channel. |
80 | |
81 | void close(); |
82 | /// Closes the attached channel. |
83 | |
84 | protected: |
85 | ~FormattingChannel(); |
86 | |
87 | private: |
88 | Formatter* _pFormatter; |
89 | Channel* _pChannel; |
90 | }; |
91 | |
92 | |
93 | } // namespace Poco |
94 | |
95 | |
96 | #endif // Foundation_FormattingChannel_INCLUDED |
97 | |