Moved OpmLog from opm-parser to opm-common

This commit is contained in:
chflo
2016-03-17 12:32:37 +01:00
committed by Joakim Hove
parent a49f6ca00c
commit f2ed1ba7ea
36 changed files with 39 additions and 1376 deletions

View File

@@ -20,10 +20,10 @@
#include <iostream>
#include <memory>
#include <opm/parser/eclipse/OpmLog/CounterLog.hpp>
#include <opm/parser/eclipse/OpmLog/StreamLog.hpp>
#include <opm/parser/eclipse/OpmLog/LogUtil.hpp>
#include <opm/parser/eclipse/OpmLog/OpmLog.hpp>
#include <opm/common/OpmLog/CounterLog.hpp>
#include <opm/common/OpmLog/StreamLog.hpp>
#include <opm/common/OpmLog/LogUtil.hpp>
#include <opm/common/OpmLog/OpmLog.hpp>
#include <opm/parser/eclipse/Parser/Parser.hpp>
#include <opm/parser/eclipse/Parser/ParseContext.hpp>

View File

@@ -19,10 +19,10 @@
#include <iostream>
#include <opm/parser/eclipse/OpmLog/CounterLog.hpp>
#include <opm/parser/eclipse/OpmLog/StreamLog.hpp>
#include <opm/parser/eclipse/OpmLog/LogUtil.hpp>
#include <opm/parser/eclipse/OpmLog/OpmLog.hpp>
#include <opm/common/OpmLog/CounterLog.hpp>
#include <opm/common/OpmLog/StreamLog.hpp>
#include <opm/common/OpmLog/LogUtil.hpp>
#include <opm/common/OpmLog/OpmLog.hpp>
#include <opm/parser/eclipse/Parser/Parser.hpp>
#include <opm/parser/eclipse/Parser/ParseContext.hpp>

View File

@@ -1,6 +1,5 @@
include_directories(BEFORE ${PROJECT_BINARY_DIR}/generated-source/include)
add_subdirectory(OpmLog/tests)
add_subdirectory(Parser/tests)
add_subdirectory(Generator/tests)
add_subdirectory(RawDeck/tests)
@@ -20,16 +19,6 @@ add_subdirectory(Utility/tests)
add_subdirectory(Applications)
add_subdirectory(IntegrationTests)
set( log_source
OpmLog/TimerLog.cpp
OpmLog/CounterLog.cpp
OpmLog/LogUtil.cpp
OpmLog/Logger.cpp
OpmLog/LogBackend.cpp
OpmLog/StreamLog.cpp
OpmLog/EclipsePRTLog.cpp
OpmLog/OpmLog.cpp )
set( rawdeck_source
RawDeck/StarToken.cpp
RawDeck/RawKeyword.cpp
@@ -75,7 +64,6 @@ Parser/ParserIntItem.cpp
Parser/ParserDoubleItem.cpp
Parser/ParserStringItem.cpp
${generator_source}
${log_source}
)
set (state_source
@@ -145,15 +133,6 @@ Utility/Stringview.cpp
)
set( HEADER_FILES
OpmLog/LogBackend.hpp
OpmLog/TimerLog.hpp
OpmLog/CounterLog.hpp
OpmLog/Logger.hpp
OpmLog/OpmLog.hpp
OpmLog/LogUtil.hpp
OpmLog/StreamLog.hpp
OpmLog/EclipsePRTLog.hpp
#
RawDeck/RawConsts.hpp
RawDeck/RawKeyword.hpp
RawDeck/RawRecord.hpp
@@ -297,7 +276,7 @@ Utility/Functional.hpp
Utility/Stringview.hpp)
add_library(buildParser ${rawdeck_source} ${build_parser_source} ${deck_source} ${unit_source} ${generator_source} ${utility_source})
target_link_libraries(buildParser opmjson ${Boost_LIBRARIES} ${ERT_LIBRARIES})
target_link_libraries(buildParser opmjson ${opm-common_LIBRARIES} ${Boost_LIBRARIES} ${ERT_LIBRARIES})
#-----------------------------------------------------------------
# This section manages the generation of C++ code for the default keywords.
@@ -342,14 +321,14 @@ add_custom_target( generatedCode ALL COMMAND createDefaultKeywordList
)
opm_add_test( runInlineKeywordTest SOURCES ${PROJECT_BINARY_DIR}/generated-source/inlineKeywordTest.cpp
LIBRARIES opmparser ${Boost_LIBRARIES}
LIBRARIES opmparser ${opm-common_LIBRARIES} ${Boost_LIBRARIES}
DEPENDS generatedCode )
#-----------------------------------------------------------------
add_library(opmparser ${generated_source} ${state_source} ${rawdeck_source} ${parser_source} ${deck_source} ${unit_source} ${log_source} ${generator_source} ${utility_source})
add_library(opmparser ${generated_source} ${state_source} ${rawdeck_source} ${parser_source} ${deck_source} ${unit_source} ${generator_source} ${utility_source})
add_dependencies( opmparser generatedCode )
target_link_libraries(opmparser opmjson ${Boost_LIBRARIES} ${ERT_LIBRARIES})
target_link_libraries(opmparser opmjson ${opm-common_LIBRARIES} ${Boost_LIBRARIES} ${ERT_LIBRARIES})
set_target_properties(opmparser PROPERTIES VERSION ${opm-parser_VERSION_MAJOR}.${opm-parser_VERSION_MINOR}
SOVERSION ${opm-parser_VERSION_MAJOR})

View File

@@ -24,8 +24,8 @@
#include <set>
#include <string>
#include <opm/parser/eclipse/OpmLog/OpmLog.hpp>
#include <opm/parser/eclipse/OpmLog/LogUtil.hpp>
#include <opm/common/OpmLog/OpmLog.hpp>
#include <opm/common/OpmLog/LogUtil.hpp>
#include <opm/parser/eclipse/Deck/Deck.hpp>
#include <opm/parser/eclipse/Deck/DeckKeyword.hpp>

