2016-03-17 06:03:07 -05:00
|
|
|
/*
|
|
|
|
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/common/OpmLog/OpmLog.hpp>
|
|
|
|
#include <opm/common/OpmLog/Logger.hpp>
|
2016-05-22 21:12:29 -05:00
|
|
|
#include <opm/common/OpmLog/StreamLog.hpp>
|
|
|
|
#include <iostream>
|
2016-03-17 06:03:07 -05:00
|
|
|
|
|
|
|
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 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-18 06:27:12 -05:00
|
|
|
void OpmLog::addTaggedMessage(int64_t messageFlag, const std::string& tag, const std::string& message) {
|
|
|
|
if (m_logger)
|
|
|
|
m_logger->addTaggedMessage( messageFlag, tag, message );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-03-17 06:03:07 -05:00
|
|
|
void OpmLog::info(const std::string& message)
|
|
|
|
{
|
2016-05-09 04:32:42 -05:00
|
|
|
addMessage(Log::MessageType::Info, message);
|
2016-03-17 06:03:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void OpmLog::warning(const std::string& message)
|
|
|
|
{
|
2016-05-09 04:32:42 -05:00
|
|
|
addMessage(Log::MessageType::Warning, message);
|
2016-03-17 06:03:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void OpmLog::problem(const std::string& message)
|
|
|
|
{
|
2016-05-09 04:32:42 -05:00
|
|
|
addMessage(Log::MessageType::Problem, message);
|
2016-03-17 06:03:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void OpmLog::error(const std::string& message)
|
|
|
|
{
|
2016-05-09 04:32:42 -05:00
|
|
|
addMessage(Log::MessageType::Error, message);
|
2016-03-17 06:03:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void OpmLog::bug(const std::string& message)
|
|
|
|
{
|
2016-05-09 04:32:42 -05:00
|
|
|
addMessage(Log::MessageType::Bug, message);
|
2016-03-17 06:03:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void OpmLog::debug(const std::string& message)
|
|
|
|
{
|
2016-05-09 04:32:42 -05:00
|
|
|
addMessage(Log::MessageType::Debug, message);
|
2016-03-17 06:03:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-06-08 02:00:24 -05:00
|
|
|
void OpmLog::note(const std::string& message)
|
2016-06-07 07:08:33 -05:00
|
|
|
{
|
2016-06-08 02:00:24 -05:00
|
|
|
addMessage(Log::MessageType::Note, message);
|
2016-06-07 07:08:33 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-18 06:27:12 -05:00
|
|
|
|
|
|
|
void OpmLog::info(const std::string& tag, const std::string& message)
|
|
|
|
{
|
|
|
|
addTaggedMessage(Log::MessageType::Info, tag, message);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void OpmLog::warning(const std::string& tag, const std::string& message)
|
|
|
|
{
|
|
|
|
addTaggedMessage(Log::MessageType::Warning, tag, message);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void OpmLog::problem(const std::string& tag, const std::string& message)
|
|
|
|
{
|
|
|
|
addTaggedMessage(Log::MessageType::Problem, tag, message);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void OpmLog::error(const std::string& tag, const std::string& message)
|
|
|
|
{
|
|
|
|
addTaggedMessage(Log::MessageType::Error, tag, message);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void OpmLog::bug(const std::string& tag, const std::string& message)
|
|
|
|
{
|
|
|
|
addTaggedMessage(Log::MessageType::Bug, tag, message);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void OpmLog::debug(const std::string& tag, const std::string& message)
|
|
|
|
{
|
|
|
|
addTaggedMessage(Log::MessageType::Debug, tag, message);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-06-08 02:00:24 -05:00
|
|
|
void OpmLog::note(const std::string& tag, const std::string& message)
|
2016-06-07 07:08:33 -05:00
|
|
|
{
|
2016-06-08 02:00:24 -05:00
|
|
|
addTaggedMessage(Log::MessageType::Note, tag, message);
|
2016-06-07 07:08:33 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-05-18 06:27:12 -05:00
|
|
|
|
2016-03-17 06:03:07 -05:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-12 03:29:48 -05:00
|
|
|
void OpmLog::removeAllBackends() {
|
2016-05-09 04:33:35 -05:00
|
|
|
if (m_logger) {
|
2016-05-12 03:29:48 -05:00
|
|
|
m_logger->removeAllBackends();
|
2016-05-09 04:33:35 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-03-17 06:03:07 -05:00
|
|
|
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 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-22 21:12:29 -05:00
|
|
|
|
2016-05-23 02:01:28 -05:00
|
|
|
void OpmLog::setupSimpleDefaultLogging(const bool use_prefix)
|
2016-05-22 21:12:29 -05:00
|
|
|
{
|
|
|
|
std::shared_ptr<StreamLog> streamLog = std::make_shared<StreamLog>(std::cout, Log::DefaultMessageTypes);
|
2016-05-23 02:01:28 -05:00
|
|
|
OpmLog::addBackend( "SimpleDefaultLog", streamLog);
|
2016-05-22 21:12:29 -05:00
|
|
|
streamLog->setMessageLimiter(std::make_shared<MessageLimiter>(10));
|
|
|
|
streamLog->setMessageFormatter(std::make_shared<SimpleMessageFormatter>(use_prefix, true));
|
|
|
|
}
|
2016-03-17 06:03:07 -05:00
|
|
|
/******************************************************************/
|
|
|
|
|
|
|
|
std::shared_ptr<Logger> OpmLog::m_logger;
|
|
|
|
}
|