Skip to content

Commit 5e46bdf

Browse files
Alex Christensenwebkit-commit-queue
authored andcommitted
Make WTFLogChannelState and WTFLogLevel enum classes
https://bugs.webkit.org/show_bug.cgi?id=195904 Patch by Alex Christensen <achristensen@webkit.org> on 2019-03-18 Reviewed by Eric Carlson. Source/WebCore: * Modules/mediasource/SourceBuffer.cpp: (WebCore::removeSamplesFromTrackBuffer): * Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.cpp: (WebCore::LibWebRTCMediaEndpoint::OnStatsDelivered): (WebCore::LibWebRTCMediaEndpoint::statsLogInterval const): * dom/Document.cpp: (WebCore::messageLevelFromWTFLogLevel): * html/FTPDirectoryDocument.cpp: (WebCore::FTPDirectoryDocument::FTPDirectoryDocument): * html/HTMLMediaElement.cpp: (WebCore::HTMLMediaElement::seekTask): (WebCore::HTMLMediaElement::selectNextSourceChild): (WebCore::HTMLMediaElement::sourceWasAdded): (WebCore::HTMLMediaElement::sourceWasRemoved): * inspector/agents/WebConsoleAgent.cpp: (WebCore::WebConsoleAgent::getLoggingChannels): (WebCore::channelConfigurationForString): * platform/Logging.cpp: (WebCore::isLogChannelEnabled): (WebCore::setLogChannelToAccumulate): * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm: (-[WebCoreAVFMovieObserver observeValueForKeyPath:ofObject:change:context:]): * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.mm: (WebCore::MediaPlayerPrivateMediaStreamAVFObjC::enqueueVideoSample): * platform/mediastream/libwebrtc/LibWebRTCProvider.cpp: (WebCore::initializePeerConnectionFactoryAndThreads): * rendering/RenderLayerCompositor.cpp: (WebCore::compositingLogEnabled): Source/WebKit: * NetworkProcess/cache/NetworkCacheSpeculativeLoadManager.cpp: (WebKit::NetworkCache::logSpeculativeLoadingDiagnosticMessage): * NetworkProcess/webrtc/NetworkRTCProvider.cpp: (WebKit::NetworkRTCProvider::NetworkRTCProvider): Source/WTF: * wtf/Assertions.cpp: * wtf/Assertions.h: * wtf/Logger.h: (WTF::Logger::logAlways const): (WTF::Logger::error const): (WTF::Logger::warning const): (WTF::Logger::info const): (WTF::Logger::debug const): (WTF::Logger::willLog const): (WTF::Logger::log): * wtf/MemoryPressureHandler.cpp: * wtf/RefCountedLeakCounter.cpp: Tools: * TestWebKitAPI/Tests/WebCore/Logging.cpp: (TestWebKitAPI::TEST_F): Canonical link: https://commits.webkit.org/210201@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@243132 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent 5e26b76 commit 5e46bdf

27 files changed

Lines changed: 255 additions & 172 deletions

Source/WTF/ChangeLog

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1+
2019-03-18 Alex Christensen <achristensen@webkit.org>
2+
3+
Make WTFLogChannelState and WTFLogLevel enum classes
4+
https://bugs.webkit.org/show_bug.cgi?id=195904
5+
6+
Reviewed by Eric Carlson.
7+
8+
* wtf/Assertions.cpp:
9+
* wtf/Assertions.h:
10+
* wtf/Logger.h:
11+
(WTF::Logger::logAlways const):
12+
(WTF::Logger::error const):
13+
(WTF::Logger::warning const):
14+
(WTF::Logger::info const):
15+
(WTF::Logger::debug const):
16+
(WTF::Logger::willLog const):
17+
(WTF::Logger::log):
18+
* wtf/MemoryPressureHandler.cpp:
19+
* wtf/RefCountedLeakCounter.cpp:
20+
121
2019-03-18 Darin Adler <darin@apple.com>
222

323
Cut down on use of StringBuffer, possibly leading toward removing it entirely

Source/WTF/wtf/AggregateLogger.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,32 +57,32 @@ class AggregateLogger : public Logger {
5757
// on some systems, so don't allow it.
5858
UNUSED_PARAM(channel);
5959
#else
60-
log(channel, WTFLogLevelAlways, arguments...);
60+
log(channel, WTFLogLevel::Always, arguments...);
6161
#endif
6262
}
6363

