Skip to content

Add timestamp to logging

Daniel Joseph Antrim requested to merge dantrim_timestamp_debug into devel

What

This MR does two things:

  1. Adds functionality for including timestamp information to the output of the current labRemote logging functionality
  2. Includes a DateTimeUtils.h header under libUtils with some functions (under namespace utils) for generating timestamp strings

New Behavior

By default, the timestamp functionality is disabled and the labRemote logging will appear unchanged as compared to before the changes included in this MR:

logger(logINFO) << "foo"; // returns: [INFO]    : foo

The timestamp functionality can be enabled by calling a static function setTimestamp(bool) on the logger class, in the same way that the debug level for the logger is increased, after which point the current timestamp will added to the logging outputs:

logIt::setTimestamp(true);
logger(logINFO) << "foo"; // returns: [2021-07-29 10:08:27.484][INFO]    : foo 

Timestamp format

Date

The date is formatted to give the usual Y-M-D date string.

Time

The time is formatted with respect to the host's localtime. I think that for most users of labRemote, they will appreciate localtime over UTC.

The time is formatted, also, to have the sub-second precision in milliseconds separated from the H:M:S string by a comma: H:M:S.ms.

Edited by Daniel Joseph Antrim

Merge request reports