2019-01-08 04:28:18 -06:00
|
|
|
/*
|
|
|
|
Copyright 2018 SINTEF Digital, Mathematics and Cybernetics.
|
|
|
|
|
|
|
|
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_DEFERREDLOGGER_HEADER_INCLUDED
|
|
|
|
#define OPM_DEFERREDLOGGER_HEADER_INCLUDED
|
|
|
|
|
|
|
|
#include <opm/common/OpmLog/OpmLog.hpp>
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace Opm
|
|
|
|
{
|
2019-01-08 04:41:19 -06:00
|
|
|
/** This class implements a deferred logger:
|
|
|
|
* 1) messages can be pushed back to a vector
|
|
|
|
* 2) a call to logMessages adds the messages to OpmLog backends
|
|
|
|
* */
|
2019-01-08 04:28:18 -06:00
|
|
|
|
2021-03-18 02:29:23 -05:00
|
|
|
namespace ExceptionType
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
If an exception has been raised on more than processor simultaneously the
|
|
|
|
highest number type will be thrown in the subsequent global rethrow.
|
|
|
|
*/
|
|
|
|
|
|
|
|
enum ExcEnum {
|
|
|
|
NONE = 0,
|
|
|
|
RUNTIME_ERROR = 1,
|
|
|
|
INVALID_ARGUMENT = 2,
|
|
|
|
LOGIC_ERROR = 3,
|
|
|
|
DEFAULT = 4, // will throw std::logic_error()
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-01-08 04:28:18 -06:00
|
|
|
class DeferredLogger
|
|
|
|
{
|
|
|
|
public:
|
2019-01-11 06:53:18 -06:00
|
|
|
|
|
|
|
struct Message
|
|
|
|
{
|
|
|
|
int64_t flag;
|
|
|
|
std::string tag;
|
|
|
|
std::string text;
|
|
|
|
};
|
|
|
|
|
2019-01-08 04:28:18 -06:00
|
|
|
void info(const std::string& tag, const std::string& message);
|
|
|
|
void warning(const std::string& tag, const std::string& message);
|
|
|
|
void error(const std::string& tag, const std::string& message);
|
|
|
|
void problem(const std::string& tag, const std::string& message);
|
|
|
|
void bug(const std::string& tag, const std::string& message);
|
|
|
|
void debug(const std::string& tag, const std::string& message);
|
|
|
|
void note(const std::string& tag, const std::string& message);
|
|
|
|
|
|
|
|
void info(const std::string& message);
|
|
|
|
void warning(const std::string& message);
|
|
|
|
void error(const std::string& message);
|
|
|
|
void problem(const std::string& message);
|
|
|
|
void bug(const std::string& message);
|
|
|
|
void debug(const std::string& message);
|
|
|
|
void note(const std::string& message);
|
|
|
|
|
2019-04-30 05:24:31 -05:00
|
|
|
/// Log all messages to the OpmLog backends,
|
|
|
|
/// and clear the message container.
|
2019-01-08 04:28:18 -06:00
|
|
|
void logMessages();
|
|
|
|
|
2019-04-30 05:24:31 -05:00
|
|
|
/// Clear the message container without logging them.
|
|
|
|
void clearMessages();
|
|
|
|
|
2019-01-08 04:28:18 -06:00
|
|
|
private:
|
|
|
|
std::vector<Message> messages_;
|
2021-05-25 05:00:04 -05:00
|
|
|
friend DeferredLogger gatherDeferredLogger(const DeferredLogger& local_deferredlogger);
|
2019-01-08 04:28:18 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Opm
|
|
|
|
|
|
|
|
#endif // OPM_DEFERREDLOGGER_HEADER_INCLUDED
|