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