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.

93 lines
3.3 KiB

  1. // -*- C++ -*-
  2. // Copyright (C) 2009-2013, Vaclav Haisman. All rights reserved.
  3. //
  4. // Redistribution and use in source and binary forms, with or without modifica-
  5. // tion, are permitted provided that the following conditions are met:
  6. //
  7. // 1. Redistributions of source code must retain the above copyright notice,
  8. // this list of conditions and the following disclaimer.
  9. //
  10. // 2. Redistributions in binary form must reproduce the above copyright notice,
  11. // this list of conditions and the following disclaimer in the documentation
  12. // and/or other materials provided with the distribution.
  13. //
  14. // THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  15. // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  16. // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  17. // APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  18. // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
  19. // DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  20. // OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  21. // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  22. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  23. // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. #ifndef LOG4CPLUS_WIN32CONSOLEAPPENDER_H
  25. #define LOG4CPLUS_WIN32CONSOLEAPPENDER_H
  26. #include <log4cplus/config.hxx>
  27. #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE)
  28. #pragma once
  29. #endif
  30. #if defined(_WIN32) && defined (LOG4CPLUS_HAVE_WIN32_CONSOLE)
  31. #include <log4cplus/appender.h>
  32. namespace log4cplus
  33. {
  34. /**
  35. * Prints events to Win32 console.
  36. *
  37. * <h3>Properties</h3>
  38. * <dl>
  39. * <dt><tt>AllocConsole</tt></dt>
  40. * <dd>This boolean property specifies whether or not this appender
  41. * will try to allocate new console using the
  42. * <code>AllocConsole()</code> Win32 function.</dd>
  43. *
  44. * <dt><tt>logToStdErr</tt></dt>
  45. * <dd>When it is set true, the output will be into
  46. * <code>STD_ERROR_HANDLE</code> instead of <code>STD_OUTPUT_HANDLE</code>.
  47. * </dd>
  48. *
  49. * <dt><tt>TextColor</tt></dt>
  50. * <dd>See MSDN documentation for
  51. * <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms682088(v=vs.85).aspx#_win32_character_attributes">
  52. * Character Attributes</a>.
  53. * </dl>
  54. */
  55. class LOG4CPLUS_EXPORT Win32ConsoleAppender
  56. : public Appender
  57. {
  58. public:
  59. explicit Win32ConsoleAppender (bool allocConsole = true,
  60. bool logToStdErr = false, unsigned int textColor = 0);
  61. Win32ConsoleAppender (helpers::Properties const & properties);
  62. virtual ~Win32ConsoleAppender ();
  63. virtual void close ();
  64. protected:
  65. virtual void append (spi::InternalLoggingEvent const &);
  66. void write_handle (void *, tchar const *, std::size_t);
  67. void write_console (void *, tchar const *, std::size_t);
  68. bool alloc_console;
  69. bool log_to_std_err;
  70. unsigned int text_color;
  71. private:
  72. Win32ConsoleAppender (Win32ConsoleAppender const &);
  73. Win32ConsoleAppender & operator = (Win32ConsoleAppender const &);
  74. };
  75. } // namespace log4cplus
  76. #endif
  77. #endif // LOG4CPLUS_WIN32CONSOLEAPPENDER_H