HDLCd-Tools
LogClientFormatter.h
Go to the documentation of this file.
1 
22 #ifndef LOG_CLIENT_FORMATTER_H
23 #define LOG_CLIENT_FORMATTER_H
24 
25 #include <boost/date_time/posix_time/posix_time_types.hpp>
26 #include <iostream>
27 #include <iomanip>
28 
29 void PrintLogEntry(const std::vector<unsigned char> &a_Buffer) {
30  // Example: 19-02-2016;21:59:07.719;
31  auto l_Now(boost::posix_time::microsec_clock::universal_time());
32  auto l_Date(l_Now.date());
33  auto l_DayTime (l_Now.time_of_day());
34  std::cout << std::dec << l_Date.day() << "-"
35  << std::setw(2) << std::setfill('0') << (int)l_Date.month() << "-"
36  << std::setw(4) << std::setfill('0') << l_Date.year() << ";"
37  << std::setw(2) << std::setfill('0') << l_DayTime.hours() << ":"
38  << std::setw(2) << std::setfill('0') << l_DayTime.minutes() << ":"
39  << std::setw(2) << std::setfill('0') << l_DayTime.seconds() << "."
40  << std::setw(3) << std::setfill('0') << (l_DayTime.total_milliseconds() % 1000) << ";";
41 
42  // Print a hexdump of the provided data buffer. It should contain a packet to be printed in one line.
43  for (auto it = a_Buffer.begin(); it != a_Buffer.end(); ++it) {
44  std::cout << std::hex << std::setw(2) << std::setfill('0') << std::uppercase << int(*it) << " ";
45  } // for
46 
47  std::cout << std::endl;
48 }
49 
50 #endif // LOG_CLIENT_FORMATTER_H
void PrintLogEntry(const std::vector< unsigned char > &a_Buffer)