GeNN  4.0.0
GPU enhanced Neuronal Networks (GeNN)
CsvFormatter.h
Go to the documentation of this file.
1 #pragma once
2 #include <plog/Record.h>
3 #include <plog/Util.h>
4 #include <iomanip>
5 
6 namespace plog
7 {
8  template<bool useUtcTime>
10  {
11  public:
13  {
14  return PLOG_NSTR("Date;Time;Severity;TID;This;Function;Message\n");
15  }
16 
17  static util::nstring format(const Record& record)
18  {
19  tm t;
20  (useUtcTime ? util::gmtime_s : util::localtime_s)(&t, &record.getTime().time);
21 
23  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(";");
24  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(";");
25  ss << severityToString(record.getSeverity()) << PLOG_NSTR(";");
26  ss << record.getTid() << PLOG_NSTR(";");
27  ss << record.getObject() << PLOG_NSTR(";");
28  ss << record.getFunc() << PLOG_NSTR("@") << record.getLine() << PLOG_NSTR(";");
29 
30  util::nstring message = record.getMessage();
31 
32  if (message.size() > kMaxMessageSize)
33  {
34  message.resize(kMaxMessageSize);
35  message.append(PLOG_NSTR("..."));
36  }
37 
38  util::nistringstream split(message);
39  util::nstring token;
40 
41  while (!split.eof())
42  {
43  std::getline(split, token, PLOG_NSTR('"'));
44  ss << PLOG_NSTR("\"") << token << PLOG_NSTR("\"");
45  }
46 
47  ss << PLOG_NSTR("\n");
48 
49  return ss.str();
50  }
51 
52  static const size_t kMaxMessageSize = 32000;
53  };
54 
55  class CsvFormatter : public CsvFormatterImpl<false> {};
56  class CsvFormatterUtcTime : public CsvFormatterImpl<true> {};
57 }
Definition: AndroidAppender.h:5
static util::nstring format(const Record &record)
Definition: CsvFormatter.h:17
unsigned short millitm
Definition: Util.h:99
#define PLOG_NSTR(x)
Definition: Util.h:43
time_t time
Definition: Util.h:98
void localtime_s(struct tm *t, const time_t *time)
Definition: Util.h:62
virtual const char * getFunc() const
Definition: Record.h:211
virtual const void * getObject() const
Definition: Record.h:195
void gmtime_s(struct tm *t, const time_t *time)
Definition: Util.h:75
virtual const util::Time & getTime() const
Definition: Record.h:180
std::ostringstream nostringstream
Definition: Util.h:57
static const size_t kMaxMessageSize
Definition: CsvFormatter.h:52
virtual size_t getLine() const
Definition: Record.h:200
static util::nstring header()
Definition: CsvFormatter.h:12
virtual Severity getSeverity() const
Definition: Record.h:185
std::istringstream nistringstream
Definition: Util.h:58
std::string nstring
Definition: Util.h:56
Definition: CsvFormatter.h:9
const char * severityToString(Severity severity)
Definition: Severity.h:16
Definition: Record.h:102
Definition: CsvFormatter.h:55
virtual unsigned int getTid() const
Definition: Record.h:190
virtual const util::nchar * getMessage() const
Definition: Record.h:205
Definition: CsvFormatter.h:56