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
99
100
101
102
103
104
105
106
107
108
// Copyright (c) 2012-2017 VideoStitch SAS
// Copyright (c) 2018 stitchEm
#include "gpu/testing.hpp"
#include <gpu/buffer.hpp>
#include "libvideostitch/logging.hpp"
#include <sstream>
namespace VideoStitch {
namespace Testing {
void testLog() {
Logger::get(Logger::Error) << "log error" << std::endl;
Logger::get(Logger::Warning) << "log warning" << std::endl;
Logger::get(Logger::Info) << "log info" << std::endl;
Logger::get(Logger::Verbose) << "log verbose" << std::endl;
Logger::get(Logger::Debug) << "log debug" << std::endl;
// Stream change
{
std::ostringstream str;
std::string test = "12345\n";
Logger::setLogStream(Logger::Info, &str);
Logger::get(Logger::Info) << test;
ENSURE_EQ(str.str(), test);
}
// Output level
{
std::ostringstream loggingErrorStr;
std::ostringstream loggingWarningStr;
std::ostringstream loggingInfoStr;
std::ostringstream loggingVerboseStr;
std::ostringstream loggingDebugStr;
Logger::setLogStream(Logger::Error, &loggingErrorStr);
Logger::setLogStream(Logger::Warning, &loggingWarningStr);
Logger::setLogStream(Logger::Info, &loggingInfoStr);
Logger::setLogStream(Logger::Verbose, &loggingVerboseStr);
Logger::setLogStream(Logger::Debug, &loggingDebugStr);
int i = 0;
Logger::get(Logger::Quiet) << "String " << i++ << std::endl;
ENSURE_EQ(loggingErrorStr.str(), std::string());
ENSURE_EQ(loggingWarningStr.str(), std::string());
ENSURE_EQ(loggingInfoStr.str(), std::string());
ENSURE_EQ(loggingVerboseStr.str(), std::string());
ENSURE_EQ(loggingDebugStr.str(), std::string());
Logger::get(Logger::Warning) << "String " << i++ << std::endl;
ENSURE_EQ(loggingErrorStr.str(), std::string());
ENSURE_EQ(loggingWarningStr.str(), std::string("String 1\n"));
ENSURE_EQ(loggingInfoStr.str(), std::string());
ENSURE_EQ(loggingVerboseStr.str(), std::string());
ENSURE_EQ(loggingDebugStr.str(), std::string());
Logger::get(Logger::Error) << "String " << i++ << std::endl;
ENSURE_EQ(loggingErrorStr.str(), std::string("String 2\n"));
ENSURE_EQ(loggingWarningStr.str(), std::string("String 1\n"));
ENSURE_EQ(loggingInfoStr.str(), std::string());
ENSURE_EQ(loggingVerboseStr.str(), std::string());
ENSURE_EQ(loggingDebugStr.str(), std::string());
loggingErrorStr.str(std::string());
Logger::error("TAG") << "String " << i++ << std::endl;
ENSURE_EQ(loggingErrorStr.str(), std::string(Logger::concatenateTags("TAG") + "String 3\n"));
ENSURE_EQ(loggingWarningStr.str(), std::string("String 1\n"));
ENSURE_EQ(loggingInfoStr.str(), std::string());
ENSURE_EQ(loggingVerboseStr.str(), std::string());
ENSURE_EQ(loggingDebugStr.str(), std::string());
}
// Filters
{
std::ostringstream str;
Logger::setLogStream(Logger::Warning, &str);
Logger::addTagFilter(Logger::Warning, "AAA");
Logger::get(Logger::Warning) << "Hello\n";
ENSURE_EQ(str.str(), std::string());
Logger::get(Logger::Warning, "BBB") << "Hello\n";
ENSURE_EQ(str.str(), std::string());
Logger::get(Logger::Warning, "AAA") << "Hello\n";
ENSURE_EQ(str.str(), std::string("[AAA] Hello\n"));
str.str(std::string());
Logger::addTagFilter(Logger::Warning, "BBB");
Logger::removeTagFilter(Logger::Warning, "AAA");
Logger::get(Logger::Warning, "AAA") << "Hello\n";
ENSURE_EQ(str.str(), std::string());
Logger::removeTagFilter(Logger::Warning, "BBB");
Logger::get(Logger::Warning, "AAA") << "Hello\n";
ENSURE_EQ(str.str(), std::string("[AAA] Hello\n"));
}
}
} // namespace Testing
} // namespace VideoStitch
int main(int argc, char** argv) {
VideoStitch::Testing::initTest();
VideoStitch::Logger::readLevelFromArgv(argc, argv);
VideoStitch::Testing::testLog();
return 0;
}