|
36 | 36 |
|
37 | 37 | namespace {
|
38 | 38 |
|
39 |
| -using namespace olp::logging; |
40 |
| -using namespace testing; |
| 39 | +namespace logging = olp::logging; |
41 | 40 |
|
42 | 41 | TEST(FileAppenderTest, Default) {
|
43 | 42 | {
|
| 43 | + logging::MessageFormatter formatter( |
| 44 | + {logging::MessageFormatter::Element( |
| 45 | + logging::MessageFormatter::ElementType::Level, "%s "), |
| 46 | + logging::MessageFormatter::Element( |
| 47 | + logging::MessageFormatter::ElementType::Tag, "%s - "), |
| 48 | + logging::MessageFormatter::Element( |
| 49 | + logging::MessageFormatter::ElementType::Message)}); |
| 50 | + |
44 | 51 | SCOPED_TRACE("Create appender");
|
45 |
| - auto appender = std::make_shared<FileAppender>("test.txt"); |
| 52 | + auto appender = |
| 53 | + std::make_shared<logging::FileAppender>("test.txt", false, formatter); |
46 | 54 | ASSERT_TRUE(appender->isValid());
|
47 | 55 | EXPECT_EQ("test.txt", appender->getFileName());
|
48 | 56 |
|
49 |
| - Configuration configuration{}; |
| 57 | + logging::Configuration configuration{}; |
50 | 58 | configuration.addAppender(appender);
|
51 |
| - Log::configure(configuration); |
52 |
| - Log::setLevel(Level::Info); |
| 59 | + logging::Log::configure(configuration); |
| 60 | + logging::Log::setLevel(logging::Level::Info); |
53 | 61 |
|
54 | 62 | OLP_SDK_LOG_INFO("test", "test 1");
|
55 | 63 | OLP_SDK_LOG_WARNING("test", "test 2");
|
56 | 64 |
|
57 |
| - Log::configure(Configuration::createDefault()); |
| 65 | + logging::Log::configure(logging::Configuration::createDefault()); |
58 | 66 | }
|
59 | 67 |
|
60 | 68 | {
|
@@ -82,42 +90,52 @@ TEST(FileAppenderTest, Default) {
|
82 | 90 | }
|
83 | 91 |
|
84 | 92 | TEST(FileAppenderTest, NonExistingFile) {
|
85 |
| - auto appender = std::make_shared<FileAppender>("asdf/foo/bar"); |
| 93 | + auto appender = std::make_shared<logging::FileAppender>("asdf/foo/bar"); |
86 | 94 | EXPECT_FALSE(appender->isValid());
|
87 | 95 | }
|
88 | 96 |
|
89 | 97 | TEST(FileAppenderTest, Append) {
|
| 98 | + logging::MessageFormatter formatter( |
| 99 | + {logging::MessageFormatter::Element( |
| 100 | + logging::MessageFormatter::ElementType::Level, "%s "), |
| 101 | + logging::MessageFormatter::Element( |
| 102 | + logging::MessageFormatter::ElementType::Tag, "%s - "), |
| 103 | + logging::MessageFormatter::Element( |
| 104 | + logging::MessageFormatter::ElementType::Message)}); |
| 105 | + |
90 | 106 | {
|
91 | 107 | SCOPED_TRACE("Create appender");
|
92 |
| - auto appender = std::make_shared<FileAppender>("test.txt", true); |
| 108 | + auto appender = |
| 109 | + std::make_shared<logging::FileAppender>("test.txt", true, formatter); |
93 | 110 | ASSERT_TRUE(appender->isValid());
|
94 | 111 | EXPECT_EQ("test.txt", appender->getFileName());
|
95 | 112 | EXPECT_TRUE(appender->getAppendFile());
|
96 | 113 |
|
97 |
| - Configuration configuration{}; |
| 114 | + logging::Configuration configuration{}; |
98 | 115 | configuration.addAppender(appender);
|
99 |
| - Log::configure(configuration); |
100 |
| - Log::setLevel(Level::Info); |
| 116 | + logging::Log::configure(configuration); |
| 117 | + logging::Log::setLevel(logging::Level::Info); |
101 | 118 |
|
102 | 119 | OLP_SDK_LOG_INFO("test", "test 1");
|
103 | 120 | OLP_SDK_LOG_WARNING("test", "test 2");
|
104 | 121 |
|
105 |
| - Log::configure(Configuration::createDefault()); |
| 122 | + logging::Log::configure(logging::Configuration::createDefault()); |
106 | 123 | }
|
107 | 124 |
|
108 | 125 | {
|
109 | 126 | SCOPED_TRACE("Re-create appender");
|
110 |
| - auto appender = std::make_shared<FileAppender>("test.txt", true); |
| 127 | + auto appender = |
| 128 | + std::make_shared<logging::FileAppender>("test.txt", true, formatter); |
111 | 129 | EXPECT_TRUE(appender->isValid());
|
112 | 130 |
|
113 |
| - Configuration configuration{}; |
| 131 | + logging::Configuration configuration{}; |
114 | 132 | configuration.addAppender(appender);
|
115 |
| - Log::configure(configuration); |
| 133 | + logging::Log::configure(configuration); |
116 | 134 |
|
117 | 135 | OLP_SDK_LOG_ERROR("test", "test 3");
|
118 | 136 | OLP_SDK_LOG_FATAL("test", "test 4");
|
119 | 137 |
|
120 |
| - Log::configure(Configuration::createDefault()); |
| 138 | + logging::Log::configure(logging::Configuration::createDefault()); |
121 | 139 | }
|
122 | 140 |
|
123 | 141 | {
|
|
0 commit comments