-
Notifications
You must be signed in to change notification settings - Fork 241
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(playwright): Log debug info (#924)
* feat(playwright): Log debug info * debug as string * debug note
- Loading branch information
Showing
9 changed files
with
93 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# How to get internal logs | ||
_Contributors: [Dario Kondratiuk](https://www.hardkoded.com/)_ | ||
|
||
## Problem | ||
|
||
You need to get the internal log information to debug a problem. | ||
|
||
## Solution | ||
|
||
Playwright Sharp uses a [.NET Logger Factory](https://docs.microsoft.com/en-us/dotnet/api/microsoft.extensions.logging.iloggerfactory?view=dotnet-plat-ext-3.1&WT.mc_id=DT-MVP-5003814) to log the communication between the library and the playwright driver. | ||
|
||
It uses two categories: | ||
* All the communication between the library and the driver is under the `PlaywrightSharp.Transport.Connection` category. | ||
* The debug information coming from the driver, when `debug: "pw:api"` is set, is under the `PlaywrightSharp.Playwright` category. The `debug` argument is a shortcut to the `DEBUG` environment variable Playwright uses to setup its logging tool. | ||
|
||
You create an `ILoggerFactory` in the same way you would build a logger in ASP.NET. You can also use extension methods, like [AddDebug](https://docs.microsoft.com/en-us/dotnet/api/microsoft.extensions.logging.debugloggerfactoryextensions.adddebug?view=dotnet-plat-ext-3.1&WT.mc_id=DT-MVP-5003814) to send the log in the output window, or [AddConsole](https://docs.microsoft.com/en-us/dotnet/api/microsoft.extensions.logging.consoleloggerextensions.addconsole?view=dotnet-plat-ext-3.1&WT.mc_id=DT-MVP-5003814) to send it to the console. | ||
|
||
```cs | ||
ILoggerFactory loggerFactory = LoggerFactory.Create(builder => | ||
{ | ||
builder.SetMinimumLevel(LogLevel.Debug); | ||
builder.AddDebug(); | ||
builder.AddFilter((f, _) => f == "PlaywrightSharp.Playwright"); | ||
}); | ||
|
||
using var playwright = await Playwright.CreateAsync(loggerFactory, debug: "pw:api"); | ||
``` | ||
|
||
The `debug` is only needed for the `PlaywrightSharp.Playwright` category. `PlaywrightSharp.Transport.Connection` logs will come with no extra argument. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
- name: Basic Examples | ||
items: | ||
- name: How to take screenshots and save it as a file | ||
href: Page.ScreenshotAsync.md | ||
href: Page.ScreenshotAsync.md | ||
- name: How to get internal logs | ||
href: Playwright.Logger.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using System; | ||
|
||
namespace PlaywrightSharp.Transport | ||
{ | ||
/// <summary> | ||
/// Log received event arguments. | ||
/// <see cref="IConnectionTransport.LogReceived"/>. | ||
/// </summary> | ||
public class LogReceivedEventArgs : EventArgs | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="LogReceivedEventArgs"/> class. | ||
/// </summary> | ||
/// <param name="message">Message.</param> | ||
public LogReceivedEventArgs(string message) => Message = message; | ||
|
||
/// <summary> | ||
/// Transport message. | ||
/// </summary> | ||
public string Message { get; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters