1
//---------------------------------------------------------------------------
3
// Project: OpenWalnut ( http://www.openwalnut.org )
5
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6
// For more information see http://www.openwalnut.org/copying
8
// This file is part of OpenWalnut.
10
// OpenWalnut is free software: you can redistribute it and/or modify
11
// it under the terms of the GNU Lesser General Public License as published by
12
// the Free Software Foundation, either version 3 of the License, or
13
// (at your option) any later version.
15
// OpenWalnut is distributed in the hope that it will be useful,
16
// but WITHOUT ANY WARRANTY; without even the implied warranty of
17
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
// GNU Lesser General Public License for more details.
20
// You should have received a copy of the GNU Lesser General Public License
21
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
23
//---------------------------------------------------------------------------
28
#include <boost/algorithm/string.hpp>
30
#include "WTerminalColor.h"
32
#include "WLogEntry.h"
34
LogLevel logLevelFromString( const std::string& str )
36
// get lower-case version
37
std::string strLower = str; // NOTE: this reserves the needed space
38
std::transform( str.begin(), str.end(), strLower.begin(), tolower );
39
if( !strLower.compare( "debug" ) )
43
else if( !strLower.compare( "info" ) )
47
else if( !strLower.compare( "warning" ) )
51
else if( !strLower.compare( "error" ) )
58
WLogEntry::WLogEntry( std::string logTime, std::string message, LogLevel level, std::string source )
63
m_errorColor( WTerminalColor( WTerminalColor::Bold, WTerminalColor::FGRed ) ),
64
m_infoColor( WTerminalColor( WTerminalColor::Bold, WTerminalColor::FGGreen ) ),
65
m_debugColor( WTerminalColor( WTerminalColor::Bold, WTerminalColor::FGBlue ) ),
66
m_warningColor( WTerminalColor( WTerminalColor::Bold, WTerminalColor::FGYellow ) ),
67
m_sourceColor( WTerminalColor( WTerminalColor::Bold, WTerminalColor::FGMagenta ) ),
68
m_timeColor( WTerminalColor( WTerminalColor::Bold, WTerminalColor::FGBlack ) ),
69
m_messageColor( WTerminalColor() )
73
WLogEntry::~WLogEntry()
77
std::string WLogEntry::getLogString( std::string format, bool colors ) const
79
std::string s = format;
81
m_errorColor.setEnabled( colors );
82
m_infoColor.setEnabled( colors );
83
m_debugColor.setEnabled( colors );
84
m_warningColor.setEnabled( colors );
85
m_sourceColor.setEnabled( colors );
86
m_timeColor.setEnabled( colors );
87
m_messageColor.setEnabled( colors );
89
boost::ireplace_first( s, "%t", m_timeColor + m_time + !m_timeColor );
94
boost::ireplace_first( s, "%l", m_debugColor + "DEBUG " + !m_debugColor );
97
boost::ireplace_first( s, "%l", m_infoColor + "INFO " + !m_infoColor );
100
boost::ireplace_first( s, "%l", m_warningColor + "WARNING" + !m_warningColor );
103
boost::ireplace_first( s, "%l", m_errorColor + "ERROR " + !m_errorColor );
109
boost::ireplace_first( s, "%m", m_messageColor + m_message + !m_messageColor );
111
boost::ireplace_first( s, "%s", m_sourceColor + m_source + !m_sourceColor );
116
LogLevel WLogEntry::getLogLevel() const
121
std::string WLogEntry::getMessage() const
126
std::string WLogEntry::getSource() const
131
std::string WLogEntry::getTime() const