This repository was archived by the owner on Apr 29, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrecord.h
More file actions
98 lines (75 loc) · 1.74 KB
/
record.h
File metadata and controls
98 lines (75 loc) · 1.74 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#pragma once
#include "cpplog/config.h"
#include "cpplog/attachment.h"
#ifndef _WIN32
#include <sys/time.h> // gettimeofday
#else
#include <time.h>
#endif
namespace cpplog {
enum class LogLevel {
Trace,
Debug,
Information,
Warning,
Error,
Fatal
};
class LogRecord {
public:
LogRecord() = default;
LogRecord(LogLevel level, const source_location&);
~LogRecord() = default;
const std::string& message() const {
return message_;
};
void set_message(string_view msg) {
#ifdef __cpp_lib_experimental_string_view
message_ = std::string(msg.data(), msg.size());
#else
message_ = msg;
#endif
}
LogLevel level() const {
return level_;
}
void set_leve(LogLevel value) {
level_ = value;
}
const source_location src_location() const {
return src_location_;
}
void set_src_location(const source_location& value) {
src_location_ = value;
}
const timespec& timestamp() const {
return timestamp_;
}
void set_timestamp(const timespec& value) {
timestamp_ = value;
}
template<typename T>
void Attach(string_view name, T&& value) {
// attachment_.Attach(name, std::forward<T>(value));
}
private:
std::string message_;
LogLevel level_ = LogLevel::Information;
timespec timestamp_ = { 0 , 0 };
source_location src_location_;
// Attachment attachment_;
};
CPPLOG_INLINE LogRecord::LogRecord(LogLevel level,
const source_location& src_loc)
: level_(level), timestamp_{0, 0}, src_location_(src_loc) {
#ifdef _WIN32
timespec_get(×tamp_, TIME_UTC);
#else
struct timeval tv;
if (0 == gettimeofday(&tv, nullptr)) {
timestamp_.tv_sec = tv.tv_sec;
timestamp_.tv_nsec = tv.tv_usec * 1000;
}
#endif
}
} // namespace cpplog