1 | // |
---|---|
2 | // FormattingChannel.cpp |
3 | // |
4 | // Library: Foundation |
5 | // Package: Logging |
6 | // Module: Formatter |
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/FormattingChannel.h" |
16 | #include "Poco/Formatter.h" |
17 | #include "Poco/Message.h" |
18 | #include "Poco/LoggingRegistry.h" |
19 | |
20 | |
21 | namespace Poco { |
22 | |
23 | |
24 | FormattingChannel::FormattingChannel(): |
25 | _pFormatter(0), |
26 | _pChannel(0) |
27 | { |
28 | } |
29 | |
30 | |
31 | FormattingChannel::FormattingChannel(Formatter* pFormatter): |
32 | _pFormatter(pFormatter), |
33 | _pChannel(0) |
34 | { |
35 | if (_pFormatter) _pFormatter->duplicate(); |
36 | } |
37 | |
38 | |
39 | FormattingChannel::FormattingChannel(Formatter* pFormatter, Channel* pChannel): |
40 | _pFormatter(pFormatter), |
41 | _pChannel(pChannel) |
42 | { |
43 | if (_pFormatter) _pFormatter->duplicate(); |
44 | if (_pChannel) _pChannel->duplicate(); |
45 | } |
46 | |
47 | |
48 | FormattingChannel::~FormattingChannel() |
49 | { |
50 | if (_pChannel) _pChannel->release(); |
51 | if (_pFormatter) _pFormatter->release(); |
52 | } |
53 | |
54 | |
55 | void FormattingChannel::setFormatter(Formatter* pFormatter) |
56 | { |
57 | if (_pFormatter) _pFormatter->release(); |
58 | _pFormatter = pFormatter; |
59 | if (_pFormatter) _pFormatter->duplicate(); |
60 | } |
61 | |
62 | |
63 | Formatter* FormattingChannel::getFormatter() const |
64 | { |
65 | return _pFormatter; |
66 | } |
67 | |
68 | |
69 | void FormattingChannel::setChannel(Channel* pChannel) |
70 | { |
71 | if (_pChannel) _pChannel->release(); |
72 | _pChannel = pChannel; |
73 | if (_pChannel) _pChannel->duplicate(); |
74 | } |
75 | |
76 | |
77 | Channel* FormattingChannel::getChannel() const |
78 | { |
79 | return _pChannel; |
80 | } |
81 | |
82 | |
83 | void FormattingChannel::log(const Message& msg) |
84 | { |
85 | if (_pChannel) |
86 | { |
87 | if (_pFormatter) |
88 | { |
89 | std::string text; |
90 | _pFormatter->format(msg, text); |
91 | _pChannel->log(Message(msg, text)); |
92 | } |
93 | else |
94 | { |
95 | _pChannel->log(msg); |
96 | } |
97 | } |
98 | } |
99 | |
100 | |
101 | void FormattingChannel::setProperty(const std::string& name, const std::string& value) |
102 | { |
103 | if (name == "channel") |
104 | setChannel(LoggingRegistry::defaultRegistry().channelForName(value)); |
105 | else if (name == "formatter") |
106 | setFormatter(LoggingRegistry::defaultRegistry().formatterForName(value)); |
107 | else if (_pChannel) |
108 | _pChannel->setProperty(name, value); |
109 | } |
110 | |
111 | |
112 | void FormattingChannel::open() |
113 | { |
114 | if (_pChannel) |
115 | _pChannel->open(); |
116 | } |
117 | |
118 | |
119 | void FormattingChannel::close() |
120 | { |
121 | if (_pChannel) |
122 | _pChannel->close(); |
123 | } |
124 | |
125 | |
126 | } // namespace Poco |
127 |