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