View File

@@ -26,8 +26,8 @@
#include <boost/test/unit_test.hpp>
#include <opm/common/utility/platform_dependent/reenable_warnings.h>
#include <opm/parser/eclipse/OpmLog/CounterLog.hpp>
#include <opm/parser/eclipse/OpmLog/OpmLog.hpp>
#include <opm/common/OpmLog/CounterLog.hpp>
#include <opm/common/OpmLog/OpmLog.hpp>
#include <opm/parser/eclipse/Deck/Deck.hpp>
#include <opm/parser/eclipse/Deck/DeckKeyword.hpp>

View File

@@ -19,6 +19,8 @@
#include <boost/algorithm/string/join.hpp>
#include <opm/common/OpmLog/OpmLog.hpp>
#include <opm/parser/eclipse/Deck/Section.hpp>
#include <opm/parser/eclipse/EclipseState/EclipseState.hpp>
#include <opm/parser/eclipse/EclipseState/Grid/Box.hpp>
@@ -37,7 +39,6 @@
#include <opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp>
#include <opm/parser/eclipse/EclipseState/SimulationConfig/SimulationConfig.hpp>
#include <opm/parser/eclipse/EclipseState/Tables/TableManager.hpp>
#include <opm/parser/eclipse/OpmLog/OpmLog.hpp>
#include <opm/parser/eclipse/Parser/ParserKeywords/M.hpp>
#include <opm/parser/eclipse/Units/Dimension.hpp>
#include <opm/parser/eclipse/Units/UnitSystem.hpp>

View File

@@ -24,8 +24,8 @@
#include <boost/lexical_cast.hpp>
#include <opm/parser/eclipse/OpmLog/OpmLog.hpp>
#include <opm/parser/eclipse/OpmLog/LogUtil.hpp>
#include <opm/common/OpmLog/OpmLog.hpp>
#include <opm/common/OpmLog/LogUtil.hpp>
#include <opm/parser/eclipse/Deck/Section.hpp>
#include <opm/parser/eclipse/Deck/Deck.hpp>
#include <opm/parser/eclipse/Deck/DeckItem.hpp>

View File

@@ -24,13 +24,10 @@
#include <vector>
#include <unordered_map>
#include <opm/common/OpmLog/OpmLog.hpp>
#include <opm/parser/eclipse/EclipseState/Grid/EclipseGrid.hpp>
#include <opm/parser/eclipse/EclipseState/Grid/GridProperty.hpp>
#include <opm/parser/eclipse/OpmLog/OpmLog.hpp>
#include <opm/parser/eclipse/OpmLog/LogUtil.hpp>
#include <opm/parser/eclipse/OpmLog/OpmLog.hpp>
#include <opm/parser/eclipse/OpmLog/LogUtil.hpp>
/*
This class implements a container (std::unordered_map<std::string ,

View File

@@ -421,7 +421,7 @@ BOOST_AUTO_TEST_CASE(GridPropertyPostProcessors) {
typedef Opm::GridPropertySupportedKeywordInfo<double> SupportedKeywordInfo;
Opm::DeckPtr deck = createDeck();
Opm::EclipseState st( deck, Opm::ParseMode() ) ;
Opm::EclipseState st( deck, Opm::ParseContext() ) ;
std::shared_ptr<Opm::EclipseGrid> grid = std::make_shared<Opm::EclipseGrid>(deck);
SupportedKeywordInfo kwInfo1("MULTPV" , 1.0 , "1");

View File

@@ -24,8 +24,8 @@
#include <boost/algorithm/string.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <opm/parser/eclipse/OpmLog/OpmLog.hpp>
#include <opm/parser/eclipse/OpmLog/LogUtil.hpp>
#include <opm/common/OpmLog/OpmLog.hpp>
#include <opm/common/OpmLog/LogUtil.hpp>
#include <opm/parser/eclipse/Deck/DeckItem.hpp>
#include <opm/parser/eclipse/Deck/DeckKeyword.hpp>
#include <opm/parser/eclipse/Deck/DeckRecord.hpp>

View File

@@ -20,7 +20,7 @@
#include <opm/parser/eclipse/Deck/Section.hpp>
#include <opm/parser/eclipse/EclipseState/Grid/GridProperties.hpp>
#include <opm/parser/eclipse/EclipseState/SimulationConfig/ThresholdPressure.hpp>
#include <opm/parser/eclipse/OpmLog/OpmLog.hpp>
#include <opm/common/OpmLog/OpmLog.hpp>
#include <opm/parser/eclipse/Parser/ParseContext.hpp>
#include <opm/parser/eclipse/Parser/ParserKeywords/E.hpp>
#include <opm/parser/eclipse/Parser/ParserKeywords/R.hpp>

View File

@@ -23,7 +23,7 @@
#include <opm/parser/eclipse/Parser/ParserKeywords/T.hpp>
#include <opm/parser/eclipse/Deck/Deck.hpp>
#include <opm/parser/eclipse/EclipseState/Tables/TableManager.hpp>
#include <opm/parser/eclipse/OpmLog/OpmLog.hpp>
#include <opm/common/OpmLog/OpmLog.hpp>
#include <opm/parser/eclipse/Parser/ParserKeywords/E.hpp>
#include <opm/parser/eclipse/Parser/ParserKeywords/M.hpp>
#include <opm/parser/eclipse/Parser/ParserKeywords/P.hpp>

View File

@@ -39,8 +39,8 @@
#include <opm/parser/eclipse/EclipseState/Tables/VFPInjTable.hpp>
#include <opm/parser/eclipse/EclipseState/Tables/VFPProdTable.hpp>
#include <opm/parser/eclipse/OpmLog/OpmLog.hpp>
#include <opm/parser/eclipse/OpmLog/LogUtil.hpp>
#include <opm/common/OpmLog/OpmLog.hpp>
#include <opm/common/OpmLog/LogUtil.hpp>
namespace Opm {

View File

@@ -18,8 +18,8 @@
*/
#include "checkDeck.hpp"
#include <opm/parser/eclipse/OpmLog/OpmLog.hpp>
#include <opm/parser/eclipse/OpmLog/LogUtil.hpp>
#include <opm/common/OpmLog/OpmLog.hpp>
#include <opm/common/OpmLog/LogUtil.hpp>
#include <opm/parser/eclipse/Deck/DeckKeyword.hpp>
#include <opm/parser/eclipse/Deck/Section.hpp>

