CLAW Library (a C++ Library Absolutely Wonderful) 1.5.5
log_stream.hpp
Go to the documentation of this file.
00001 /*
00002   CLAW - a C++ Library Absolutely Wonderful
00003 
00004   CLAW is a free library without any particular aim but being useful to 
00005   anyone.
00006 
00007   Copyright (C) 2005-2010 Julien Jorge
00008 
00009   This library is free software; you can redistribute it and/or
00010   modify it under the terms of the GNU Lesser General Public
00011   License as published by the Free Software Foundation; either
00012   version 2.1 of the License, or (at your option) any later version.
00013 
00014   This library is distributed in the hope that it will be useful,
00015   but WITHOUT ANY WARRANTY; without even the implied warranty of
00016   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017   Lesser General Public License for more details.
00018 
00019   You should have received a copy of the GNU Lesser General Public
00020   License along with this library; if not, write to the Free Software
00021   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00022 
00023   contact: julien_jorge@yahoo.fr
00024 */
00030 #ifndef __CLAW_LOG_STREAM_HPP__
00031 #define __CLAW_LOG_STREAM_HPP__
00032 
00033 #include <string>
00034 #include <fstream>
00035 #include <claw/non_copyable.hpp>
00036 
00037 #ifndef CLAW_LOGGER_EXPORT
00038 #  ifdef CLAW_LOGGER_NO_EXPORT
00039 #    define CLAW_LOGGER_EXPORT
00040 #  else
00041 #    ifdef _WIN32
00042 #      ifdef claw_logger_EXPORTS
00043 #        define CLAW_LOGGER_EXPORT __declspec(dllexport)
00044 #      else
00045 #        define CLAW_LOGGER_EXPORT __declspec(dllimport)
00046 #      endif // def claw_logger_EXPORTS
00047 #    else // def _WIN32
00048 #      define CLAW_LOGGER_EXPORT
00049 #    endif // def _WIN32
00050 #  endif // def CLAW_LOGGER_NO_EXPORT
00051 #endif // ndef CLAW_LOGGER_EXPORT
00052 
00053 namespace claw
00054 {
00059   class CLAW_LOGGER_EXPORT log_stream
00060   {
00061   public:
00062     virtual ~log_stream();
00063     virtual void write( const std::string& str ) = 0;
00064     virtual void flush();
00065   }; // class log_stream
00066 
00071   class CLAW_LOGGER_EXPORT console_logger
00072     : public log_stream,
00073       public pattern::non_copyable
00074   {
00075   public:
00076     virtual void write( const std::string& str );
00077     virtual void flush();
00078   }; // class console_logger
00079 
00084   class CLAW_LOGGER_EXPORT file_logger
00085     : public log_stream,
00086       public pattern::non_copyable
00087   {
00088   public:
00089     file_logger( const std::string& filename );
00090     virtual ~file_logger();
00091 
00092     virtual void write( const std::string& str );
00093     virtual void flush();
00094 
00095   private:
00097     std::ofstream* m_file;
00098 
00099   }; // class file_logger
00100 } // namespace claw
00101 
00102 #endif // __CLAW_LOG_STREAM_HPP__