LoggingFactory.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. //
  2. // LoggingFactory.h
  3. //
  4. // $Id: //poco/1.4/Foundation/include/Poco/LoggingFactory.h#1 $
  5. //
  6. // Library: Foundation
  7. // Package: Logging
  8. // Module: LoggingFactory
  9. //
  10. // Definition of the LoggingFactory class.
  11. //
  12. // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
  13. // and Contributors.
  14. //
  15. // SPDX-License-Identifier: BSL-1.0
  16. //
  17. #ifndef Foundation_LoggingFactory_INCLUDED
  18. #define Foundation_LoggingFactory_INCLUDED
  19. #include "Poco/Foundation.h"
  20. #include "Poco/DynamicFactory.h"
  21. #include "Poco/Channel.h"
  22. #include "Poco/Formatter.h"
  23. namespace Poco {
  24. class Foundation_API LoggingFactory
  25. /// An extensible factory for channels and formatters.
  26. ///
  27. /// The following channel classes are pre-registered:
  28. /// - AsyncChannel
  29. /// - ConsoleChannel
  30. /// - EventLogChannel (Windows platforms only)
  31. /// - FileChannel
  32. /// - FormattingChannel
  33. /// - NullChannel
  34. /// - OpcomChannel (OpenVMS only)
  35. /// - SplitterChannel
  36. /// - SyslogChannel (Unix platforms only)
  37. ///
  38. /// The following formatter classes are pre-registered:
  39. /// - PatternFormatter
  40. {
  41. public:
  42. typedef AbstractInstantiator<Channel> ChannelInstantiator;
  43. typedef AbstractInstantiator<Formatter> FormatterFactory;
  44. LoggingFactory();
  45. /// Creates the LoggingFactory.
  46. ///
  47. /// Automatically registers class factories for the
  48. /// built-in channel and formatter classes.
  49. ~LoggingFactory();
  50. /// Destroys the LoggingFactory.
  51. void registerChannelClass(const std::string& className, ChannelInstantiator* pFactory);
  52. /// Registers a channel class with the LoggingFactory.
  53. void registerFormatterClass(const std::string& className, FormatterFactory* pFactory);
  54. /// Registers a formatter class with the LoggingFactory.
  55. Channel* createChannel(const std::string& className) const;
  56. /// Creates a new Channel instance from specified class.
  57. ///
  58. /// Throws a NotFoundException if the specified channel class
  59. /// has not been registered.
  60. Formatter* createFormatter(const std::string& className) const;
  61. /// Creates a new Formatter instance from specified class.
  62. ///
  63. /// Throws a NotFoundException if the specified formatter class
  64. /// has not been registered.
  65. static LoggingFactory& defaultFactory();
  66. /// Returns a reference to the default
  67. /// LoggingFactory.
  68. private:
  69. void registerBuiltins();
  70. DynamicFactory<Channel> _channelFactory;
  71. DynamicFactory<Formatter> _formatterFactory;
  72. };
  73. } // namespace Poco
  74. #endif // Foundation_LoggingFactory_INCLUDED