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