Add configureDecoration() and decorateMessage() to LogBackend.
This commit is contained in:
parent
9a03758e9f
commit
b40ea5dda7
@ -17,8 +17,8 @@
|
||||
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <cstdint>
|
||||
#include <opm/common/OpmLog/LogBackend.hpp>
|
||||
#include <opm/common/OpmLog/LogUtil.hpp>
|
||||
|
||||
namespace Opm {
|
||||
|
||||
@ -31,17 +31,33 @@ namespace Opm {
|
||||
{
|
||||
}
|
||||
|
||||
bool LogBackend::includeMessage(int64_t messageFlag) {
|
||||
if (((messageFlag & m_mask) == messageFlag) &&
|
||||
(messageFlag > 0))
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
void LogBackend::configureDecoration(bool use_prefix, bool use_color_coding)
|
||||
{
|
||||
use_prefix_ = use_prefix;
|
||||
use_color_coding_ = use_color_coding;
|
||||
}
|
||||
|
||||
int64_t LogBackend::getMask() const {
|
||||
int64_t LogBackend::getMask() const
|
||||
{
|
||||
return m_mask;
|
||||
}
|
||||
|
||||
bool LogBackend::includeMessage(int64_t messageFlag)
|
||||
{
|
||||
return ((messageFlag & m_mask) == messageFlag) && (messageFlag > 0);
|
||||
}
|
||||
|
||||
std::string LogBackend::decorateMessage(int64_t messageFlag, const std::string& message)
|
||||
{
|
||||
std::string msg = message;
|
||||
if (use_prefix_) {
|
||||
msg = Log::prefixMessage(messageFlag, msg);
|
||||
}
|
||||
if (use_color_coding_) {
|
||||
msg = Log::colorCodeMessage(messageFlag, msg);
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -37,6 +37,9 @@ namespace Opm
|
||||
/// Virtual destructor to enable inheritance.
|
||||
virtual ~LogBackend();
|
||||
|
||||
/// Configure how decorateMessage() will modify message strings.
|
||||
void configureDecoration(bool use_prefix, bool use_color_coding);
|
||||
|
||||
/// Add a message to the backend.
|
||||
///
|
||||
/// Typically a subclass may filter, change, and output
|
||||
@ -49,10 +52,15 @@ namespace Opm
|
||||
|
||||
protected:
|
||||
/// Return true if all bits of messageFlag are also set in our mask.
|
||||
bool includeMessage(int64_t messageFlag);
|
||||
bool includeMessage(int64_t messageFlag);
|
||||
|
||||
/// Return decorated version of message depending on configureDecoration() arguments.
|
||||
std::string decorateMessage(int64_t messageFlag, const std::string& message);
|
||||
|
||||
private:
|
||||
int64_t m_mask;
|
||||
bool use_prefix_ = false;
|
||||
bool use_color_coding_ = false;
|
||||
};
|
||||
|
||||
} // namespace LogBackend
|
||||
|
Loading…
Reference in New Issue
Block a user