-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.cpp
More file actions
71 lines (63 loc) · 2.48 KB
/
example.cpp
File metadata and controls
71 lines (63 loc) · 2.48 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
#include "additional_unit.h"
class entity_with_own_logger{
public:
int _some_field;
entity_with_own_logger(int some_field_) : _some_field(some_field_), _log( ("EntityWithLogger"+std::to_string(some_field_)).c_str()){
_log.level_console = seq_logger::logging_level::debug;
_log.level_seq = seq_logger::logging_level::verbose;
_log.add_enricher([&](seq_logger::seq_context &ctx_) {
ctx_.add("EnrichedThreadId", std::this_thread::get_id());
});
_log.add_enricher([&](seq_logger::seq_context &ctx_) {
ctx_.add("EnrichedFieldValue", _some_field);
if (_some_field>2) {
ctx_.level--;
}
});
_log.add_property("AddedProperty", time(NULL));
std::thread t(&entity_with_own_logger::thread_handler, this);
t.detach();
}
~entity_with_own_logger(){};
private:
seq_logger::seq _log;
void thread_handler() {
auto sleep_duration = std::chrono::milliseconds(5);
for(auto i=0; i<3; ++i){
std::this_thread::sleep_for(sleep_duration);
_log.info("This is a message from a thread {MagicValue}", {{"MagicValue", i}});
}
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
_log.warning("Thread finished");
}
};
int some_field;
int main() {
using namespace seq_logger;
seq::init("127.0.0.1:5341", logging_level::debug, logging_level::debug, 100, ""/*, "<SOME_SEQ_API_KEY>"*/, 1000,
true);
seq::base_level_console = seq_logger::logging_level::debug;
seq::base_level_seq = seq_logger::logging_level::verbose;
srand(time(NULL));
seq::add_shared_property("ProcessRunIdentifier", rand());
seq::add_shared_enricher([&](seq_logger::seq_context &ctx) {
ctx.add("SomeField", some_field++);
if (some_field>9){
ctx.level++;
}
});
seq::log_debug("Static logging", {{"PassedValue", "RandomValue"}});
seq::log_debug("Static logging", {{"PassedValue", 3}});
std::vector<std::shared_ptr<entity_with_own_logger>> vec;
for(int i=0; i<3; i++){
seq::log_debug("Creating new entity with logger!");
vec.emplace_back(std::make_shared<entity_with_own_logger>(i));
}
entity_with_own_logger e1(1);
seq::log_verbose("Should not be visible");
seq::log_warning("Should be visible");
auto au = additional_unit();
au.do_something();
std::this_thread::sleep_for(std::chrono::milliseconds(1500));
return 0;
}