Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initialize logging earlier #2218

Merged
merged 1 commit into from
Jun 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions lib/PuppeteerSharp/Browser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ internal Browser(
Connection = connection;
_closeCallback = closeCallback;
_targetFilterCallback = targetFilter ?? ((TargetInfo _) => true);
_logger = Connection.LoggerFactory.CreateLogger<Browser>();
_isPageTargetFunc =
isPageTargetFunc ??
new Func<TargetInfo, bool>((TargetInfo target) =>
Expand Down Expand Up @@ -75,8 +76,6 @@ internal Browser(
CreateTarget,
_targetFilterCallback);
}

_logger = Connection.LoggerFactory.CreateLogger<Browser>();
}

/// <inheritdoc/>
Expand Down
2 changes: 1 addition & 1 deletion lib/PuppeteerSharp/ChromeTargetManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ public ChromeTargetManager(
_connection = connection;
_targetFilterFunc = targetFilterFunc;
_targetFactoryFunc = targetFactoryFunc;
_logger = _connection.LoggerFactory.CreateLogger<ChromeTargetManager>();
_connection.MessageReceived += OnMessageReceived;
_connection.SessionDetached += Connection_SessionDetached;
_logger = _connection.LoggerFactory.CreateLogger<ChromeTargetManager>();

_ = _connection.SendAsync("Target.setDiscoverTargets", new TargetSetDiscoverTargetsRequest
{
Expand Down
6 changes: 3 additions & 3 deletions lib/PuppeteerSharp/FirefoxTargetManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma warning disable CS0067 // Temporal, do not merge with this
#pragma warning disable CS0067 // Temporal, do not merge with this
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
Expand Down Expand Up @@ -31,9 +31,9 @@ public FirefoxTargetManager(
_connection = connection;
_targetFilterFunc = targetFilterFunc;
_targetFactoryFunc = targetFactoryFunc;
_logger = _connection.LoggerFactory.CreateLogger<FirefoxTargetManager>();
_connection.MessageReceived += OnMessageReceived;
_connection.SessionDetached += Connection_SessionDetached;
_logger = _connection.LoggerFactory.CreateLogger<FirefoxTargetManager>();
}

public event EventHandler<TargetChangedArgs> TargetAvailable;
Expand Down Expand Up @@ -191,4 +191,4 @@ private void FinishInitializationIfReady(string targetId = null)
}
}
}
#pragma warning restore CS0067
#pragma warning restore CS0067
9 changes: 3 additions & 6 deletions lib/PuppeteerSharp/IsolatedWorld.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public IsolatedWorld(
Frame frame,
TimeoutSettings timeoutSettings)
{
Logger = client.Connection.LoggerFactory.CreateLogger<IsolatedWorld>();
_logger = client.Connection.LoggerFactory.CreateLogger<IsolatedWorld>();
_client = client;
_frameManager = frameManager;
_customQueriesManager = ((Browser)frameManager.Page.Browser).CustomQueriesManager;
Expand All @@ -48,7 +48,6 @@ public IsolatedWorld(

_detached = false;
_client.MessageReceived += Client_MessageReceived;
_logger = _client.Connection.LoggerFactory.CreateLogger<IsolatedWorld>();
}

internal TaskManager TaskManager { get; set; } = new();
Expand All @@ -57,8 +56,6 @@ public IsolatedWorld(

internal bool HasContext => _contextResolveTaskWrapper?.Task.IsCompleted == true;

internal ILogger Logger { get; }

internal ConcurrentDictionary<string, Delegate> BoundFunctions { get; } = new();

internal TaskCompletionSource<IJSHandle> PuppeteerUtilTaskCompletionSource { get; private set; } = new(TaskCreationOptions.RunContinuationsAsynchronously);
Expand Down Expand Up @@ -500,7 +497,7 @@ private async Task InjectPuppeteerUtil(ExecutionContext context)
}
catch (Exception ex)
{
Logger.LogError(ex.ToString());
_logger.LogError(ex.ToString());
}
}

Expand All @@ -518,7 +515,7 @@ private async void Client_MessageReceived(object sender, MessageEventArgs e)
catch (Exception ex)
{
var message = $"IsolatedWorld failed to process {e.MessageID}. {ex.Message}. {ex.StackTrace}";
Logger.LogError(ex, message);
_logger.LogError(ex, message);
_client.Close(message);
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/PuppeteerSharp/NetworkManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ internal NetworkManager(CDPSession client, bool ignoreHTTPSErrors, FrameManager
FrameManager = frameManager;
_client = client;
_ignoreHTTPSErrors = ignoreHTTPSErrors;
_client.MessageReceived += Client_MessageReceived;
_logger = _client.Connection.LoggerFactory.CreateLogger<NetworkManager>();
_client.MessageReceived += Client_MessageReceived;
}

internal event EventHandler<ResponseCreatedEventArgs> Response;
Expand Down