Pol  Revision:3cfda13
LogSink.cpp
Go to the documentation of this file.
1 #include "LogSink.h"
2 
3 #include <chrono>
4 #include <time.h>
5 
6 #include "../clib.h"
7 
8 namespace Pol
9 {
10 namespace Clib
11 {
12 namespace Logging
13 {
14 using namespace std;
15 using std::chrono::system_clock;
16 
18 
20 
22 
24 
25 void LogSink::addTimeStamp( ostream& stream )
26 {
27  stream << getTimeStamp();
28 }
29 
31 {
32  fmt::Writer writer;
33  time_t tClockTime = system_clock::to_time_t( system_clock::now() );
34  struct tm tTime = Clib::localtime( tClockTime );
35 
36  // write "[%m/%d %H:%M:%S] "
37  writer << '[' << fmt::pad( tTime.tm_mon + 1, 2, '0' ) << '/' << fmt::pad( tTime.tm_mday, 2, '0' )
38  << ' ' << fmt::pad( tTime.tm_hour, 2, '0' ) << ':' << fmt::pad( tTime.tm_min, 2, '0' )
39  << ':' << fmt::pad( tTime.tm_sec, 2, '0' ) << "] ";
40 
41  return writer.str();
42 }
43 
45 }
46 }
47 } // namespaces
std::tm localtime(const std::time_t &t)
threadsafe version of localtime
Definition: clib.h:143
STL namespace.
static std::string getTimeStamp()
Definition: LogSink.cpp:30
static void addTimeStamp(std::ostream &stream)
Definition: LogSink.cpp:25
Definition: berror.cpp:12