Adding timestamps
A single log file might provide some value with just messages, but recording the date and time of each log message makes it much more valuable. And once we start working with multiple log files from different micro-services, the need to order the log messages by time becomes critical.
It’s fairly simple to add timestamps. All we need to do is get the current time, format it into a standard timestamp that eliminates misunderstanding between the year, month, and day, and then send the timestamp to the log along with the message. The caller doesn’t need to do anything.
It’s also difficult to test directly to make sure it works. We can manually open the log file and see the timestamps; that will be enough for now. We’re not going to add any new tests for the timestamps.
All we need to do is modify Log.h
so it looks like this:
#include <chrono>
#include <ctime>
#include <fstream>
#include <iomanip>
#include...