View File

@@ -28,9 +28,8 @@
#include <boost/date_time/posix_time/posix_time.hpp>
#include <opm/common/utility/platform_dependent/reenable_warnings.h>
#include <opm/parser/eclipse/OpmLog/CounterLog.hpp>
#include <opm/parser/eclipse/OpmLog/LogUtil.hpp>
#include <opm/parser/eclipse/OpmLog/OpmLog.hpp>
#include <opm/common/OpmLog/OpmLog.hpp>
#include <opm/common/OpmLog/CounterLog.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/ScheduleEnums.hpp>

View File

@@ -1,64 +0,0 @@
/*
Copyright 2014 Andreas Lauser
This file is part of the Open Porous Media project (OPM).
OPM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OPM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OPM. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdexcept>
#include <sstream>
#include <cassert>
#include <opm/parser/eclipse/OpmLog/OpmLog.hpp>
#include <opm/parser/eclipse/OpmLog/LogUtil.hpp>
#include <opm/parser/eclipse/OpmLog/CounterLog.hpp>
namespace Opm {
CounterLog::CounterLog(int64_t messageTypes) : LogBackend(messageTypes)
{ }
CounterLog::CounterLog() : LogBackend(Log::DefaultMessageTypes)
{ }
size_t CounterLog::numMessages(int64_t messageType) const {
if (Log::isPower2( messageType )) {
auto iter = m_count.find( messageType );
if (iter == m_count.end())
return 0;
else
return (*iter).second;
} else
throw std::invalid_argument("The messageType ID must be 2^n");
}
void CounterLog::addMessage(int64_t messageType , const std::string& ) {
if (includeMessage( messageType ))
m_count[messageType]++;
}
void CounterLog::clear()
{
m_count.clear();
}
} // namespace Opm

View File

@@ -1,57 +0,0 @@
/*
Copyright 2014 Andreas Lauser
This file is part of the Open Porous Media project (OPM).
OPM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OPM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OPM. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef OPM_COUNTERLOG_HPP
#define OPM_COUNTERLOG_HPP
#include <string>
#include <memory>
#include <map>
#include <opm/parser/eclipse/OpmLog/LogBackend.hpp>
namespace Opm {
/*!
* \brief Provides a simple sytem for log message which are found by the
* Parser/Deck/EclipseState classes during processing the deck.
*/
class CounterLog : public LogBackend {
public:
CounterLog(int64_t messageMask);
CounterLog();
size_t numMessages(int64_t messageType) const;
void addMessage(int64_t messageFlag ,
const std::string& message);
void clear();
~CounterLog() {};
private:
std::map<int64_t , size_t> m_count;
};
typedef std::shared_ptr<CounterLog> CounterLogPtr;
typedef std::shared_ptr<const CounterLog> CounterLogConstPtr;
} // namespace Opm
#endif

View File

@@ -1,59 +0,0 @@
/*
Copyright 2016 Statoil ASA.
This file is part of the Open Porous Media project (OPM).
OPM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OPM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OPM. If not, see <http://www.gnu.org/licenses/>.
*/
#include <opm/parser/eclipse/OpmLog/EclipsePRTLog.hpp>
#include <opm/parser/eclipse/OpmLog/LogUtil.hpp>
namespace Opm {
void EclipsePRTLog::addMessage(int64_t messageType, const std::string& message)
{
StreamLog::addMessage(messageType, message);
m_count[messageType]++;
}
size_t EclipsePRTLog::numMessages(int64_t messageType) const
{
if (Log::isPower2( messageType )) {
auto iter = m_count.find( messageType );
if (iter == m_count.end())
return 0;
else
return (*iter).second;
} else
throw std::invalid_argument("The messageType ID must be 2^n");
}
EclipsePRTLog::~EclipsePRTLog()
{
//output summary.
const std::string summary_msg = "\n\nError summary:" +
std::string("\nWarnings " + std::to_string(numMessages(Log::MessageType::Warning))) +
std::string("\nProblems " + std::to_string(numMessages(Log::MessageType::Problem))) +
std::string("\nErrors " + std::to_string(numMessages(Log::MessageType::Error))) +
std::string("\nBugs " + std::to_string(numMessages(Log::MessageType::Bug))) +
std::string("\nDebug " + std::to_string(numMessages(Log::MessageType::Debug))) +
std::string("\nProblems " + std::to_string(numMessages(Log::MessageType::Problem))) +"\n";
addMessage(Log::MessageType::Info, summary_msg);
}
}

View File

@@ -1,44 +0,0 @@
/*
Copyright 2016 Statoil ASA.
This file is part of the Open Porous Media project (OPM).
OPM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OPM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OPM. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ECLIPSEPRTLOG_H
#define ECLIPSEPRTLOG_H
#include <map>
#include <string>
#include <opm/parser/eclipse/OpmLog/StreamLog.hpp>
namespace Opm {
class EclipsePRTLog : public StreamLog {
public:
using StreamLog::StreamLog;
void addMessage(int64_t messageType, const std::string& message);
size_t numMessages(int64_t messageType) const;
~EclipsePRTLog();
private:
std::map<int64_t, size_t> m_count;
};
}
#endif // ECLIPSEPRTLOG_H

View File

@@ -1,44 +0,0 @@
/*
Copyright 2015 Statoil ASA.
This file is part of the Open Porous Media project (OPM).
OPM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OPM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OPM. If not, see <http://www.gnu.org/licenses/>.
*/
#include <cstdint>
#include <opm/parser/eclipse/OpmLog/LogBackend.hpp>
namespace Opm {
LogBackend::LogBackend( int64_t mask ) :
m_mask(mask)
{
}
bool LogBackend::includeMessage(int64_t messageFlag) {
if (((messageFlag & m_mask) == messageFlag) &&
(messageFlag > 0))
return true;
else
return false;
}
int64_t LogBackend::getMask() const {
return m_mask;
}
}

