You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

85 lines
2.4 KiB

  1. // -*- C++ -*-
  2. // Module: Log4CPLUS
  3. // File: consoleappender.h
  4. // Created: 6/2001
  5. // Author: Tad E. Smith
  6. //
  7. //
  8. // Copyright 2001-2009 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. namespace log4cplus {
  30. /**
  31. * ConsoleAppender appends log events to <code>std::cout</code> or
  32. * <code>std::cerr</code> using a layout specified by the
  33. * user. The default target is <code>std::cout</code>.
  34. *
  35. * <h3>Properties</h3>
  36. * <dl>
  37. * <dt><tt>logToStdErr</tt></dt>
  38. * <dd>When it is set true, the output stream will be
  39. * <code>std::cerr</code> instead of <code>std::cout</code>.</dd>
  40. *
  41. * <dt><tt>ImmediateFlush</tt></dt>
  42. * <dd>When it is set true, output stream will be flushed after
  43. * each appended event.</dd>
  44. *
  45. * </dl>
  46. * \sa Appender
  47. */
  48. class LOG4CPLUS_EXPORT ConsoleAppender : public Appender {
  49. public:
  50. // Ctors
  51. ConsoleAppender(bool logToStdErr = false, bool immediateFlush = false);
  52. ConsoleAppender(const log4cplus::helpers::Properties & properties);
  53. // Dtor
  54. ~ConsoleAppender();
  55. // Methods
  56. virtual void close();
  57. //! This mutex is used by ConsoleAppender and helpers::LogLog
  58. //! classes to synchronize output to console.
  59. static log4cplus::thread::Mutex const & getOutputMutex();
  60. protected:
  61. virtual void append(const spi::InternalLoggingEvent& event);
  62. // Data
  63. bool logToStdErr;
  64. /**
  65. * Immediate flush means that the underlying output stream
  66. * will be flushed at the end of each append operation.
  67. */
  68. bool immediateFlush;
  69. };
  70. } // end namespace log4cplus
  71. #endif // LOG4CPLUS_CONSOLE_APPENDER_HEADER_