log4cplus  1.1.0
win32consoleappender.h
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //  Copyright (C) 2009-2010, Vaclav Haisman. All rights reserved.
00003 //  
00004 //  Redistribution and use in source and binary forms, with or without modifica-
00005 //  tion, are permitted provided that the following conditions are met:
00006 //  
00007 //  1. Redistributions of  source code must  retain the above copyright  notice,
00008 //     this list of conditions and the following disclaimer.
00009 //  
00010 //  2. Redistributions in binary form must reproduce the above copyright notice,
00011 //     this list of conditions and the following disclaimer in the documentation
00012 //     and/or other materials provided with the distribution.
00013 //  
00014 //  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
00015 //  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
00016 //  FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
00017 //  APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
00018 //  INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
00019 //  DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
00020 //  OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
00021 //  ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
00022 //  (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
00023 //  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00024 
00025 #ifndef LOG4CPLUS_WIN32CONSOLEAPPENDER_H
00026 #define LOG4CPLUS_WIN32CONSOLEAPPENDER_H
00027 
00028 #include <log4cplus/config.hxx>
00029 
00030 #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE)
00031 #pragma once
00032 #endif
00033 
00034 #if defined(_WIN32) && defined (LOG4CPLUS_HAVE_WIN32_CONSOLE)
00035 
00036 #include <log4cplus/appender.h>
00037 
00038 
00039 namespace log4cplus
00040 {
00041 
00063     class LOG4CPLUS_EXPORT Win32ConsoleAppender
00064         : public Appender
00065     {
00066     public:
00067         explicit Win32ConsoleAppender (bool allocConsole = true,
00068             bool logToStdErr = false, unsigned int textColor = 0);
00069         Win32ConsoleAppender (helpers::Properties const & properties);
00070         virtual ~Win32ConsoleAppender ();
00071 
00072         virtual void close ();
00073 
00074     protected:
00075         virtual void append (spi::InternalLoggingEvent const &);
00076 
00077         void write_handle (void *, tchar const *, std::size_t);
00078         void write_console (void *, tchar const *, std::size_t);
00079 
00080         bool alloc_console;
00081         bool log_to_std_err;
00082         unsigned int text_color;
00083 
00084     private:
00085         Win32ConsoleAppender (Win32ConsoleAppender const &);
00086         Win32ConsoleAppender & operator = (Win32ConsoleAppender const &);
00087     };
00088 
00089 } // namespace log4cplus
00090 
00091 #endif
00092 
00093 #endif // LOG4CPLUS_WIN32CONSOLEAPPENDER_H