View File

@@ -1,45 +0,0 @@
/*
Copyright 2015 Statoil ASA.
This file is part of the Open Porous Media project (OPM).
OPM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OPM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OPM. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef OPM_LOGBACKEND_HPP
#define OPM_LOGBACKEND_HPP
#include <cstdint>
#include <string>
namespace Opm {
class LogBackend {
public:
LogBackend( int64_t mask );
virtual ~LogBackend() { };
virtual void addMessage(int64_t , const std::string& ) { };
int64_t getMask() const;
bool includeMessage(int64_t messageFlag);
private:
int64_t m_mask;
};
}
#endif

View File

@@ -1,76 +0,0 @@
/*
Copyright 2015 Statoil ASA.
This file is part of the Open Porous Media project (OPM).
OPM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OPM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OPM. If not, see <http://www.gnu.org/licenses/>.
*/
#include <sstream>
#include <stdexcept>
#include <opm/parser/eclipse/OpmLog/LogUtil.hpp>
namespace Opm {
namespace Log {
bool isPower2(int64_t x) {
return ((x != 0) && !(x & (x - 1)));
}
std::string fileMessage(const std::string& filename , int line , const std::string& message) {
std::ostringstream oss;
oss << filename << ":" << line << ": " << message;
return oss.str();
}
std::string fileMessage(int64_t messageType , const std::string& filename , int line , const std::string& message) {
return fileMessage( filename , line , prefixMessage( messageType , message ));
}
std::string prefixMessage(int64_t messageType, const std::string& message) {
std::string prefix;
switch (messageType) {
case MessageType::Debug:
prefix = "debug";
break;
case MessageType::Info:
prefix = "info";
break;
case MessageType::Warning:
prefix = "warning";
break;
case MessageType::Error:
prefix = "error";
break;
case MessageType::Problem:
prefix = "problem";
break;
case MessageType::Bug:
prefix = "bug";
break;
default:
throw std::invalid_argument("Unhandled messagetype");
}
return prefix + ": " + message;
}
}
}

View File

@@ -1,47 +0,0 @@
/*
Copyright 2015 Statoil ASA.
This file is part of the Open Porous Media project (OPM).
OPM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OPM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OPM. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef OPM_LOG_UTIL_HPP
#define OPM_LOG_UTIL_HPP
#include <cstdint>
#include <string>
namespace Opm {
namespace Log {
namespace MessageType {
const int64_t Debug = 1; /* Excessive information */
const int64_t Info = 2; /* Normal status information */
const int64_t Warning = 4; /* Input anomaly - possible error */
const int64_t Error = 8; /* Error in the input data - should probably exit. */
const int64_t Problem = 16; /* Calculation problems - e.g. convergence failure. */
const int64_t Bug = 32; /* An inconsistent state has been encountered in the simulator - should probably exit. */
}
const int64_t DefaultMessageTypes = MessageType::Debug + MessageType::Info + MessageType::Warning + MessageType::Error + MessageType::Problem + MessageType::Bug;
bool isPower2(int64_t x);
std::string fileMessage(const std::string& path, int line , const std::string& msg);
std::string fileMessage(int64_t messageType , const std::string& path, int line , const std::string& msg);
std::string prefixMessage(int64_t messageType , const std::string& msg);
}
}
#endif

View File

@@ -1,114 +0,0 @@
/*
Copyright 2015 Statoil ASA.
This file is part of the Open Porous Media project (OPM).
OPM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OPM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OPM. If not, see <http://www.gnu.org/licenses/>.
*/
#include <sstream>
#include <stdexcept>
#include <iostream>
#include <opm/parser/eclipse/OpmLog/LogBackend.hpp>
#include <opm/parser/eclipse/OpmLog/Logger.hpp>
#include <opm/parser/eclipse/OpmLog/LogUtil.hpp>
namespace Opm {
Logger::Logger()
: m_globalMask(0),
m_enabledTypes(0)
{
addMessageType( Log::MessageType::Debug , "debug");
addMessageType( Log::MessageType::Info , "info");
addMessageType( Log::MessageType::Warning , "warning");
addMessageType( Log::MessageType::Error , "error");
addMessageType( Log::MessageType::Problem , "problem");
addMessageType( Log::MessageType::Bug , "bug");
}
void Logger::addMessage(int64_t messageType , const std::string& message) const {
if ((m_enabledTypes & messageType) == 0)
throw std::invalid_argument("Tried to issue message with unrecognized message ID");
if (m_globalMask & messageType) {
for (auto iter = m_backends.begin(); iter != m_backends.end(); ++iter) {
std::shared_ptr<LogBackend> backend = (*iter).second;
backend->addMessage( messageType , message );
}
}
}
void Logger::updateGlobalMask( int64_t mask ) {
m_globalMask |= mask;
}
bool Logger::hasBackend(const std::string& name) {
if (m_backends.find( name ) == m_backends.end())
return false;
else
return true;
}
bool Logger::removeBackend(const std::string& name) {
size_t eraseCount = m_backends.erase( name );
if (eraseCount == 1)
return true;
else
return false;
}
void Logger::addBackend(const std::string& name , std::shared_ptr<LogBackend> backend) {
updateGlobalMask( backend->getMask() );
m_backends[ name ] = backend;
}
int64_t Logger::enabledMessageTypes() const {
return m_enabledTypes;
}
//static:
bool Logger::enabledMessageType( int64_t enabledTypes , int64_t messageType) {
if (Log::isPower2( messageType)) {
if ((messageType & enabledTypes) == 0)
return false;
else
return true;
} else
throw std::invalid_argument("The message type id must be ~ 2^n");
}
//static:
bool Logger::enabledDefaultMessageType( int64_t messageType) {
return enabledMessageType( Log::DefaultMessageTypes , messageType );
}
bool Logger::enabledMessageType( int64_t messageType) const {
return enabledMessageType( m_enabledTypes , messageType );
}
void Logger::addMessageType( int64_t messageType , const std::string& /* prefix */) {
if (Log::isPower2( messageType)) {
m_enabledTypes |= messageType;
} else
throw std::invalid_argument("The message type id must be ~ 2^n");
}
}

