OpenWalnut  1.4.0
WLogStream.cpp
00001 //---------------------------------------------------------------------------
00002 //
00003 // Project: OpenWalnut ( http://www.openwalnut.org )
00004 //
00005 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
00006 // For more information see http://www.openwalnut.org/copying
00007 //
00008 // This file is part of OpenWalnut.
00009 //
00010 // OpenWalnut is free software: you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as published by
00012 // the Free Software Foundation, either version 3 of the License, or
00013 // (at your option) any later version.
00014 //
00015 // OpenWalnut is distributed in the hope that it will be useful,
00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 // GNU Lesser General Public License for more details.
00019 //
00020 // You should have received a copy of the GNU Lesser General Public License
00021 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
00022 //
00023 //---------------------------------------------------------------------------
00024 
00025 #include <string>
00026 
00027 #include "WLogStream.h"
00028 
00029 
00030 WLogStream::WLogStream( std::ostream& output, LogLevel logLevel, std::string format,  bool colored ): // NOLINT - we need this non-const ref here
00031     m_output( output ),
00032     m_logLevel( logLevel ),
00033     m_format( format ),
00034     m_color( colored )
00035 {
00036     // do nothing
00037 }
00038 
00039 void WLogStream::printEntry( const WLogEntry& entry )
00040 {
00041     // level test
00042     if( m_logLevel > entry.getLogLevel() )
00043     {
00044         return;
00045     }
00046 
00047     m_output << entry.getLogString( m_format, m_color );
00048     m_output.flush();
00049 }
00050 
00051 void WLogStream::setLogLevel( LogLevel logLevel )
00052 {
00053     m_logLevel = logLevel;
00054 }
00055 
00056 LogLevel WLogStream::getLogLevel() const
00057 {
00058     return m_logLevel;
00059 }
00060 
00061 void WLogStream::setFormat( std::string format )
00062 {
00063     m_format = format;
00064 }
00065 
00066 std::string WLogStream::getFormat() const
00067 {
00068     return m_format;
00069 }
00070 
00071 void WLogStream::setColored( bool colors )
00072 {
00073     m_color = colors;
00074 }
00075 
00076 bool WLogStream::isColored() const
00077 {
00078     return m_color;
00079 }
00080