Changeset 280823 in webkit
- Timestamp:
- Aug 9, 2021, 8:11:48 PM (5 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
-
ChangeLog (modified) (1 diff)
-
Introduction.md (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ChangeLog
r280689 r280823 1 2021-08-09 Myles C. Maxfield <mmaxfield@apple.com> 2 3 Update logging docs after r280758 4 https://bugs.webkit.org/show_bug.cgi?id=228899 5 6 Reviewed by Fujii Hironori. 7 8 Add more information about logging. 9 10 * Introduction.md: 11 1 12 2021-08-05 Michael Catanzaro <mcatanzaro@gnome.org> 2 13 -
trunk/Introduction.md
r275482 r280823 1345 1345 # Logging in WebKit 1346 1346 1347 Some places in WebKit use a macro called `LOG_WITH_STREAM`. Here's an example invocation: 1347 ## Setup 1348 1349 Each framework (WebCore, WebKit, WebKitLegacy, WTF) enable their own logging infrastructure independently (though the infrastructure itself is shared). If you want to log a message, `#include` the relevant framework's `Logging.h` header. Then, you can use the macros below. 1350 1351 Beware that you can't `#include` multiple framework's `Logging.h` headers at the same time - they each define a macro `LOG_CHANNEL_PREFIX` which will conflict with each other. Only `#include` the `Logging.h` header from your specific framework. 1352 1353 If you want to do more advanced operations, like searching through the list of log channels, `#include` your framework's `LogInitialization.h` header. These do not conflict across frameworks, so you can do something like 1354 1355 ``` 1356 #include "LogInitialization.h" 1357 #include <WebCore/LogInitialization.h> 1358 #include <WTF/LogInitialization.h> 1359 ``` 1360 1361 Indeed, WebKit does this to initialize all frameworks' log channels during Web Process startup. 1362 1363 ## Logging messages 1364 1365 There are a few relevant macros for logging messages: 1366 1367 - `LOG()`: Log a printf-style message in debug builds. Requires you to name a logging channel to output to. 1368 - `LOG_WITH_STREAM()` Log an iostream-style message in debug builds. Requires you to name a logging channel to output to. 1369 - `RELEASE_LOG()`: Just like `LOG()` but logs in both debug and release builds. Requires you to name a logging channel to output to. 1370 - `WTFLogAlways()`: Mainly for local debugging, unconditionally output a message. Does not require a logging channel to output to. 1371 1372 Here's an example invocation of `LOG()`: 1373 1374 ``` 1375 LOG(MediaQueries, "HTMLMediaElement %p selectNextSourceChild evaluating media queries", this); 1376 ``` 1377 1378 That first argument is a log channel. These have 2 purposes: 1379 1380 - Individual channels can be enabled/disabled independently (So you can get all the WebGL logging without getting any Loading logging) 1381 - When multiple channels are enabled, and you're viewing the logs, you can search/filter by the channel 1382 1383 Here's an example invocation of `LOG_WITH_STREAM()`: 1348 1384 1349 1385 ``` … … 1351 1387 ``` 1352 1388 1353 The first argument is the _log channel_ and the second is the _log content_. By default, this logging is enabled in 1354 debug builds and disabled in release builds (see definition of `LOG_DISABLED`). 1355 1356 The only logs that will be printed are those whose channels you have enabled. You can specify the channels you want to 1357 enable by constructing a comma-separated list with the following syntax: 1358 1359 * `ChannelName` to enable logging for this channel 1360 * `all` to enable logging for all channels 1361 * `-ChannelName` to disable logging for this channel 1362 1363 Where you specify this list depends on the platform you are running WebKit on. 1389 The macro sets up a local variable named `stream` which the second argument can direct messages to. The second argument is a collection of statements - not expressions like `LOG()` and `RELEASE_LOG()`. So, you can do things like this: 1390 1391 ``` 1392 LOG_WITH_STREAM(TheLogChannel, 1393 for (const auto& something : stuffToLog) 1394 stream << " " << something; 1395 ); 1396 ``` 1397 1398 The reason why (most of) these use macros is so the entire thing can be compiled out when logging is disabled. Consider this: 1399 1400 ``` 1401 LOG(TheLogChannel, "The result is %d", someSuperComplicatedCalculation()); 1402 ``` 1403 1404 If these were not macros, you'd have to pay for `someSuperComplicatedCalculation()` whether logging is enabled or not. 1405 1406 ## Enabling and disabling log channels 1407 1408 Channels are enabled/disabled at startup by passing a carefully crafted string to `initializeLogChannelsIfNecessary()`. On the macOS and iOS ports, this string comes from the _defaults_ database. On other UNIX systems and Windows, it comes from environment variables. 1409 1410 You can read the grammar of this string in `initializeLogChannelsIfNecessary()`. Here is an example: 1411 1412 ``` 1413 WebGL -Loading 1414 ``` 1415 1416 You can also specify the string `all` to enable all logging. 1417 1418 On macOS/iOS and Windows, each framework has its own individually supplied string that it uses to enable its own logging channels. On Linux, all frameworks share the same string. 1364 1419 1365 1420 ### Linux … … 1371 1426 ``` 1372 1427 1373 ### Mac 1374 1375 Set a value for the `WebCoreLogging` key in [standardUserDefaults](https://developer.apple.com/documentation/foundation/nsuserdefaults/1416603-standarduserdefaults). 1428 ### macOS 1429 1430 On macOS, you can supply these strings with these terminal commands: 1431 1432 ``` 1433 % defaults write com.apple.WebKit.WebContent WTFLogging "Threading" 1434 % defaults write com.apple.WebKit.WebContent WebCoreLogging "WebGL" 1435 % defaults write com.apple.WebKit.WebContent WebKit2Logging "ResourceLoadStatistics" 1436 ``` 1437 1438 You may also need to specify these strings to `com.apple.WebKit.WebContent.Development`, the global domain, or the Safari container, depending on what you're running. 1376 1439 1377 1440 You may also pass this key and value as an argument: … … 1381 1444 ``` 1382 1445 1383 or set the key and value on the [NSGlobalDomain](https://developer.apple.com/documentation/foundation/nsglobaldomain).1384 1385 ```1386 defaults write NSGlobalDomain WebCoreLogging -string Scrolling1387 Tools/Scripts/run-minibrowser --debug1388 ```1389 1390 1446 ### Windows 1391 1447 1392 1448 Set the `WebCoreLogging` environment variable. 1449 1450 ## Adding a new log channel 1451 1452 Simply add a line to your framework's `Logging.h` header. Depending on how the accompanying `Logging.cpp` file is set up, you may need to add a parallel line there. That should be all you need. It is acceptable to have log channels in different frameworks with the same name - this is what `LOG_CHANNEL_PREFIX` is for.
Note:
See TracChangeset
for help on using the changeset viewer.