View File

@@ -1,80 +0,0 @@
/*
Copyright 2015 Statoil ASA.
This file is part of the Open Porous Media project (OPM).
OPM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OPM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OPM. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef OPM_LOGGER_HPP
#define OPM_LOGGER_HPP
#include <stdexcept>
#include <cstdint>
#include <map>
#include <memory>
#include <string>
namespace Opm {
class LogBackend;
class Logger {
public:
Logger();
void addMessage(int64_t messageType , const std::string& message) const;
static bool enabledDefaultMessageType( int64_t messageType);
bool enabledMessageType( int64_t messageType) const;
void addMessageType( int64_t messageType , const std::string& prefix);
int64_t enabledMessageTypes() const;
void addBackend(const std::string& name , std::shared_ptr<LogBackend> backend);
bool hasBackend(const std::string& name);
bool removeBackend(const std::string& name);
template <class BackendType>
std::shared_ptr<BackendType> getBackend(const std::string& name) const {
auto pair = m_backends.find( name );
if (pair == m_backends.end())
throw std::invalid_argument("Invalid backend name: " + name);
else
return std::static_pointer_cast<BackendType>(m_backends.find(name)->second);
}
template <class BackendType>
std::shared_ptr<BackendType> popBackend(const std::string& name) {
auto pair = m_backends.find( name );
if (pair == m_backends.end())
throw std::invalid_argument("Invalid backend name: " + name);
else {
std::shared_ptr<LogBackend> backend = (*pair).second;
removeBackend( name );
return std::static_pointer_cast<BackendType>(backend);
}
}
private:
void updateGlobalMask( int64_t mask );
static bool enabledMessageType( int64_t enabledTypes , int64_t messageType);
int64_t m_globalMask;
int64_t m_enabledTypes;
std::map<std::string , std::shared_ptr<LogBackend> > m_backends;
};
}
#endif

View File

@@ -1,120 +0,0 @@
/*
Copyright 2014 Statoil ASA.
This file is part of the Open Porous Media project (OPM).
OPM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OPM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OPM. If not, see <http://www.gnu.org/licenses/>.
*/
#include <opm/parser/eclipse/OpmLog/OpmLog.hpp>
#include <opm/parser/eclipse/OpmLog/Logger.hpp>
namespace Opm {
std::shared_ptr<Logger> OpmLog::getLogger() {
if (!m_logger)
m_logger.reset( new Logger() );
return m_logger;
}
void OpmLog::addMessage(int64_t messageFlag , const std::string& message) {
if (m_logger)
m_logger->addMessage( messageFlag , message );
}
void OpmLog::info(const std::string& message)
{
const std::string msg = Log::prefixMessage(Log::MessageType::Info, message);
addMessage(Log::MessageType::Info, msg);
}
void OpmLog::warning(const std::string& message)
{
const std::string msg = Log::prefixMessage(Log::MessageType::Warning, message);
addMessage(Log::MessageType::Warning, msg);
}
void OpmLog::problem(const std::string& message)
{
const std::string msg = Log::prefixMessage(Log::MessageType::Problem, message);
addMessage(Log::MessageType::Problem, msg);
}
void OpmLog::error(const std::string& message)
{
const std::string msg = Log::prefixMessage(Log::MessageType::Error, message);
addMessage(Log::MessageType::Error, msg);
}
void OpmLog::bug(const std::string& message)
{
const std::string msg = Log::prefixMessage(Log::MessageType::Bug, message);
addMessage(Log::MessageType::Bug, msg);
}
void OpmLog::debug(const std::string& message)
{
const std::string msg = Log::prefixMessage(Log::MessageType::Debug, message);
addMessage(Log::MessageType::Debug, msg);
}
bool OpmLog::enabledMessageType( int64_t messageType ) {
if (m_logger)
return m_logger->enabledMessageType( messageType );
else
return Logger::enabledDefaultMessageType( messageType );
}
bool OpmLog::hasBackend(const std::string& name) {
if (m_logger)
return m_logger->hasBackend( name );
else
return false;
}
bool OpmLog::removeBackend(const std::string& name) {
if (m_logger)
return m_logger->removeBackend( name );
else
return false;
}
void OpmLog::addMessageType( int64_t messageType , const std::string& prefix) {
auto logger = OpmLog::getLogger();
logger->addMessageType( messageType , prefix );
}
void OpmLog::addBackend(const std::string& name , std::shared_ptr<LogBackend> backend) {
auto logger = OpmLog::getLogger();
return logger->addBackend( name , backend );
}
/******************************************************************/
std::shared_ptr<Logger> OpmLog::m_logger;
}

View File

