LoggingFactory.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. //
  2. // LoggingFactory.cpp
  3. //
  4. // $Id: //poco/1.4/Foundation/src/LoggingFactory.cpp#3 $
  5. //
  6. // Library: Foundation
  7. // Package: Logging
  8. // Module: LoggingFactory
  9. //
  10. // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
  11. // and Contributors.
  12. //
  13. // SPDX-License-Identifier: BSL-1.0
  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/FormattingChannel.h"
  21. #include "Poco/SplitterChannel.h"
  22. #include "Poco/NullChannel.h"
  23. #if defined(POCO_OS_FAMILY_UNIX) && !defined(POCO_NO_SYSLOGCHANNEL)
  24. #include "Poco/SyslogChannel.h"
  25. #endif
  26. #if defined(POCO_OS_FAMILY_VMS)
  27. #include "Poco/OpcomChannel.h"
  28. #endif
  29. #if defined(POCO_OS_FAMILY_WINDOWS) && !defined(_WIN32_WCE)
  30. #include "Poco/EventLogChannel.h"
  31. #include "Poco/WindowsConsoleChannel.h"
  32. #endif
  33. #include "Poco/PatternFormatter.h"
  34. namespace Poco {
  35. LoggingFactory::LoggingFactory()
  36. {
  37. registerBuiltins();
  38. }
  39. LoggingFactory::~LoggingFactory()
  40. {
  41. }
  42. void LoggingFactory::registerChannelClass(const std::string& className, ChannelInstantiator* pFactory)
  43. {
  44. _channelFactory.registerClass(className, pFactory);
  45. }
  46. void LoggingFactory::registerFormatterClass(const std::string& className, FormatterFactory* pFactory)
  47. {
  48. _formatterFactory.registerClass(className, pFactory);
  49. }
  50. Channel* LoggingFactory::createChannel(const std::string& className) const
  51. {
  52. return _channelFactory.createInstance(className);
  53. }
  54. Formatter* LoggingFactory::createFormatter(const std::string& className) const
  55. {
  56. return _formatterFactory.createInstance(className);
  57. }
  58. namespace
  59. {
  60. static SingletonHolder<LoggingFactory> sh;
  61. }
  62. LoggingFactory& LoggingFactory::defaultFactory()
  63. {
  64. return *sh.get();
  65. }
  66. void LoggingFactory::registerBuiltins()
  67. {
  68. _channelFactory.registerClass("AsyncChannel", new Instantiator<AsyncChannel, Channel>);
  69. #if defined(POCO_OS_FAMILY_WINDOWS) && !defined(_WIN32_WCE)
  70. _channelFactory.registerClass("ConsoleChannel", new Instantiator<WindowsConsoleChannel, Channel>);
  71. _channelFactory.registerClass("ColorConsoleChannel", new Instantiator<WindowsColorConsoleChannel, Channel>);
  72. #else
  73. _channelFactory.registerClass("ConsoleChannel", new Instantiator<ConsoleChannel, Channel>);
  74. _channelFactory.registerClass("ColorConsoleChannel", new Instantiator<ColorConsoleChannel, Channel>);
  75. #endif
  76. #ifndef POCO_NO_FILECHANNEL
  77. _channelFactory.registerClass("FileChannel", new Instantiator<FileChannel, Channel>);
  78. #endif
  79. _channelFactory.registerClass("FormattingChannel", new Instantiator<FormattingChannel, Channel>);
  80. #ifndef POCO_NO_SPLITTERCHANNEL
  81. _channelFactory.registerClass("SplitterChannel", new Instantiator<SplitterChannel, Channel>);
  82. #endif
  83. _channelFactory.registerClass("NullChannel", new Instantiator<NullChannel, Channel>);
  84. #if defined(POCO_OS_FAMILY_UNIX)
  85. #ifndef POCO_NO_SYSLOGCHANNEL
  86. _channelFactory.registerClass("SyslogChannel", new Instantiator<SyslogChannel, Channel>);
  87. #endif
  88. #endif
  89. #if defined(POCO_OS_FAMILY_VMS)
  90. _channelFactory.registerClass("OpcomChannel", new Instantiator<OpcomChannel, Channel>);
  91. #endif
  92. #if defined(POCO_OS_FAMILY_WINDOWS) && !defined(_WIN32_WCE)
  93. _channelFactory.registerClass("EventLogChannel", new Instantiator<EventLogChannel, Channel>);
  94. #endif
  95. _formatterFactory.registerClass("PatternFormatter", new Instantiator<PatternFormatter, Formatter>);
  96. }
  97. } // namespace Poco