source: s10k/CommonLibs/plog/Formatters/CsvFormatter.h@ 1085

Last change on this file since 1085 was 1073, checked in by s10k, 7 years ago

added XML Tools latest version (2.0d) and s10k's common libs

File size: 1.9 KB
Line 
1#pragma once
2#include <plog/Record.h>
3#include <plog/Util.h>
4#include <iomanip>
5
6namespace plog
7{
8 class CsvFormatter
9 {
10 public:
11 static util::nstring header()
12 {
13 return PLOG_NSTR("Date;Time;Severity;TID;This;Function;Message\n");
14 }
15
16 static util::nstring format(const Record& record)
17 {
18 tm t;
19 util::localtime_s(&t, &record.getTime().time);
20
21 util::nstringstream ss;
22 ss << t.tm_year + 1900 << PLOG_NSTR("/") << std::setfill(PLOG_NSTR('0')) << std::setw(2) << t.tm_mon + 1 << PLOG_NSTR("/") << std::setfill(PLOG_NSTR('0')) << std::setw(2) << t.tm_mday << PLOG_NSTR(";");
23 ss << std::setfill(PLOG_NSTR('0')) << std::setw(2) << t.tm_hour << PLOG_NSTR(":") << std::setfill(PLOG_NSTR('0')) << std::setw(2) << t.tm_min << PLOG_NSTR(":") << std::setfill(PLOG_NSTR('0')) << std::setw(2) << t.tm_sec << PLOG_NSTR(".") << std::setfill(PLOG_NSTR('0')) << std::setw(3) << record.getTime().millitm << PLOG_NSTR(";");
24 ss << severityToString(record.getSeverity()) << PLOG_NSTR(";");
25 ss << record.getTid() << PLOG_NSTR(";");
26 ss << record.getObject() << PLOG_NSTR(";");
27 ss << record.getFunc() << PLOG_NSTR("@") << record.getLine() << PLOG_NSTR(";");
28
29 util::nstring message = record.getMessage();
30
31 if (message.size() > kMaxMessageSize)
32 {
33 message.resize(kMaxMessageSize);
34 message.append(PLOG_NSTR("..."));
35 }
36
37 util::nstringstream split(message);
38 util::nstring token;
39
40 while (!split.eof())
41 {
42 std::getline(split, token, PLOG_NSTR('"'));
43 ss << PLOG_NSTR("\"") << token << PLOG_NSTR("\"");
44 }
45
46 ss << PLOG_NSTR("\n");
47
48 return ss.str();
49 }
50
51 static const size_t kMaxMessageSize = 32000;
52 };
53}
Note: See TracBrowser for help on using the repository browser.