@@ -1,81 +0,0 @@
/*
Copyright 2014 Statoil ASA.
This file is part of the Open Porous Media project (OPM).
OPM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OPM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OPM. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef OPMLOG_HPP
#define OPMLOG_HPP
#include <memory>
#include <cstdint>
#include <opm/parser/eclipse/OpmLog/Logger.hpp>
#include <opm/parser/eclipse/OpmLog/LogUtil.hpp>
namespace Opm {
class LogBackend;
/*
The OpmLog class is a fully static class which manages a proper
Logger instance.
*/
class OpmLog {
public:
static void addMessage(int64_t messageFlag , const std::string& message);
static void info(const std::string& message);
static void warning(const std::string& message);
static void error(const std::string& message);
static void problem(const std::string& message);
static void bug(const std::string& message);
static void debug(const std::string& message);
static bool hasBackend( const std::string& backendName );
static void addBackend(const std::string& name , std::shared_ptr<LogBackend> backend);
static bool removeBackend(const std::string& name);
static bool enabledMessageType( int64_t messageType );
static void addMessageType( int64_t messageType , const std::string& prefix);
template <class BackendType>
static std::shared_ptr<BackendType> getBackend(const std::string& name) {
auto logger = OpmLog::getLogger();
return logger->getBackend<BackendType>(name);
}
template <class BackendType>
static std::shared_ptr<BackendType> popBackend(const std::string& name) {
auto logger = OpmLog::getLogger();
return logger->popBackend<BackendType>(name);
}
private:
static std::shared_ptr<Logger> getLogger();
static std::shared_ptr<Logger> m_logger;
};
}
#endif

View File

@@ -1,61 +0,0 @@
/*
Copyright 2015 Statoil ASA.
This file is part of the Open Porous Media project (OPM).
OPM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OPM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OPM. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdexcept>
#include <opm/parser/eclipse/OpmLog/StreamLog.hpp>
namespace Opm {
StreamLog::StreamLog(const std::string& logFile , int64_t messageMask) : LogBackend(messageMask)
{
m_ofstream.open( logFile.c_str() , std::ofstream::out );
m_streamOwner = true;
m_ostream = &m_ofstream;
}
StreamLog::StreamLog(std::ostream& os , int64_t messageMask) : LogBackend(messageMask)
{
m_ostream = &os;
m_streamOwner = false;
}
void StreamLog::close() {
if (m_streamOwner && m_ofstream.is_open()) {
m_ofstream.close();
m_ostream = NULL;
}
}
void StreamLog::addMessage(int64_t messageType , const std::string& message) {
if (includeMessage( messageType )) {
(*m_ostream) << message << std::endl;
if (m_ofstream.is_open())
m_ofstream.flush();
}
}
StreamLog::~StreamLog() {
close();
}
}

View File

@@ -1,48 +0,0 @@
/*
Copyright 2015 Statoil ASA.
This file is part of the Open Porous Media project (OPM).
OPM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OPM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OPM. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef STREAMLOG_H
#define STREAMLOG_H
#include <fstream>
#include <iostream>
#include <cstdint>
#include <opm/parser/eclipse/OpmLog/LogBackend.hpp>
namespace Opm {
class StreamLog : public LogBackend {
public:
StreamLog(const std::string& logFile , int64_t messageMask);
StreamLog(std::ostream& os , int64_t messageMask);
void addMessage(int64_t messageType , const std::string& message);
~StreamLog();
private:
void close();
std::ofstream m_ofstream;
std::ostream * m_ostream;
bool m_streamOwner;
};
}
#endif

View File

@@ -1,60 +0,0 @@
/*
Copyright 2014 Statoil ASA.
This file is part of the Open Porous Media project (OPM).
OPM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OPM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OPM. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdexcept>
#include <cassert>
#include <iomanip>
#include <opm/parser/eclipse/OpmLog/OpmLog.hpp>
#include <opm/parser/eclipse/OpmLog/LogUtil.hpp>
#include <opm/parser/eclipse/OpmLog/TimerLog.hpp>
#include <opm/parser/eclipse/OpmLog/StreamLog.hpp>
namespace Opm {
TimerLog::TimerLog(const std::string& logFile) : StreamLog( logFile , StopTimer | StartTimer )
{
m_work.precision(8);
}
TimerLog::TimerLog(std::ostream& os) : StreamLog( os , StopTimer | StartTimer )
{
m_work.precision(8);
}
void TimerLog::addMessage(int64_t messageType , const std::string& msg ) {
if (messageType == StopTimer) {
clock_t stop = clock();
double secondsElapsed = 1.0 * (m_start - stop) / CLOCKS_PER_SEC ;
m_work.str("");
m_work << std::fixed << msg << ": " << secondsElapsed << " seconds ";
StreamLog::addMessage( messageType , m_work.str());
} else {
if (messageType == StartTimer)
m_start = clock();
}
}
} // namespace Opm

View File

@@ -1,60 +0,0 @@
/*
Copyright 2014 Statoil ASA.
This file is part of the Open Porous Media project (OPM).
OPM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OPM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OPM. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef OPM_TIMERLOG_HPP
#define OPM_TIMERLOG_HPP
#include <time.h>
#include <memory>
#include <sstream>
#include <string>
#include <opm/parser/eclipse/OpmLog/StreamLog.hpp>
/*
This class is a simple demonstration of how the logging framework
can be used to create a simple very special case logging facility.
*/
namespace Opm {
class TimerLog : public StreamLog {
public:
static const int64_t StartTimer = 4096;
static const int64_t StopTimer = 8192;
TimerLog(const std::string& logFile);
TimerLog(std::ostream& os);
void addMessage(int64_t messageFlag ,
const std::string& message);
void clear();
~TimerLog() {};
private:
clock_t m_start;
std::ostringstream m_work;
};
typedef std::shared_ptr<TimerLog> TimerLogPtr;
typedef std::shared_ptr<const TimerLog> TimerLogConstPtr;
} // namespace Opm
#endif

View File

@@ -1,3 +0,0 @@
opm_add_test(runOpmLogTests SOURCES OpmLogTests.cpp
EXE_NAME runOpmLogTests
LIBRARIES opmparser ${Boost_LIBRARIES})