6464
template<typename... Arguments>
6565
inline void error(WTFLogChannel& channel, const Arguments&... arguments) const
6666
{
67-
log(channel, WTFLogLevelError, arguments...);
67+
log(channel, WTFLogLevel::Error, arguments...);
6868
}
6969

7070
template<typename... Arguments>
7171
inline void warning(WTFLogChannel& channel, const Arguments&... arguments) const
7272
{
73-
log(channel, WTFLogLevelWarning, arguments...);
73+
log(channel, WTFLogLevel::Warning, arguments...);
7474
}
7575

7676
template<typename... Arguments>
7777
inline void info(WTFLogChannel& channel, const Arguments&... arguments) const
7878
{
79-
log(channel, WTFLogLevelInfo, arguments...);
79+
log(channel, WTFLogLevel::Info, arguments...);
8080
}
8181

8282
template<typename... Arguments>
8383
inline void debug(WTFLogChannel& channel, const Arguments&... arguments) const
8484
{
85-
log(channel, WTFLogLevelDebug, arguments...);
85+
log(channel, WTFLogLevel::Debug, arguments...);
8686
}
8787

8888
inline bool willLog(const WTFLogChannel& channel, WTFLogLevel level) const

Source/WTF/wtf/Assertions.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -409,15 +409,15 @@ void WTFSetLogChannelLevel(WTFLogChannel* channel, WTFLogLevel level)
409409

410410
bool WTFWillLogWithLevel(WTFLogChannel* channel, WTFLogLevel level)
411411
{
412-
return channel->level >= level && channel->state != WTFLogChannelOff;
412+
return channel->level >= level && channel->state != WTFLogChannelState::Off;
413413
}
414414

