Skip to content

Commit 3b7e84e

Browse files
committed
wsd: move the old Log::prefix to tests only
Change-Id: Ia5127c9f1869e9a57c6ed2da1231e757b6211303 Signed-off-by: Ashod Nakashian <[email protected]>
1 parent ddcddc1 commit 3b7e84e

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

common/Log.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -649,8 +649,9 @@ namespace Log
649649
return _prefix;
650650
}
651651

652-
char* prefix(const std::chrono::time_point<std::chrono::system_clock>& tp, char* buffer,
653-
const std::string_view level)
652+
#ifdef BUILDING_TESTS
653+
char* prefixReference(const std::chrono::time_point<std::chrono::system_clock>& tp,
654+
char* buffer, const std::string_view level)
654655
{
655656
#if defined(IOS) || defined(__FreeBSD__)
656657
// Don't bother with the "Source" which would be just "Mobile" always (or whatever the app
@@ -752,6 +753,7 @@ namespace Log
752753

753754
return buffer;
754755
}
756+
#endif // BUILDING_TESTS
755757

756758
void initialize(const std::string& name,
757759
const std::string& logLevel,

common/Log.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,11 @@ namespace Log
118118
char* _level_pos;
119119
};
120120

121-
/// Generates log entry prefix. Example follows (without the vertical bars).
122-
/// |wsd-07272-07298 2020-04-25 17:29:28.928697 -0400 [ websrv_poll ] TRC |
123-
/// This is fully signal-safe. Buffer must be at least 128 bytes.
124-
char* prefix(const std::chrono::time_point<std::chrono::system_clock>& tp, char* buffer,
125-
const std::string_view level);
121+
#ifdef BUILDING_TESTS
122+
/// Generates the reference log entry prefix. Do *not* use, except for tests.
123+
char* prefixReference(const std::chrono::time_point<std::chrono::system_clock>& tp,
124+
char* buffer, const std::string_view level);
125+
#endif
126126

127127
inline std::string_view
128128
prefix(const std::string_view level,

test/LoggingWhiteBoxTests.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ void LoggingTests::testLogPrefix()
7777
{
7878
char buffer[256];
7979
const auto str = prefix.update(level, tp);
80-
LOK_ASSERT_EQUAL_STR(Log::prefix(tp, buffer, level), str);
80+
LOK_ASSERT_EQUAL_STR(Log::prefixReference(tp, buffer, level), str);
8181
const auto firstPos = str.find_first_of(' ');
8282
const auto secondPos = str.find_first_of(' ', firstPos + 1);
8383
const auto thirdPos = str.find_first_of(' ', secondPos + 1);
@@ -141,13 +141,13 @@ void LoggingTests::testLogPrefix()
141141

142142
char buffer[256];
143143
const auto str = prefix.update(level, tp);
144-
LOK_ASSERT_EQUAL_STR(Log::prefix(tp, buffer, level), str);
144+
LOK_ASSERT_EQUAL_STR(Log::prefixReference(tp, buffer, level), str);
145145

146146
Log::Prefix prefix2;
147147
LOK_ASSERT_EQUAL_STR(buffer, prefix2.update(level, tp));
148148

149149
tp += std::chrono::seconds(1);
150-
LOK_ASSERT_EQUAL_STR(Log::prefix(tp, buffer, level), prefix2.update(level, tp));
150+
LOK_ASSERT_EQUAL_STR(Log::prefixReference(tp, buffer, level), prefix2.update(level, tp));
151151
}
152152

153153
// Randomized comparative tests.
@@ -159,7 +159,7 @@ void LoggingTests::testLogPrefix()
159159

160160
char buffer[256];
161161
const auto str = prefix.update(level, tp);
162-
LOK_ASSERT_EQUAL_STR(Log::prefix(tp, buffer, level), str);
162+
LOK_ASSERT_EQUAL_STR(Log::prefixReference(tp, buffer, level), str);
163163

164164
Log::Prefix prefix2;
165165
LOK_ASSERT_EQUAL_STR(buffer, prefix2.update(level, tp));
@@ -183,7 +183,7 @@ void LoggingTests::testLogPrefix()
183183
for (int i = 0; i < 1'000'000; ++i)
184184
{
185185
const auto tp = getSystemTimeRoundedToMillis(i * 32);
186-
[[maybe_unused]] const auto str = Log::prefix(tp, buffer, level);
186+
[[maybe_unused]] const auto str = Log::prefixReference(tp, buffer, level);
187187
}
188188

189189
LOG_INF("Old prefix took: " << sw.elapsed<std::chrono::microseconds>());

0 commit comments

Comments
 (0)