-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy patht-defaults.cpp
93 lines (81 loc) · 2.38 KB
/
t-defaults.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
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
// Copyright (c) Borislav Stanimirov
// SPDX-License-Identifier: MIT
//
#include <doctest/doctest.h>
#include "TestSink.hpp"
#include <jalog/Log.hpp>
#include <jalog/LogPrintf.hpp>
#include <jalog/PrintfWrap.hpp>
#include <jalog/DefaultLogger.hpp>
#include <jalog/Instance.hpp>
TEST_SUITE_BEGIN("jalog");
jalog::Scope gscope("g", 10, 20);
JALOG_DEFINE_PRINTF_FUNC(log_gscope, gscope)
TEST_CASE("default logger/scope")
{
auto sink = std::make_shared<TestSink>();
auto& es = sink->entries;
jalog::Instance i;
i.setup()
.defaultLevel(jalog::Level::Info)
.add(sink);
JALOG(Debug, "dbg", 1);
JALOG_PRINTF(Info, "info%d", 1);
JALOG(Error, "error", 1);
jalog::Scope scope("s1", 1, 2);
JALOG_SCOPE(scope, Debug, "dbg", 2);
JALOG_SCOPE(scope, Info, "info", 2);
JALOG_PRINTF_SCOPE(scope, Critical, "crit%d", 2);
JALOG_PRINTF_SCOPE(gscope, Debug, "dbg%d", 3);
JALOG_SCOPE(gscope, Error, "err", 3);
log_gscope<jalog::Level::Warning>("wrn%d", 11);
REQUIRE(es.size() == 6);
{
auto& e = es[0];
CHECK(e.scope.label().empty());
CHECK(e.scope.id() == 0);
CHECK(e.scope.userData == -1);
CHECK(e.level == jalog::Level::Info);
CHECK(e.text == "info1");
}
{
auto& e = es[1];
CHECK(e.scope.label().empty());
CHECK(e.scope.id() == 0);
CHECK(e.scope.userData == -1);
CHECK(e.level == jalog::Level::Error);
CHECK(e.text == "error1");
}
{
auto& e = es[2];
CHECK(e.scope.label() == "s1");
CHECK(e.scope.id() == 1);
CHECK(e.scope.userData == 2);
CHECK(e.level == jalog::Level::Info);
CHECK(e.text == "info2");
}
{
auto& e = es[3];
CHECK(e.scope.label() == "s1");
CHECK(e.scope.id() == 1);
CHECK(e.scope.userData == 2);
CHECK(e.level == jalog::Level::Critical);
CHECK(e.text == "crit2");
}
{
auto& e = es[4];
CHECK(e.scope.label() == "g");
CHECK(e.scope.id() == 10);
CHECK(e.scope.userData == 20);
CHECK(e.level == jalog::Level::Error);
CHECK(e.text == "err3");
}
{
auto& e = es[5];
CHECK(e.scope.label() == "g");
CHECK(e.scope.id() == 10);
CHECK(e.scope.userData == 20);
CHECK(e.level == jalog::Level::Warning);
CHECK(e.text == "wrn11");
}
}