415415
void WTFLogWithLevel(WTFLogChannel* channel, WTFLogLevel level, const char* format, ...)
416416
{
417-
if (level != WTFLogLevelAlways && level > channel->level)
417+
if (level != WTFLogLevel::Always && level > channel->level)
418418
return;
419419

420-
if (channel->level != WTFLogLevelAlways && channel->state == WTFLogChannelOff)
420+
if (channel->level != WTFLogLevel::Always && channel->state == WTFLogChannelState::Off)
421421
return;
422422

423423
va_list args;
@@ -432,15 +432,15 @@ void WTFLogWithLevel(WTFLogChannel* channel, WTFLogLevel level, const char* form
432432

433433
static void WTFLogVaList(WTFLogChannel* channel, const char* format, va_list args)
434434
{
435-
if (channel->state == WTFLogChannelOff)
435+
if (channel->state == WTFLogChannelState::Off)
436436
return;
437437

438-
if (channel->state == WTFLogChannelOn) {
438+
if (channel->state == WTFLogChannelState::On) {
439439
vprintf_stderr_with_trailing_newline(format, args);
440440
return;
441441
}
442442

443-
ASSERT(channel->state == WTFLogChannelOnWithAccumulation);
443+
ASSERT(channel->state == WTFLogChannelState::OnWithAccumulation);
444444

445445
ALLOW_NONLITERAL_FORMAT_BEGIN
446446
String loggingString = WTF::createWithFormatAndArguments(format, args);
@@ -466,7 +466,7 @@ void WTFLog(WTFLogChannel* channel, const char* format, ...)
466466

467467
void WTFLogVerbose(const char* file, int line, const char* function, WTFLogChannel* channel, const char* format, ...)
468468
{
469-
if (channel->state != WTFLogChannelOn)
469+
if (channel->state != WTFLogChannelState::On)
470470
return;
471471

472472
va_list args;
@@ -533,9 +533,9 @@ void WTFInitializeLogChannelStatesFromString(WTFLogChannel* channels[], size_t c
533533
Vector<String> componentInfo = logLevelComponent.split('=');
534534
String component = componentInfo[0].stripWhiteSpace();
535535

536-
WTFLogChannelState logChannelState = WTFLogChannelOn;
536+
WTFLogChannelState logChannelState = WTFLogChannelState::On;
537537
if (component.startsWith('-')) {
538-
logChannelState = WTFLogChannelOff;
538+
logChannelState = WTFLogChannelState::Off;
539539
component = component.substring(1);
540540
}
541541

@@ -544,17 +544,17 @@ void WTFInitializeLogChannelStatesFromString(WTFLogChannel* channels[], size_t c
544544
continue;
545545
}
546546

547-
WTFLogLevel logChannelLevel = WTFLogLevelError;
547+
WTFLogLevel logChannelLevel = WTFLogLevel::Error;
548548
if (componentInfo.size() > 1) {
549549
String level = componentInfo[1].stripWhiteSpace();
550550
if (equalLettersIgnoringASCIICase(level, "error"))
551-
logChannelLevel = WTFLogLevelError;
551+
logChannelLevel = WTFLogLevel::Error;
552552
else if (equalLettersIgnoringASCIICase(level, "warning"))
553-
logChannelLevel = WTFLogLevelWarning;
553+
logChannelLevel = WTFLogLevel::Warning;
554554
else if (equalLettersIgnoringASCIICase(level, "info"))
555-
logChannelLevel = WTFLogLevelInfo;
555+
logChannelLevel = WTFLogLevel::Info;
556556
else if (equalLettersIgnoringASCIICase(level, "debug"))
557-
logChannelLevel = WTFLogLevelDebug;
557+
logChannelLevel = WTFLogLevel::Debug;
558558
else
559559
WTFLogAlways("Unknown logging level: %s", level.utf8().data());
560560
}

Source/WTF/wtf/Assertions.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,13 @@ extern "C" {
148148
#define NO_RETURN_DUE_TO_CRASH
149149
#endif
150150

151-
typedef enum { WTFLogChannelOff, WTFLogChannelOn, WTFLogChannelOnWithAccumulation } WTFLogChannelState;
152-
typedef enum { WTFLogLevelAlways, WTFLogLevelError, WTFLogLevelWarning, WTFLogLevelInfo, WTFLogLevelDebug } WTFLogLevel;
151+
#ifdef __cplusplus
152+
enum class WTFLogChannelState : uint8_t { Off, On, OnWithAccumulation };
153+
enum class WTFLogLevel : uint8_t { Always, Error, Warning, Info, Debug };
154+
#else
155+
typedef uint8_t WTFLogChannelState;
156+
typedef uint8_t WTFLogLevel;
157+
#endif
153158

154159
typedef struct {
155160
WTFLogChannelState state;
@@ -174,10 +179,10 @@ typedef struct {
174179
#if !defined(DEFINE_LOG_CHANNEL)
175180
#if RELEASE_LOG_DISABLED
176181
#define DEFINE_LOG_CHANNEL(name, subsystem) \
177-
WTFLogChannel LOG_CHANNEL(name) = { WTFLogChannelOff, #name, WTFLogLevelError };
182+
WTFLogChannel LOG_CHANNEL(name) = { (WTFLogChannelState)0, #name, (WTFLogLevel)1 };
178183
#else
179184
#define DEFINE_LOG_CHANNEL(name, subsystem) \
180-
WTFLogChannel LOG_CHANNEL(name) = { WTFLogChannelOff, #name, WTFLogLevelError, subsystem, OS_LOG_DEFAULT };
185+
WTFLogChannel LOG_CHANNEL(name) = { (WTFLogChannelState)0, #name, (WTFLogLevel)1, subsystem, OS_LOG_DEFAULT };
181186
#endif
182187
#endif
183188

Source/WTF/wtf/Logger.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -126,58 +126,58 @@ class Logger : public RefCounted<Logger> {
126126
// on some systems, so don't allow it.
127127
UNUSED_PARAM(channel);
128128
#else
129-
if (!willLog(channel, WTFLogLevelAlways))
129+
if (!willLog(channel, WTFLogLevel::Always))
130130
return;
131131

132-
log(channel, WTFLogLevelAlways, arguments...);
132+
log(channel, WTFLogLevel::Always, arguments...);
133133
#endif
134134
}
135135

136136
template<typename... Arguments>
137137
inline void error(WTFLogChannel& channel, const Arguments&... arguments) const
138138
{
139-
if (!willLog(channel, WTFLogLevelError))
139+
if (!willLog(channel, WTFLogLevel::Error))
140140
return;
141141

142-
log(channel, WTFLogLevelError, arguments...);
142+
log(channel, WTFLogLevel::Error, arguments...);
143143
}
144144

145145
template<typename... Arguments>
146146
inline void warning(WTFLogChannel& channel, const Arguments&... arguments) const
147147
{
148-
if (!willLog(channel, WTFLogLevelWarning))
148+
if (!willLog(channel, WTFLogLevel::Warning))
149149
return;
150150

151-
log(channel, WTFLogLevelWarning, arguments...);
151+
log(channel, WTFLogLevel::Warning, arguments...);
152152
}
153153

154154
template<typename... Arguments>
155155
inline void info(WTFLogChannel& channel, const Arguments&... arguments) const
156156
{
157-
if (!willLog(channel, WTFLogLevelInfo))
157+
if (!willLog(channel, WTFLogLevel::Info))
158158
return;
159159

160-
log(channel, WTFLogLevelInfo, arguments...);
160+
log(channel, WTFLogLevel::Info, arguments...);
161161
}
162162

163163
template<typename... Arguments>
164164
inline void debug(WTFLogChannel& channel, const Arguments&... arguments) const
165165
{
166-
if (!willLog(channel, WTFLogLevelDebug))
166+
if (!willLog(channel, WTFLogLevel::Debug))
167167
return;
168168

169-
log(channel, WTFLogLevelDebug, arguments...);
169+
log(channel, WTFLogLevel::Debug, arguments...);
170170
}
171171

172172
inline bool willLog(const WTFLogChannel& channel, WTFLogLevel level) const
173173
{
174174
if (!m_enabled)
175175
return false;
176176

177-
if (level <= WTFLogLevelError)
177+
if (level <= WTFLogLevel::Error)
178178
return true;
179179

180-
if (channel.state == WTFLogChannelOff || level > channel.level)
180+
if (channel.state == WTFLogChannelState::Off || level > channel.level)
181181
return false;
182182

183183
return m_enabled;
@@ -242,7 +242,7 @@ class Logger : public RefCounted<Logger> {
242242
os_log(channel.osLogChannel, "%{public}s", logMessage.utf8().data());
243243
#endif
244244

245-
if (channel.state == WTFLogChannelOff || level > channel.level)
245+
if (channel.state == WTFLogChannelState::Off || level > channel.level)
246246
return;
247247

248248
for (Observer& observer : observers())

Source/WTF/wtf/MemoryPressureHandler.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@
3535
namespace WTF {
3636

3737
#if RELEASE_LOG_DISABLED
38-
WTFLogChannel LogMemoryPressure = { WTFLogChannelOn, "MemoryPressure", WTFLogLevelError };
38+
WTFLogChannel LogMemoryPressure = { WTFLogChannelState::On, "MemoryPressure", WTFLogLevel::Error };
3939
#else
40-
WTFLogChannel LogMemoryPressure = { WTFLogChannelOn, "MemoryPressure", WTFLogLevelError, LOG_CHANNEL_WEBKIT_SUBSYSTEM, OS_LOG_DEFAULT };
40+
WTFLogChannel LogMemoryPressure = { WTFLogChannelState::On, "MemoryPressure", WTFLogLevel::Error, LOG_CHANNEL_WEBKIT_SUBSYSTEM, OS_LOG_DEFAULT };
4141
#endif
4242

4343
WTF_EXPORT_PRIVATE bool MemoryPressureHandler::ReliefLogger::s_loggingEnabled = false;

Source/WTF/wtf/RefCountedLeakCounter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ void RefCountedLeakCounter::decrement() { }
4040

4141
#define LOG_CHANNEL_PREFIX Log
4242
#if RELEASE_LOG_DISABLED
43-
static WTFLogChannel LogRefCountedLeaks = { WTFLogChannelOn, "RefCountedLeaks", WTFLogLevelError };
43+
static WTFLogChannel LogRefCountedLeaks = { WTFLogChannelState::On, "RefCountedLeaks", WTFLogLevel::Error };
4444
#else
45-
static WTFLogChannel LogRefCountedLeaks = { WTFLogChannelOn, "RefCountedLeaks", WTFLogLevelError, LOG_CHANNEL_WEBKIT_SUBSYSTEM, OS_LOG_DEFAULT };
45+
static WTFLogChannel LogRefCountedLeaks = { WTFLogChannelState::On, "RefCountedLeaks", WTFLogLevel::Error, LOG_CHANNEL_WEBKIT_SUBSYSTEM, OS_LOG_DEFAULT };
4646
#endif
4747

4848
typedef HashCountedSet<const char*, PtrHash<const char*>> ReasonSet;

Source/WebCore/ChangeLog

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,39 @@
1+
2019-03-18 Alex Christensen <achristensen@webkit.org>
2+
3+
Make WTFLogChannelState and WTFLogLevel enum classes
4+
https://bugs.webkit.org/show_bug.cgi?id=195904
5+
6+
Reviewed by Eric Carlson.
7+
8+
* Modules/mediasource/SourceBuffer.cpp:
9+
(WebCore::removeSamplesFromTrackBuffer):
10+
* Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.cpp:
11+
(WebCore::LibWebRTCMediaEndpoint::OnStatsDelivered):
12+
(WebCore::LibWebRTCMediaEndpoint::statsLogInterval const):
13+
* dom/Document.cpp:
14+
(WebCore::messageLevelFromWTFLogLevel):
15+
* html/FTPDirectoryDocument.cpp:
16+
(WebCore::FTPDirectoryDocument::FTPDirectoryDocument):
17+
* html/HTMLMediaElement.cpp:
18+
(WebCore::HTMLMediaElement::seekTask):
19+
(WebCore::HTMLMediaElement::selectNextSourceChild):
20+
(WebCore::HTMLMediaElement::sourceWasAdded):
21+
(WebCore::HTMLMediaElement::sourceWasRemoved):
22+
* inspector/agents/WebConsoleAgent.cpp:
23+
(WebCore::WebConsoleAgent::getLoggingChannels):
24+
(WebCore::channelConfigurationForString):
25+
* platform/Logging.cpp:
26+
(WebCore::isLogChannelEnabled):
27+
(WebCore::setLogChannelToAccumulate):
28+
* platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
29+
(-[WebCoreAVFMovieObserver observeValueForKeyPath:ofObject:change:context:]):
30+
* platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.mm:
31+
(WebCore::MediaPlayerPrivateMediaStreamAVFObjC::enqueueVideoSample):
32+
* platform/mediastream/libwebrtc/LibWebRTCProvider.cpp:
33+
(WebCore::initializePeerConnectionFactoryAndThreads):
34+
* rendering/RenderLayerCompositor.cpp:
35+
(WebCore::compositingLogEnabled):
36+
137
2019-03-18 Said Abou-Hallawa <sabouhallawa@apple.com>
238

339
Remove the SVG property tear off objects for SVGStringList

Source/WebCore/Modules/mediasource/SourceBuffer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ static PlatformTimeRanges removeSamplesFromTrackBuffer(const DecodeOrderSampleMa
741741
size_t bytesRemoved = 0;
742742
auto logIdentifier = WTF::Logger::LogSiteIdentifier(buffer->logClassName(), logPrefix, buffer->logIdentifier());
743743
auto& logger = buffer->logger();
744-
auto willLog = logger.willLog(buffer->logChannel(), WTFLogLevelDebug);
744+
auto willLog = logger.willLog(buffer->logChannel(), WTFLogLevel::Debug);
745745
#else
746746
UNUSED_PARAM(logPrefix);
747747
UNUSED_PARAM(buffer);

Source/WebCore/Modules/mediastream/libwebrtc/LibWebRTCMediaEndpoint.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -865,7 +865,7 @@ void LibWebRTCMediaEndpoint::OnStatsDelivered(const rtc::scoped_refptr<const web
865865
}
866866

867867
for (auto iterator = report->begin(); iterator != report->end(); ++iterator) {
868-
if (logger().willLog(logChannel(), WTFLogLevelDebug)) {
868+
if (logger().willLog(logChannel(), WTFLogLevel::Debug)) {
869869
// Stats are very verbose, let's only display them in inspector console in verbose mode.
870870
logger().debug(LogWebRTC,
871871
Logger::LogSiteIdentifier("LibWebRTCMediaEndpoint", "OnStatsDelivered", logIdentifier()),
@@ -904,7 +904,7 @@ WTFLogChannel& LibWebRTCMediaEndpoint::logChannel() const
904904

905905
Seconds LibWebRTCMediaEndpoint::statsLogInterval(int64_t reportTimestamp) const
906906
{
907-
if (logger().willLog(logChannel(), WTFLogLevelInfo))
907+
if (logger().willLog(logChannel(), WTFLogLevel::Info))
908908
return 2_s;
909909

910910
if (reportTimestamp - m_statsFirstDeliveredTimestamp > 15000000)

0 commit comments

Comments
 (0)