#include <TimeLogger.hpp>
Public Member Functions | |
TimeLogger (Log *log, string scope) | |
~TimeLogger () | |
Private Attributes | |
Log * | _log |
string | _scope |
std::chrono::steady_clock::time_point | _started |
A TimeLogger instance logs start/finish messages for the execution of a section of code contained in a C++ scope, augmenting the finish message with the time elapsed between start and finish. The start and finish messages are logged by the constructor and destructor, respectively. Typical use is to construct an instance at the beginning of a scope; the finish message is automatically generated by the destructor when the instance goes out of scope. Nested pairs of start/finish messages can easily be obtained by using TimeLogger in different scopes.
TimeLogger::TimeLogger | ( | Log * | log, |
string | scope | ||
) |
The constructor logs a start message with level Info to the specified log instance, and stores the current time for use by the destructor. The start message is formed by prefixing the specified scope name with the string "Starting ".
TimeLogger::~TimeLogger | ( | ) |
The destructor logs a finish message with level Success to the log instance specified in the constructor. The finish message is formed by prefixing the specified scope name with the string "Finished " and appending the time elapsed between start and finish in a nice format.