View File

@@ -1,250 +0,0 @@
/*
Copyright 2013 Statoil ASA.
This file is part of the Open Porous Media project (OPM).
OPM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OPM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OPM. If not, see <http://www.gnu.org/licenses/>.
*/
#define BOOST_TEST_MODULE LogTests
#include <opm/common/utility/platform_dependent/disable_warnings.h>
#include <boost/test/unit_test.hpp>
#include <opm/common/utility/platform_dependent/reenable_warnings.h>
#include <stdexcept>
#include <iostream>
#include <sstream>
#include <opm/parser/eclipse/OpmLog/OpmLog.hpp>
#include <opm/parser/eclipse/OpmLog/LogBackend.hpp>
#include <opm/parser/eclipse/OpmLog/CounterLog.hpp>
#include <opm/parser/eclipse/OpmLog/TimerLog.hpp>
#include <opm/parser/eclipse/OpmLog/StreamLog.hpp>
#include <opm/parser/eclipse/OpmLog/LogUtil.hpp>
using namespace Opm;
BOOST_AUTO_TEST_CASE(DoLogging) {
OpmLog::addMessage(Log::MessageType::Warning , "Warning1");
OpmLog::addMessage(Log::MessageType::Warning , "Warning2");
}
BOOST_AUTO_TEST_CASE(Test_Format) {
BOOST_CHECK_EQUAL( "/path/to/file:100: There is a mild fuckup here?" , Log::fileMessage("/path/to/file" , 100 , "There is a mild fuckup here?"));
BOOST_CHECK_EQUAL( "error: This is the error" , Log::prefixMessage(Log::MessageType::Error , "This is the error"));
BOOST_CHECK_EQUAL( "warning: This is the warning" , Log::prefixMessage(Log::MessageType::Warning , "This is the warning"));
BOOST_CHECK_EQUAL( "info: This is the info" , Log::prefixMessage(Log::MessageType::Info , "This is the info"));
}
BOOST_AUTO_TEST_CASE(Test_AbstractBackend) {
int64_t mask = 1+4+16;
LogBackend backend(mask);
BOOST_CHECK_EQUAL(false , backend.includeMessage(0 ));
BOOST_CHECK_EQUAL(true , backend.includeMessage(1 ));
BOOST_CHECK_EQUAL(false , backend.includeMessage(2 ));
BOOST_CHECK_EQUAL(true , backend.includeMessage(4 ));
BOOST_CHECK_EQUAL(false , backend.includeMessage(8 ));
BOOST_CHECK_EQUAL(true , backend.includeMessage(16 ));
BOOST_CHECK_EQUAL(false, backend.includeMessage(6 ));
BOOST_CHECK_EQUAL(true , backend.includeMessage(5 ));
}
BOOST_AUTO_TEST_CASE(Test_Logger) {
Logger logger;
std::ostringstream log_stream;
std::shared_ptr<CounterLog> counter = std::make_shared<CounterLog>();
std::shared_ptr<StreamLog> streamLog = std::make_shared<StreamLog>( log_stream , Log::MessageType::Warning );
BOOST_CHECK_EQUAL( false , logger.hasBackend("NO"));
logger.addBackend("COUNTER" , counter);
logger.addBackend("STREAM" , streamLog);
BOOST_CHECK_EQUAL( true , logger.hasBackend("COUNTER"));
BOOST_CHECK_EQUAL( true , logger.hasBackend("STREAM"));
logger.addMessage( Log::MessageType::Error , "Error");
logger.addMessage( Log::MessageType::Warning , "Warning");
BOOST_CHECK_EQUAL( 1U , counter->numMessages(Log::MessageType::Error) );
BOOST_CHECK_EQUAL( 1U , counter->numMessages(Log::MessageType::Warning) );
BOOST_CHECK_EQUAL( 0U , counter->numMessages(Log::MessageType::Info) );
BOOST_CHECK_EQUAL( log_stream.str() , "Warning\n");
BOOST_CHECK_THROW( logger.getBackend<LogBackend>("No") , std::invalid_argument );
{
auto counter2 = logger.getBackend<CounterLog>("COUNTER");
BOOST_CHECK_EQUAL( 1U , counter2->numMessages( Log::MessageType::Warning));
BOOST_CHECK_EQUAL( 1U , counter2->numMessages( Log::MessageType::Error));
BOOST_CHECK_EQUAL( 0 , counter2->numMessages( Log::MessageType::Info));
}
BOOST_CHECK_EQUAL( false , logger.removeBackend("NO-not-found"));
BOOST_CHECK_EQUAL( true , logger.removeBackend("COUNTER"));
BOOST_CHECK_EQUAL( false , logger.hasBackend("COUNTER") );
{
auto stream2 = logger.popBackend<StreamLog>("STREAM");
BOOST_CHECK_EQUAL( false , logger.hasBackend("STREAM") );
BOOST_CHECK_THROW( logger.popBackend<StreamLog>("STREAM") , std::invalid_argument );
}
}
BOOST_AUTO_TEST_CASE(LoggerAddTypes_PowerOf2) {
Logger logger;
int64_t not_power_of2 = 13;
int64_t power_of2 = 4096;
BOOST_CHECK_THROW( logger.addMessageType( not_power_of2 , "Prefix") , std::invalid_argument);
BOOST_CHECK_THROW( logger.enabledMessageType( not_power_of2 ) , std::invalid_argument);
logger.addMessageType( power_of2 , "Prefix");
BOOST_CHECK( logger.enabledMessageType( power_of2 ));
BOOST_CHECK_EQUAL( false , logger.enabledMessageType( 2*power_of2 ));
}
class TestLog: public LogBackend {
public:
TestLog( int64_t messageMask ) : LogBackend( messageMask )
{
m_defaultMessages = 0;
m_specialMessages = 0;
}
void addMessage(int64_t messageType , const std::string& /* message */) {
if (messageType & Log::DefaultMessageTypes)
m_defaultMessages +=1;
else
m_specialMessages += 1;
}
int m_defaultMessages;
int m_specialMessages;
};
/*
Testing that the logger frontend does not let unknown message types
pass through; even though the backend has shown interest in the
phony 4096 messagetype.
*/
BOOST_AUTO_TEST_CASE(LoggerMasksTypes) {
Logger logger;
int64_t power_of2 = 4096;
std::shared_ptr<TestLog> testLog = std::make_shared<TestLog>(Log::DefaultMessageTypes + power_of2);
logger.addBackend("TEST" , testLog);
BOOST_CHECK_EQUAL( false , logger.enabledMessageType( power_of2 ));
logger.addMessage( Log::MessageType::Error , "Error");
logger.addMessage( Log::MessageType::Warning , "Warning");
logger.addMessage( Log::MessageType::Info , "Info");
BOOST_CHECK_THROW( logger.addMessage( power_of2 , "Blocked message") , std::invalid_argument );
BOOST_CHECK_EQUAL( testLog->m_defaultMessages , 3 );
BOOST_CHECK_EQUAL( testLog->m_specialMessages , 0 );
logger.addMessageType( power_of2 , "Phony");
logger.addMessage( power_of2 , "Passing through");
BOOST_CHECK_EQUAL( testLog->m_specialMessages , 1 );
}
BOOST_AUTO_TEST_CASE(LoggerDefaultTypesEnabled) {
Logger logger;
BOOST_CHECK_EQUAL( logger.enabledMessageTypes() , Log::DefaultMessageTypes);
}
BOOST_AUTO_TEST_CASE( CounterLogTesting) {
CounterLog counter(Log::DefaultMessageTypes);
counter.addMessage( Log::MessageType::Error , "This is an error ...");
counter.addMessage( Log::MessageType::Warning , "This is a warning");
BOOST_CHECK_EQUAL(1U , counter.numMessages( Log::MessageType::Error ));
BOOST_CHECK_EQUAL(1U , counter.numMessages( Log::MessageType::Warning ));
BOOST_CHECK_EQUAL(0 , counter.numMessages( Log::MessageType::Info ));
{
int64_t not_enabled = 4096;
int64_t not_power2 = 4095;
BOOST_CHECK_EQUAL( 0 , counter.numMessages( not_enabled ));
BOOST_CHECK_THROW( counter.numMessages( not_power2 ) , std::invalid_argument);
}
}
BOOST_AUTO_TEST_CASE(TestTimerLog) {
Logger logger;
std::ostringstream sstream;
std::shared_ptr<TimerLog> timer = std::make_shared<TimerLog>(sstream);
logger.addBackend( "TIMER" , timer );
logger.addMessageType( TimerLog::StartTimer , "Start");
logger.addMessageType( TimerLog::StopTimer , "Stop");
logger.addMessage( TimerLog::StartTimer , "");
logger.addMessage( TimerLog::StopTimer , "This was fast");
std::cout << sstream.str() << std::endl;
}
/*****************************************************************/
void initLogger(std::ostringstream& log_stream);
void initLogger(std::ostringstream& log_stream) {
std::shared_ptr<CounterLog> counter = std::make_shared<CounterLog>();
std::shared_ptr<StreamLog> streamLog = std::make_shared<StreamLog>( log_stream , Log::MessageType::Warning );
BOOST_CHECK_EQUAL( false , OpmLog::hasBackend("NO"));
OpmLog::addBackend("COUNTER" , counter);
OpmLog::addBackend("STREAM" , streamLog);
BOOST_CHECK_EQUAL( true , OpmLog::hasBackend("COUNTER"));
BOOST_CHECK_EQUAL( true , OpmLog::hasBackend("STREAM"));
}
BOOST_AUTO_TEST_CASE(TestOpmLog) {
std::ostringstream log_stream;
initLogger(log_stream);
OpmLog::addMessage( Log::MessageType::Warning , "Warning");
OpmLog::addMessage( Log::MessageType::Error , "Error");
{
auto counter = OpmLog::getBackend<CounterLog>("COUNTER");
BOOST_CHECK_EQUAL( 1 , counter->numMessages(Log::MessageType::Error) );
BOOST_CHECK_EQUAL( 1 , counter->numMessages(Log::MessageType::Warning) );
BOOST_CHECK_EQUAL( 0 , counter->numMessages(Log::MessageType::Info) );
}
BOOST_CHECK_EQUAL( log_stream.str() , "Warning\n");
}

