-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLogging_console.cpp
54 lines (50 loc) · 1.41 KB
/
Logging_console.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include "Logging_console.h"
#include <iostream>
#include <string>
#include <chrono>
using namespace std;
using namespace logging;
Logger & Logger::operator <<(Flags flag) {
if (is_null()) return *this;
switch (flag) {
case L_time: logTime(); break;
case L_flush:
_flags = static_cast<Flags>(_flags & L_allwaysFlush); // all zero's except L_allwaysFlush if set.
*this << " |F|\n";
flush();
break;
case L_endl: {
if (_flags & L_allwaysFlush) { *this << " |F|"; } else if (_flags == L_startWithFlushing) { *this << " |SF|"; }
auto streamPtr = &stream();
Logger* logger = this;
do {
*streamPtr << "\n";
logger = logger->mirror_stream(streamPtr);
} while (streamPtr);
if (_flags & L_allwaysFlush || _flags == L_startWithFlushing) flush();
}
[[fallthrough]];
case L_clearFlags:
if (_flags != L_startWithFlushing) {
_flags = static_cast<Flags>(_flags & L_allwaysFlush); // all zero's except L_allwaysFlush if set.
}
break;
case L_allwaysFlush: _flags += L_allwaysFlush; break;
case L_concat: removeFlag(L_tabs); break;
default:
addFlag(flag);
}
return *this;
}
tm* Logger::getTime() {
std::time_t now = std::time(nullptr);
auto localTime = std::localtime(&now);
log_date.dayNo = localTime->tm_mday;
log_date.monthNo = localTime->tm_mon + 1;
return localTime;
}
Logger& Logger::logTime() {
*this << std::put_time(getTime(), "%d/%m/%y %H:%M:%S");
_flags += L_time;
return *this;
}