WebCFace 2.5.2
Web-based Communication Framework & Dashboard-like UI
Loading...
Searching...
No Matches
log.h
Go to the documentation of this file.
1#pragma once
2#include "./base.h"
4#include <deque>
5
6#ifndef MSGPACK_DEFINE_MAP
7#define MSGPACK_DEFINE_MAP(...)
8#endif
9
11namespace message {
12
13struct LogLine {
14 int level_ = 0;
21 std::uint64_t time_ms = 0;
23 LogLine() = default;
24 LogLine(int level, std::uint64_t time_ms, const SharedString &message)
25 : level_(level), time_ms(time_ms), message_(message) {}
26 MSGPACK_DEFINE_MAP(MSGPACK_NVP("v", level_), MSGPACK_NVP("t", time_ms),
27 MSGPACK_NVP("m", message_))
28};
35struct LogDefault : public MessageBase<MessageKind::log_default> {
36 unsigned int member_id = 0;
37 std::shared_ptr<std::deque<LogLine>> log;
38 LogDefault() = default;
39 LogDefault(unsigned int member_id,
40 const std::shared_ptr<std::deque<LogLine>> &log)
41 : member_id(member_id), log(log) {}
42 template <typename It>
43 LogDefault(const It &begin, const It &end) : member_id(0) {
44 this->log = std::make_shared<std::deque<LogLine>>();
45 for (auto it = begin; it < end; it++) {
46 if constexpr (std::is_same_v<decltype(*it), LogLine>) {
47 this->log->push_back(*it);
48 } else {
49 this->log->emplace_back(it->toMessage());
50 }
51 }
52 }
53 explicit LogDefault(const LogLine &ll) : member_id(0) {
54 this->log = std::make_shared<std::deque<LogLine>>(1);
55 this->log->front() = ll;
56 }
57 MSGPACK_DEFINE_MAP(MSGPACK_NVP("m", member_id), MSGPACK_NVP("l", log))
58};
59
60struct Log : public MessageBase<MessageKind::log> {
61 static SharedString defaultLogName();
62
64 std::shared_ptr<std::deque<LogLine>> log;
65 Log() = default;
66 Log(const SharedString &field,
67 const std::shared_ptr<std::deque<LogLine>> &log)
68 : field(field), log(log) {}
69 template <typename It>
70 Log(const SharedString &field, const It &begin, const It &end)
71 : field(field) {
72 this->log = std::make_shared<std::deque<LogLine>>();
73 for (auto it = begin; it < end; it++) {
74 if constexpr (std::is_same_v<decltype(*it), LogLine>) {
75 this->log->push_back(*it);
76 } else {
77 this->log->emplace_back(it->toMessage());
78 }
79 }
80 }
81 explicit Log(const SharedString &field, const LogLine &ll) : field(field) {
82 this->log = std::make_shared<std::deque<LogLine>>(1);
83 this->log->front() = ll;
84 }
85 MSGPACK_DEFINE_MAP(MSGPACK_NVP("f", field), MSGPACK_NVP("l", log))
86};
87struct LogReqDefault : public MessageBase<MessageKind::log_req_default> {
89 MSGPACK_DEFINE_MAP(MSGPACK_NVP("M", member))
90};
91struct LogEntryDefault : public MessageBase<MessageKind::log_entry_default> {
92 unsigned int member_id = 0;
93 MSGPACK_DEFINE_MAP(MSGPACK_NVP("m", member_id))
94};
95template <>
96struct Res<Log> : public MessageBase<MessageKind::log + MessageKind::res> {
97 unsigned int req_id = 0;
99 std::shared_ptr<std::deque<LogLine>> log;
100 Res() = default;
101 Res(unsigned int req_id, const SharedString &sub_field,
102 const std::shared_ptr<std::deque<LogLine>> &log)
103 : MessageBase<MessageKind::log + MessageKind::res>(), req_id(req_id),
104 sub_field(sub_field), log(log) {}
105 template <typename It>
106 Res(unsigned int req_id, const SharedString &sub_field, const It &begin,
107 const It &end)
108 : MessageBase<MessageKind::log + MessageKind::res>(), req_id(req_id),
109 sub_field(sub_field) {
110 this->log = std::make_shared<std::deque<LogLine>>();
111 for (auto it = begin; it < end; it++) {
112 if constexpr (std::is_same_v<decltype(*it), LogLine>) {
113 this->log->push_back(*it);
114 } else {
115 this->log->emplace_back(it->toMessage());
116 }
117 }
118 }
119
120 MSGPACK_DEFINE_MAP(MSGPACK_NVP("i", req_id), MSGPACK_NVP("f", sub_field),
121 MSGPACK_NVP("l", log))
122};
123
124
125}
u8stringとstringとwstringをshared_ptrで持ち共有する
Definition encoding.h:69
#define MSGPACK_DEFINE_MAP(...)
Definition canvas2d.h:10
client(member)->server->client logを追加
Definition log.h:35
LogDefault(unsigned int member_id, const std::shared_ptr< std::deque< LogLine > > &log)
Definition log.h:39
LogDefault(const LogLine &ll)
Definition log.h:53
std::shared_ptr< std::deque< LogLine > > log
Definition log.h:37
LogDefault(const It &begin, const It &end)
Definition log.h:43
Definition log.h:13
LogLine(int level, std::uint64_t time_ms, const SharedString &message)
Definition log.h:24
SharedString message_
Definition log.h:22
SharedString member
Definition log.h:88
Definition log.h:60
Log(const SharedString &field, const LogLine &ll)
Definition log.h:81
Log(const SharedString &field, const std::shared_ptr< std::deque< LogLine > > &log)
Definition log.h:66
SharedString field
Definition log.h:63
std::shared_ptr< std::deque< LogLine > > log
Definition log.h:64
Log(const SharedString &field, const It &begin, const It &end)
Definition log.h:70
型からkindを取得するためだけのベースクラス
Definition base.h:53
Res(unsigned int req_id, const SharedString &sub_field, const std::shared_ptr< std::deque< LogLine > > &log)
Definition log.h:101
Res(unsigned int req_id, const SharedString &sub_field, const It &begin, const It &end)
Definition log.h:106
SharedString sub_field
Definition log.h:98
std::shared_ptr< std::deque< LogLine > > log
Definition log.h:99
Definition base.h:58
#define WEBCFACE_NS_END
Definition webcface-config.h:104
#define WEBCFACE_NS_BEGIN
Definition webcface-config.h:103