2014-11-02 23:58:35 +01:00
|
|
|
#include "LogSink.h"
|
|
|
|
|
|
|
|
|
|
#include <chrono>
|
2018-01-29 21:55:48 +01:00
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
|
|
#include "../clib.h"
|
2014-11-02 23:58:35 +01:00
|
|
|
|
2016-02-19 19:26:35 +01:00
|
|
|
namespace Pol
|
|
|
|
|
{
|
|
|
|
|
namespace Clib
|
|
|
|
|
{
|
|
|
|
|
namespace Logging
|
|
|
|
|
{
|
2014-11-02 23:58:35 +01:00
|
|
|
using std::chrono::system_clock;
|
|
|
|
|
|
2019-02-10 14:00:55 +01:00
|
|
|
void LogSink::addTimeStamp( std::ostream& stream )
|
2014-11-02 23:58:35 +01:00
|
|
|
{
|
2016-02-19 19:26:35 +01:00
|
|
|
stream << getTimeStamp();
|
2014-11-02 23:58:35 +01:00
|
|
|
}
|
|
|
|
|
|
2019-02-10 14:00:55 +01:00
|
|
|
std::string LogSink::getTimeStamp()
|
2014-11-02 23:58:35 +01:00
|
|
|
{
|
2016-02-19 19:26:35 +01:00
|
|
|
fmt::Writer writer;
|
|
|
|
|
time_t tClockTime = system_clock::to_time_t( system_clock::now() );
|
|
|
|
|
struct tm tTime = Clib::localtime( tClockTime );
|
|
|
|
|
|
|
|
|
|
// write "[%m/%d %H:%M:%S] "
|
|
|
|
|
writer << '[' << fmt::pad( tTime.tm_mon + 1, 2, '0' ) << '/' << fmt::pad( tTime.tm_mday, 2, '0' )
|
|
|
|
|
<< ' ' << fmt::pad( tTime.tm_hour, 2, '0' ) << ':' << fmt::pad( tTime.tm_min, 2, '0' )
|
|
|
|
|
<< ':' << fmt::pad( tTime.tm_sec, 2, '0' ) << "] ";
|
|
|
|
|
|
|
|
|
|
return writer.str();
|
2014-11-02 23:58:35 +01:00
|
|
|
}
|
|
|
|
|
|
2019-02-10 14:00:55 +01:00
|
|
|
} // namespace Logging
|
|
|
|
|
} // namespace Clib
|
|
|
|
|
} // namespace Pol
|