MCPcopy Create free account
hub / github.com/bcndev/bytecoin / format_pattern

Function format_pattern

src/logging/CommonLogger.cpp:10–51  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8namespace {
9
10std::string format_pattern(const std::string &pattern, const std::string &category, Level level, std::time_t time) {
11 std::stringstream s;
12
13 for (const char *p = pattern.c_str(); p && *p != 0; ++p) {
14 if (*p == '%') {
15 ++p;
16 switch (*p) {
17 case 0:
18 break;
19 case 'C':
20 s << category;
21 break;
22 case 'D': {
23 char tb[30]{};
24 std::strftime(tb, sizeof(tb) - 1, "%Y-%m-%d", std::localtime(&time));
25 s << std::string(tb);
26 break;
27 }
28 case 'T': {
29 char tb[30]{};
30 std::strftime(tb, sizeof(tb) - 1, "%H:%M:%S", std::localtime(&time));
31 s << std::string(tb);
32 break;
33 }
34 case 'l':
35 s << ILogger::LEVEL_NAMES[level][0];
36 break;
37 case 'L':
38 s << ILogger::LEVEL_NAMES[level];
39 if (ILogger::LEVEL_NAMES[level].size() < 5)
40 s << std::string(5 - ILogger::LEVEL_NAMES[level].size(), ' ');
41 break;
42 default:
43 s << *p;
44 }
45 } else {
46 s << *p;
47 }
48 }
49
50 return s.str();
51}
52} // namespace
53
54void CommonLogger::write(const std::string &category, Level level, std::time_t time, const std::string &body) {

Callers 1

writeMethod · 0.85

Calls 1

sizeMethod · 0.45

Tested by

no test coverage detected