1//
2// LoggingFactory.cpp
3//
4// Library: Foundation
5// Package: Logging
6// Module: LoggingFactory
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/LoggingFactory.h"
16#include "Poco/SingletonHolder.h"
17#include "Poco/AsyncChannel.h"
18#include "Poco/ConsoleChannel.h"
19#include "Poco/FileChannel.h"
20#include "Poco/SimpleFileChannel.h"
21#include "Poco/FormattingChannel.h"
22#include "Poco/SplitterChannel.h"
23#include "Poco/NullChannel.h"
24#include "Poco/EventChannel.h"
25#if defined(POCO_OS_FAMILY_UNIX) && !defined(POCO_NO_SYSLOGCHANNEL)
26#include "Poco/SyslogChannel.h"
27#endif
28#if defined(POCO_OS_FAMILY_WINDOWS) && !defined(_WIN32_WCE)
29#include "Poco/EventLogChannel.h"
30#include "Poco/WindowsConsoleChannel.h"
31#endif
32#include "Poco/PatternFormatter.h"
33
34
35namespace Poco {
36
37
38LoggingFactory::LoggingFactory()
39{
40 registerBuiltins();
41}
42
43
44LoggingFactory::~LoggingFactory()
45{
46}
47
48
49void LoggingFactory::registerChannelClass(const std::string& className, ChannelInstantiator* pFactory)
50{
51 _channelFactory.registerClass(className, pFactory);
52}
53
54
55void LoggingFactory::registerFormatterClass(const std::string& className, FormatterFactory* pFactory)
56{
57 _formatterFactory.registerClass(className, pFactory);
58}
59
60
61Channel::Ptr LoggingFactory::createChannel(const std::string& className) const
62{
63 return _channelFactory.createInstance(className);
64}
65
66
67Formatter::Ptr LoggingFactory::createFormatter(const std::string& className) const
68{
69 return _formatterFactory.createInstance(className);
70}
71
72
73namespace
74{
75 static SingletonHolder<LoggingFactory> sh;
76}
77
78
79LoggingFactory& LoggingFactory::defaultFactory()
80{
81 return *sh.get();
82}
83
84
85void LoggingFactory::registerBuiltins()
86{
87 _channelFactory.registerClass("AsyncChannel", new Instantiator<AsyncChannel, Channel>);
88#if defined(POCO_OS_FAMILY_WINDOWS) && !defined(_WIN32_WCE)
89 _channelFactory.registerClass("ConsoleChannel", new Instantiator<WindowsConsoleChannel, Channel>);
90 _channelFactory.registerClass("ColorConsoleChannel", new Instantiator<WindowsColorConsoleChannel, Channel>);
91#else
92 _channelFactory.registerClass("ConsoleChannel", new Instantiator<ConsoleChannel, Channel>);
93 _channelFactory.registerClass("ColorConsoleChannel", new Instantiator<ColorConsoleChannel, Channel>);
94#endif
95
96#ifndef POCO_NO_FILECHANNEL
97 _channelFactory.registerClass("FileChannel", new Instantiator<FileChannel, Channel>);
98 _channelFactory.registerClass("SimpleFileChannel", new Instantiator<SimpleFileChannel, Channel>);
99#endif
100 _channelFactory.registerClass("FormattingChannel", new Instantiator<FormattingChannel, Channel>);
101#ifndef POCO_NO_SPLITTERCHANNEL
102 _channelFactory.registerClass("SplitterChannel", new Instantiator<SplitterChannel, Channel>);
103#endif
104 _channelFactory.registerClass("NullChannel", new Instantiator<NullChannel, Channel>);
105 _channelFactory.registerClass("EventChannel", new Instantiator<EventChannel, Channel>);
106
107#if defined(POCO_OS_FAMILY_UNIX)
108#ifndef POCO_NO_SYSLOGCHANNEL
109 _channelFactory.registerClass("SyslogChannel", new Instantiator<SyslogChannel, Channel>);
110#endif
111#endif
112
113#if defined(POCO_OS_FAMILY_WINDOWS) && !defined(_WIN32_WCE)
114 _channelFactory.registerClass("EventLogChannel", new Instantiator<EventLogChannel, Channel>);
115#endif
116
117 _formatterFactory.registerClass("PatternFormatter", new Instantiator<PatternFormatter, Formatter>);
118}
119
120
121} // namespace Poco
122