consoleappender.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. // -*- C++ -*-
  2. // Module: Log4CPLUS
  3. // File: consoleappender.h
  4. // Created: 6/2001
  5. // Author: Tad E. Smith
  6. //
  7. //
  8. // Copyright 2001-2017 Tad E. Smith
  9. //
  10. // Licensed under the Apache License, Version 2.0 (the "License");
  11. // you may not use this file except in compliance with the License.
  12. // You may obtain a copy of the License at
  13. //
  14. // http://www.apache.org/licenses/LICENSE-2.0
  15. //
  16. // Unless required by applicable law or agreed to in writing, software
  17. // distributed under the License is distributed on an "AS IS" BASIS,
  18. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  19. // See the License for the specific language governing permissions and
  20. // limitations under the License.
  21. /** @file */
  22. #ifndef LOG4CPLUS_CONSOLE_APPENDER_HEADER_
  23. #define LOG4CPLUS_CONSOLE_APPENDER_HEADER_
  24. #include <log4cplus/config.hxx>
  25. #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE)
  26. #pragma once
  27. #endif
  28. #include <log4cplus/appender.h>
  29. #include <locale>
  30. namespace log4cplus {
  31. /**
  32. * ConsoleAppender appends log events to <code>std::cout</code> or
  33. * <code>std::cerr</code> using a layout specified by the
  34. * user. The default target is <code>std::cout</code>.
  35. *
  36. * <h3>Properties</h3>
  37. * <dl>
  38. * <dt><tt>logToStdErr</tt></dt>
  39. * <dd>When it is set true, the output stream will be
  40. * <code>std::cerr</code> instead of <code>std::cout</code>.</dd>
  41. *
  42. * <dt><tt>ImmediateFlush</tt></dt>
  43. * <dd>When it is set true, output stream will be flushed after
  44. * each appended event.</dd>
  45. *
  46. * <dt><tt>Locale</tt></dt>
  47. * <dd>This property specifies a locale name that will be imbued
  48. * into output stream. Locale can be specified either by system
  49. * specific locale name, e.g., <tt>en_US.UTF-8</tt>, or by one of
  50. * four recognized keywords: <tt>GLOBAL</tt>, <tt>DEFAULT</tt>
  51. * (which is an alias for <tt>GLOBAL</tt>), <tt>USER</tt> and
  52. * <tt>CLASSIC</tt>. When specified locale is not available,
  53. * <tt>GLOBAL</tt> is used instead. It is possible to register
  54. * additional locale keywords by registering an instance of
  55. * <code>spi::LocaleFactory</code> in
  56. * <code>spi::LocaleFactoryRegistry</code>.
  57. * \sa spi::getLocaleFactoryRegistry().
  58. *
  59. * Note: if <tt>Locale</tt> is set, <tt>ImmediateFlush</tt> will
  60. * be set to true automatically.
  61. * </dd>
  62. *
  63. * </dl>
  64. * \sa Appender
  65. */
  66. class LOG4CPLUS_EXPORT ConsoleAppender : public Appender {
  67. public:
  68. // Ctors
  69. ConsoleAppender(bool logToStdErr = false, bool immediateFlush = false);
  70. ConsoleAppender(const log4cplus::helpers::Properties & properties);
  71. // Dtor
  72. ~ConsoleAppender();
  73. // Methods
  74. virtual void close();
  75. //! This mutex is used by ConsoleAppender and helpers::LogLog
  76. //! classes to synchronize output to console.
  77. static log4cplus::thread::Mutex const & getOutputMutex();
  78. protected:
  79. virtual void append(const spi::InternalLoggingEvent& event);
  80. // Data
  81. bool logToStdErr;
  82. /**
  83. * Immediate flush means that the underlying output stream
  84. * will be flushed at the end of each append operation.
  85. */
  86. bool immediateFlush;
  87. std::unique_ptr<std::locale> locale;
  88. };
  89. } // end namespace log4cplus
  90. #endif // LOG4CPLUS_CONSOLE_APPENDER_HEADER_