Ensure scope_logger won't throw

Coverity pointed out that scope_logger is occasionally used in destructors. If it throws, the game will abort.
This commit is contained in:
Alexander van Gessel 2017-09-12 17:01:41 +02:00
parent 7dcb9d09f9
commit 76c814d6f7
2 changed files with 13 additions and 6 deletions

View File

@ -237,18 +237,23 @@ std::ostream &logger::operator()(log_domain const &domain, bool show_names, bool
}
}
void scope_logger::do_log_entry(log_domain const &domain, const std::string& str)
void scope_logger::do_log_entry(log_domain const &domain, const std::string& str) NOEXCEPT
{
output_ = &debug()(domain, false, true);
str_ = str;
ticks_ = boost::posix_time::microsec_clock::local_time();
try {
ticks_ = boost::posix_time::microsec_clock::local_time();
} catch(...) {}
(*output_) << "{ BEGIN: " << str_ << "\n";
++indent;
}
void scope_logger::do_log_exit()
void scope_logger::do_log_exit() NOEXCEPT
{
const long ticks = (boost::posix_time::microsec_clock::local_time() - ticks_).total_milliseconds();
long ticks = 0;
try {
ticks = (boost::posix_time::microsec_clock::local_time() - ticks_).total_milliseconds();
} catch(...) {}
--indent;
do_indent();
if (timestamp) (*output_) << get_timestamp(time(nullptr));

View File

@ -44,6 +44,8 @@
#pragma once
#include "global.hpp"
#ifndef __func__
#ifdef __FUNCTION__
#define __func__ __FUNCTION__
@ -164,8 +166,8 @@ public:
}
void do_indent() const;
private:
void do_log_entry(log_domain const &domain, const std::string& str);
void do_log_exit();
void do_log_entry(log_domain const &domain, const std::string& str) NOEXCEPT;
void do_log_exit() NOEXCEPT;
};
/**