View File

@@ -22,8 +22,8 @@
#include <boost/algorithm/string.hpp>
#include <opm/parser/eclipse/OpmLog/LogUtil.hpp>
#include <opm/parser/eclipse/OpmLog/OpmLog.hpp>
#include <opm/common/OpmLog/LogUtil.hpp>
#include <opm/common/OpmLog/OpmLog.hpp>
#include <opm/parser/eclipse/Parser/InputErrorAction.hpp>
#include <opm/parser/eclipse/Parser/ParseContext.hpp>

View File

@@ -26,8 +26,8 @@
#include <opm/json/JsonObject.hpp>
#include <opm/parser/eclipse/OpmLog/LogUtil.hpp>
#include <opm/parser/eclipse/OpmLog/OpmLog.hpp>
#include <opm/common/OpmLog/LogUtil.hpp>
#include <opm/common/OpmLog/OpmLog.hpp>
#include <opm/parser/eclipse/Deck/Deck.hpp>
#include <opm/parser/eclipse/Deck/DeckItem.hpp>

View File

@@ -1,5 +1,5 @@
#include <opm/parser/eclipse/OpmLog/OpmLog.hpp>
#include <opm/parser/eclipse/OpmLog/StreamLog.hpp>
#include <opm/common/OpmLog/OpmLog.hpp>
#include <opm/common/OpmLog/StreamLog.hpp>
extern "C" {