Changeset 220938 in webkit


Ignore:
Timestamp:
Aug 18, 2017 3:46:17 PM (7 years ago)
Author:
eric.carlson@apple.com
Message:

Add WTFLogChannel level to allow runtime log filtering
https://bugs.webkit.org/show_bug.cgi?id=175731
<rdar://problem/33967234>

Reviewed by Jer Noble.
Source/WTF:

Add WTFLog*, LOG, and RELEASE_LOG variants that take a "log level" parameter so code
can include logging statements that are only conditionally emitted.

  • wtf/Assertions.cpp:
  • wtf/Assertions.h:
  • wtf/MemoryPressureHandler.cpp:
  • wtf/RefCountedLeakCounter.cpp:

Tools:

  • TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
  • TestWebKitAPI/Tests/WebCore/Logging.cpp: Added.

(TestWebKitAPI::LoggingTest::output):
(TestWebKitAPI::TEST_F):

Location:
trunk
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r220926 r220938  
     12017-08-18  Eric Carlson  <eric.carlson@apple.com>
     2
     3        Add WTFLogChannel level to allow runtime log filtering
     4        https://bugs.webkit.org/show_bug.cgi?id=175731
     5        <rdar://problem/33967234>
     6
     7        Reviewed by Jer Noble.
     8       
     9        Add WTFLog*, LOG, and RELEASE_LOG variants that take a "log level" parameter so code
     10        can include logging statements that are only conditionally emitted.
     11
     12        * wtf/Assertions.cpp:
     13        * wtf/Assertions.h:
     14        * wtf/MemoryPressureHandler.cpp:
     15        * wtf/RefCountedLeakCounter.cpp:
     16
    1172017-08-18  Per Arne Vollan  <pvollan@apple.com>
    218
  • trunk/Source/WTF/wtf/Assertions.cpp

    r219506 r220938  
    411411}
    412412
     413void WTFSetLogChannelLevel(WTFLogChannel* channel, WTFLogLevel level)
     414{
     415    channel->level = level;
     416    WTFLog(channel, "Channel \"%s\" level set to %i", channel->name, level);
     417}
     418
     419bool WTFWillLogWithLevel(WTFLogChannel* channel, WTFLogLevel level)
     420{
     421    return channel->level >= level && channel->state != WTFLogChannelOff;
     422}
     423
     424void WTFLogWithLevel(WTFLogChannel* channel, WTFLogLevel level, const char* format, ...)
     425{
     426    if (channel->level < level)
     427        return;
     428
     429    if (channel->state == WTFLogChannelOff)
     430        return;
     431
     432    va_list args;
     433    va_start(args, format);
     434
     435#if COMPILER(CLANG)
     436#pragma clang diagnostic push
     437#pragma clang diagnostic ignored "-Wformat-nonliteral"
     438#endif
     439    WTFLog(channel, format, args);
     440#if COMPILER(CLANG)
     441#pragma clang diagnostic pop
     442#endif
     443
     444    va_end(args);
     445}
     446
    413447void WTFLog(WTFLogChannel* channel, const char* format, ...)
    414448{
     
    523557
    524558    for (size_t i = 0; i < components.size(); ++i) {
    525         String component = components[i];
     559        Vector<String> componentInfo;
     560        components[i].split('=', componentInfo);
     561        String component = componentInfo[0].stripWhiteSpace();
    526562
    527563        WTFLogChannelState logChannelState = WTFLogChannelOn;
     
    536572        }
    537573
    538         if (WTFLogChannel* channel = WTFLogChannelByName(channels, count, component.utf8().data()))
     574        WTFLogLevel logChannelLevel = WTFLogLevelError;
     575        if (componentInfo.size() > 1) {
     576            String level = componentInfo[1].stripWhiteSpace();
     577            if (equalLettersIgnoringASCIICase(level, "error"))
     578                logChannelLevel = WTFLogLevelError;
     579            else if (equalLettersIgnoringASCIICase(level, "warning"))
     580                logChannelLevel = WTFLogLevelWarning;
     581            else if (equalLettersIgnoringASCIICase(level, "info"))
     582                logChannelLevel = WTFLogLevelInfo;
     583            else if (equalLettersIgnoringASCIICase(level, "debug"))
     584                logChannelLevel = WTFLogLevelDebug;
     585            else
     586                WTFLogAlways("Unknown logging level: %s", level.utf8().data());
     587        }
     588
     589        if (WTFLogChannel* channel = WTFLogChannelByName(channels, count, component.utf8().data())) {
    539590            channel->state = logChannelState;
    540         else
     591            channel->level = logChannelLevel;
     592        } else
    541593            WTFLogAlways("Unknown logging channel: %s", component.utf8().data());
    542594    }
  • trunk/Source/WTF/wtf/Assertions.h

    r219250 r220938  
    149149
    150150typedef enum { WTFLogChannelOff, WTFLogChannelOn, WTFLogChannelOnWithAccumulation } WTFLogChannelState;
     151typedef enum { WTFLogLevelError, WTFLogLevelWarning, WTFLogLevelInfo, WTFLogLevelDebug } WTFLogLevel;
    151152
    152153typedef struct {
    153154    WTFLogChannelState state;
    154155    const char* name;
     156    WTFLogLevel level;
    155157#if !RELEASE_LOG_DISABLED
    156158    const char* subsystem;
     
    172174#if RELEASE_LOG_DISABLED
    173175#define DEFINE_LOG_CHANNEL(name, subsystem) \
    174     WTFLogChannel LOG_CHANNEL(name) = { WTFLogChannelOff, #name };
     176    WTFLogChannel LOG_CHANNEL(name) = { WTFLogChannelOff, #name, WTFLogLevelError };
    175177#else
    176178#define DEFINE_LOG_CHANNEL(name, subsystem) \
    177     WTFLogChannel LOG_CHANNEL(name) = { WTFLogChannelOff, #name, subsystem, OS_LOG_DEFAULT };
     179    WTFLogChannel LOG_CHANNEL(name) = { WTFLogChannelOff, #name, WTFLogLevelError, subsystem, OS_LOG_DEFAULT };
    178180#endif
    179181#endif
     
    191193WTF_EXPORT_PRIVATE WTFLogChannel* WTFLogChannelByName(WTFLogChannel*[], size_t count, const char*);
    192194WTF_EXPORT_PRIVATE void WTFInitializeLogChannelStatesFromString(WTFLogChannel*[], size_t count, const char*);
     195WTF_EXPORT_PRIVATE void WTFLogWithLevel(WTFLogChannel*, WTFLogLevel, const char* format, ...) WTF_ATTRIBUTE_PRINTF(3, 4);
     196WTF_EXPORT_PRIVATE void WTFSetLogChannelLevel(WTFLogChannel*, WTFLogLevel);
     197WTF_EXPORT_PRIVATE bool WTFWillLogWithLevel(WTFLogChannel*, WTFLogLevel);
    193198
    194199WTF_EXPORT_PRIVATE void WTFGetBacktrace(void** stack, int* size);
     
    428433#endif
    429434
     435/* LOG_WITH_LEVEL */
     436
     437#if LOG_DISABLED
     438#define LOG_WITH_LEVEL(channel, level, ...) ((void)0)
     439#else
     440#define LOG_WITH_LEVEL(channel, level, ...) WTFLogWithLevel(&LOG_CHANNEL(channel), level, __VA_ARGS__)
     441#endif
     442
    430443/* RELEASE_LOG */
    431444
     
    436449#define RELEASE_LOG_IF(      isAllowed, channel, format, ...) ((void)0)
    437450#define RELEASE_LOG_ERROR_IF(isAllowed, channel, format, ...) do { if (isAllowed) RELEASE_LOG_ERROR(channel, format, ##__VA_ARGS__); } while (0)
     451
     452#define RELEASE_LOG_WITH_LEVEL(              channel, level, format, ...) ((void)0)
     453#define RELEASE_LOG_WITH_LEVEL_IF(isAllowed, channel, level, format, ...) do { if (isAllowed) RELEASE_LOG_WITH_LEVEL(channel, level, format, ##__VA_ARGS__); } while (0)
    438454#else
    439455#define RELEASE_LOG(      channel, format, ...) os_log(      LOG_CHANNEL(channel).osLogChannel, format, ##__VA_ARGS__)
     
    442458#define RELEASE_LOG_IF(      isAllowed, channel, format, ...) do { if (isAllowed) RELEASE_LOG(      channel, format, ##__VA_ARGS__); } while (0)
    443459#define RELEASE_LOG_ERROR_IF(isAllowed, channel, format, ...) do { if (isAllowed) RELEASE_LOG_ERROR(channel, format, ##__VA_ARGS__); } while (0)
     460
     461#define RELEASE_LOG_WITH_LEVEL(channel, logLevel, format, ...) do { \
     462    if (LOG_CHANNEL(channel).level >= (logLevel)) \
     463        os_log(LOG_CHANNEL(channel).osLogChannel, format, ##__VA_ARGS__); \
     464} while (0)
     465
     466#define RELEASE_LOG_WITH_LEVEL_IF(isAllowed, channel, logLevel, format, ...) do { \
     467    if ((isAllowed) && LOG_CHANNEL(channel).level >= (logLevel)) \
     468        os_log(LOG_CHANNEL(channel).osLogChannel, format, ##__VA_ARGS__); \
     469} while (0)
    444470#endif
    445471
  • trunk/Source/WTF/wtf/MemoryPressureHandler.cpp

    r219595 r220938  
    3535
    3636#if RELEASE_LOG_DISABLED
    37 WTFLogChannel LogMemoryPressure = { WTFLogChannelOn, "MemoryPressure" };
     37WTFLogChannel LogMemoryPressure = { WTFLogChannelOn, "MemoryPressure", WTFLogLevelError };
    3838#else
    39 WTFLogChannel LogMemoryPressure = { WTFLogChannelOn, "MemoryPressure", LOG_CHANNEL_WEBKIT_SUBSYSTEM, OS_LOG_DEFAULT };
     39WTFLogChannel LogMemoryPressure = { WTFLogChannelOn, "MemoryPressure", WTFLogLevelError, LOG_CHANNEL_WEBKIT_SUBSYSTEM, OS_LOG_DEFAULT };
    4040#endif
    4141
  • trunk/Source/WTF/wtf/RefCountedLeakCounter.cpp

    r205275 r220938  
    4141#define LOG_CHANNEL_PREFIX Log
    4242#if RELEASE_LOG_DISABLED
    43 static WTFLogChannel LogRefCountedLeaks = { WTFLogChannelOn, "RefCountedLeaks" };
     43static WTFLogChannel LogRefCountedLeaks = { WTFLogChannelOn, "RefCountedLeaks", WTFLogLevelError };
    4444#else
    45 static WTFLogChannel LogRefCountedLeaks = { WTFLogChannelOn, "RefCountedLeaks", LOG_CHANNEL_WEBKIT_SUBSYSTEM, OS_LOG_DEFAULT };
     45static WTFLogChannel LogRefCountedLeaks = { WTFLogChannelOn, "RefCountedLeaks", WTFLogLevelError, LOG_CHANNEL_WEBKIT_SUBSYSTEM, OS_LOG_DEFAULT };
    4646#endif
    4747
  • trunk/Tools/ChangeLog

    r220925 r220938  
     12017-08-18  Eric Carlson  <eric.carlson@apple.com>
     2
     3        Add WTFLogChannel level to allow runtime log filtering
     4        https://bugs.webkit.org/show_bug.cgi?id=175731
     5        <rdar://problem/33967234>
     6
     7        Reviewed by Jer Noble.
     8
     9        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
     10        * TestWebKitAPI/Tests/WebCore/Logging.cpp: Added.
     11        (TestWebKitAPI::LoggingTest::output):
     12        (TestWebKitAPI::TEST_F):
     13
    1142017-08-18  Alexey Proskuryakov  <ap@apple.com>
    215
  • trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj

    r220865 r220938  
    2626                07492B3C1DF8B86600633DE1 /* enumerateMediaDevices.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 07492B391DF8ADA400633DE1 /* enumerateMediaDevices.html */; };
    2727                074994421EA5034B000DA44E /* getUserMedia.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 4A410F4D19AF7BEF002EBAB5 /* getUserMedia.html */; };
     28                076E507F1F4513D6006E9F5A /* Logging.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 076E507E1F45031E006E9F5A /* Logging.cpp */; };
    2829                0799C3491EBA2D7B003B7532 /* UserMediaDisabled.mm in Sources */ = {isa = PBXBuildFile; fileRef = 07EDEFAC1EB9400C00D43292 /* UserMediaDisabled.mm */; };
    2930                0799C34B1EBA3301003B7532 /* disableGetUserMedia.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 0799C34A1EBA32F4003B7532 /* disableGetUserMedia.html */; };
     
    991992                07492B3A1DF8AE2D00633DE1 /* EnumerateMediaDevices.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = EnumerateMediaDevices.cpp; sourceTree = "<group>"; };
    992993                0766DD1F1A5AD5200023E3BB /* PendingAPIRequestURL.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PendingAPIRequestURL.cpp; sourceTree = "<group>"; };
     994                076E507E1F45031E006E9F5A /* Logging.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Logging.cpp; sourceTree = "<group>"; };
    993995                0799C34A1EBA32F4003B7532 /* disableGetUserMedia.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = disableGetUserMedia.html; sourceTree = "<group>"; };
    994996                07C046C91E42573E007201E7 /* CARingBuffer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CARingBuffer.cpp; sourceTree = "<group>"; };
     
    20312033                                7A909A751D877475007E10F8 /* IntSize.cpp */,
    20322034                                14464012167A8305000BD218 /* LayoutUnit.cpp */,
     2035                                076E507E1F45031E006E9F5A /* Logging.cpp */,
    20332036                                CD225C071C45A69200140761 /* ParsedContentRange.cpp */,
    20342037                                CDCFA7A91E45122F00C2433D /* SampleMap.cpp */,
     
    32553258                                7CCE7F0C1A411AE600447C4C /* PrivateBrowsingPushStateNoHistoryCallback.cpp in Sources */,
    32563259                                4647B1261EBA3B850041D7EF /* ProcessDidTerminate.cpp in Sources */,
     3260                                076E507F1F4513D6006E9F5A /* Logging.cpp in Sources */,
    32573261                                7C83E0C11D0A652F00FEBCF3 /* ProvisionalURLNotChange.mm in Sources */,
    32583262                                7CCE7EC81A411A7E00447C4C /* PublicSuffix.mm in Sources */,
Note: See TracChangeset for help on using the changeset viewer.