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

[dotnet] Internal logging #13140

Merged
merged 66 commits into from
Dec 3, 2023
Merged
Show file tree
Hide file tree
Changes from 57 commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
0688c8b
INitial implementation
nvborisenko Oct 20, 2023
091ee36
With context
nvborisenko Oct 23, 2023
eea4ab6
Update HttpCommandExecutor.cs
nvborisenko Oct 23, 2023
f8c27f8
Nullable handlers
nvborisenko Oct 24, 2023
3cee19d
Don't capture logger
nvborisenko Oct 24, 2023
c722c4e
Log message issuer
nvborisenko Oct 24, 2023
16c3cae
Simplify things
nvborisenko Oct 24, 2023
d7ceb67
Merge remote-tracking branch 'upstream/trunk' into dotnet-logging
nvborisenko Nov 10, 2023
2a85e27
Continue
nvborisenko Nov 10, 2023
4fca9a3
Merge remote-tracking branch 'upstream/trunk' into dotnet-logging
nvborisenko Nov 13, 2023
4c7ba77
Update nunit adapter to work with dotnet 7 and be more friendly with …
nvborisenko Nov 13, 2023
0dc4b35
Merge remote-tracking branch 'upstream/trunk' into dotnet-logging
nvborisenko Nov 13, 2023
1042d4e
Rename to LogEventLevel
nvborisenko Nov 22, 2023
eae7f4c
Typo
nvborisenko Nov 22, 2023
0b7c610
Introduce LogContextManager
nvborisenko Nov 22, 2023
1390b1e
Typo again
nvborisenko Nov 22, 2023
e87773e
Rename to Timestamp
nvborisenko Nov 23, 2023
b874730
Make ILogger as static field
nvborisenko Nov 23, 2023
fcf811c
Support hierarchical contexts
nvborisenko Nov 28, 2023
3a9dbaf
Rename to EmitMessage
nvborisenko Nov 28, 2023
ca73016
Do not emit message to parent context
nvborisenko Nov 28, 2023
bf004d6
Deep copy of loggers and handlers per context
nvborisenko Nov 28, 2023
88cb872
Make fields private
nvborisenko Nov 28, 2023
9795e8f
Static works with current log context
nvborisenko Nov 28, 2023
6f3e484
Create context with minimum level
nvborisenko Nov 28, 2023
478ae5a
Set minimum level for context
nvborisenko Nov 28, 2023
5f54cfa
Rename to WithHandler
nvborisenko Nov 28, 2023
571479a
Set minimum level per issuer
nvborisenko Nov 28, 2023
edb14d3
Simplify getting internal logger
nvborisenko Nov 28, 2023
4573398
Use DateTimeOffset
nvborisenko Nov 28, 2023
044fc86
Docs for log event level
nvborisenko Nov 28, 2023
13b00f6
Docs for ILogger
nvborisenko Nov 28, 2023
34b9b40
Docs for Logger
nvborisenko Nov 28, 2023
cec3811
Docs for others
nvborisenko Nov 28, 2023
3cf6e48
Make ILogger interface as internal
nvborisenko Nov 28, 2023
c7dd8ed
Revert "Make ILogger interface as internal"
nvborisenko Nov 28, 2023
7a02443
First test
nvborisenko Nov 28, 2023
339e4f9
Merge remote-tracking branch 'upstream/trunk' into dotnet-logging-test
nvborisenko Nov 28, 2023
9cb6a14
Update LogTest.cs
nvborisenko Nov 28, 2023
c4af631
Fix build error
nvborisenko Nov 28, 2023
684d565
Info minimum log level by default
nvborisenko Nov 28, 2023
cba7a68
Remove unnecessary log call in ChromeDriver
nvborisenko Nov 28, 2023
84da458
Adjust log levels in console output
nvborisenko Nov 29, 2023
48bd407
Make it length fixed
nvborisenko Nov 29, 2023
cd46467
Make webdriver assembly internals visible to tests
nvborisenko Nov 29, 2023
1d1cfc5
Make ILogger hidden from user
nvborisenko Nov 29, 2023
d7d22b2
More tests for log context
nvborisenko Nov 29, 2023
a6271e7
Rename back to AddHandler
nvborisenko Nov 29, 2023
fbc36ab
Make format script happy?
nvborisenko Nov 29, 2023
0514324
Make format script happy?
nvborisenko Nov 29, 2023
3314553
Rename back to SetLevel
nvborisenko Nov 29, 2023
479c357
Console handler by default
nvborisenko Nov 29, 2023
20a66ae
Output logs to stderr
nvborisenko Nov 29, 2023
5fb6acf
New api to mange log handlers
nvborisenko Nov 29, 2023
4681724
Merge branch 'trunk' into dotnet-logging
nvborisenko Nov 29, 2023
e3255a6
Use logging in DriverFactory
nvborisenko Nov 30, 2023
0167dfa
Revert "Use logging in DriverFactory"
nvborisenko Nov 30, 2023
7ac3376
Verbose driver creation in tests
nvborisenko Dec 1, 2023
225474c
Search driver type in loaded assemblies
nvborisenko Dec 1, 2023
9b61d8a
Decalare internals visible to in csproj to not conflict with bazel
nvborisenko Dec 1, 2023
3e35ca7
Clean specific assembly name for driver type
nvborisenko Dec 1, 2023
b7bd127
Merge branch 'trunk' into dotnet-logging
nvborisenko Dec 1, 2023
9663bc3
Merge branch 'trunk' into dotnet-logging
nvborisenko Dec 1, 2023
5ff197f
Merge remote-tracking branch 'upstream/trunk' into dotnet-logging
nvborisenko Dec 1, 2023
0885002
Old school using to make bazel happy
nvborisenko Dec 1, 2023
1138648
Fix targeting packs for test targets
nvborisenko Dec 1, 2023
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
5 changes: 5 additions & 0 deletions dotnet/src/webdriver/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ csharp_library(
"**/*.cs",
]) + devtools_version_targets(),
out = "WebDriver",
internals_visible_to = [
"WebDriver.Common.Tests",
],
langversion = "10.0",
resources = [
"//javascript/atoms/fragments:find-elements.js",
"//javascript/atoms/fragments:is-displayed.js",
Expand Down Expand Up @@ -64,6 +68,7 @@ csharp_library(
]) + devtools_version_targets(),
out = "WebDriver.StrongNamed",
keyfile = "//dotnet:WebDriver.snk",
langversion = "10.0",
resources = [
"//javascript/atoms/fragments:find-elements.js",
"//javascript/atoms/fragments:is-displayed.js",
Expand Down
1 change: 1 addition & 0 deletions dotnet/src/webdriver/Chrome/ChromeDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using System.Collections.ObjectModel;
using OpenQA.Selenium.Remote;
using OpenQA.Selenium.Chromium;
using OpenQA.Selenium.Internal.Logging;

namespace OpenQA.Selenium.Chrome
{
Expand Down
49 changes: 49 additions & 0 deletions dotnet/src/webdriver/Internal/Logging/ConsoleLogHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// <copyright file="ConsoleLogHandler.cs" company="WebDriver Committers">
// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The SFC licenses this file
// to you under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>

using System;

namespace OpenQA.Selenium.Internal.Logging
{
/// <summary>
/// Represents a log handler that writes log events to the console.
/// </summary>
public class ConsoleLogHandler : ILogHandler
{
// performance trick to avoid expensive Enum.ToString() with fixed length
private static readonly string[] _levels = { "TRACE", "DEBUG", " INFO", " WARN", "ERROR" };

/// <summary>
/// Handles a log event by writing it to the console.
/// </summary>
/// <param name="logEvent">The log event to handle.</param>
public void Handle(LogEvent logEvent)
{
Console.Error.WriteLine($"{logEvent.Timestamp:HH:mm:ss.fff} {_levels[(int)logEvent.Level]} {logEvent.IssuedBy.Name}: {logEvent.Message}");
}

/// <summary>
/// Creates a new instance of the <see cref="ConsoleLogHandler"/> class.
/// </summary>
/// <returns>A new instance of the <see cref="ConsoleLogHandler"/> class.</returns>
public ILogHandler Clone()
{
return this;
}
}
}
83 changes: 83 additions & 0 deletions dotnet/src/webdriver/Internal/Logging/ILogContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// <copyright file="ILogContext.cs" company="WebDriver Committers">
// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The SFC licenses this file
// to you under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>

using System;

namespace OpenQA.Selenium.Internal.Logging
{
/// <summary>
/// Represents a logging context that provides methods for creating sub-contexts, retrieving loggers, emitting log messages, and configuring minimum log levels.
/// </summary>
public interface ILogContext : IDisposable
{
/// <summary>
/// Creates a new logging context.
/// </summary>
/// <returns>A new instance of <see cref="ILogContext"/>.</returns>
ILogContext CreateContext();

/// <summary>
/// Creates a new logging context with the specified minimum log level.
/// </summary>
/// <param name="minimumLevel">The minimum log level for the new context.</param>
/// <returns>A new instance of <see cref="ILogContext"/> with the specified minimum log level.</returns>
ILogContext CreateContext(LogEventLevel minimumLevel);

/// <summary>
/// Gets a logger for the specified type.
/// </summary>
/// <typeparam name="T">The type for which to retrieve the logger.</typeparam>
/// <returns>An instance of <see cref="ILogger"/> for the specified type.</returns>
internal ILogger GetLogger<T>();

/// <summary>
/// Gets a logger for the specified type.
/// </summary>
/// <param name="type">The type for which to retrieve the logger.</param>
/// <returns>An instance of <see cref="ILogger"/> for the specified type.</returns>
internal ILogger GetLogger(Type type);

/// <summary>
/// Emits a log message using the specified logger, log level, and message.
/// </summary>
/// <param name="logger">The logger to emit the log message.</param>
/// <param name="level">The log level of the message.</param>
/// <param name="message">The log message.</param>
internal void EmitMessage(ILogger logger, LogEventLevel level, string message);

/// <summary>
/// Sets the minimum log level for the current context.
/// </summary>
/// <param name="level">The minimum log level.</param>
/// <returns>The current instance of <see cref="ILogContext"/> with the minimum log level set.</returns>
ILogContext SetLevel(LogEventLevel level);
nvborisenko marked this conversation as resolved.
Show resolved Hide resolved

/// <summary>
/// Sets the minimum log level for the specified type in the current context.
/// </summary>
/// <param name="issuer">The type for which to set the minimum log level.</param>
/// <param name="level">The minimum log level.</param>
/// <returns>The current instance of <see cref="ILogContext"/> with the minimum log level set for the specified type.</returns>
ILogContext SetLevel(Type issuer, LogEventLevel level);

/// <summary>
/// Gets a list of log handlers.
/// </summary>
ILogHandlerList Handlers { get; }
}
}
38 changes: 38 additions & 0 deletions dotnet/src/webdriver/Internal/Logging/ILogHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// <copyright file="ILogHandler.cs" company="WebDriver Committers">
// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The SFC licenses this file
// to you under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>

namespace OpenQA.Selenium.Internal.Logging
{
/// <summary>
/// Represents a log handler that handles log events.
/// </summary>
public interface ILogHandler
{
/// <summary>
/// Handles a log event.
/// </summary>
/// <param name="logEvent">The log event to handle.</param>
void Handle(LogEvent logEvent);

/// <summary>
/// Creates a clone of the log handler.
/// </summary>
/// <returns>A clone of the log handler.</returns>
ILogHandler Clone();
}
}
48 changes: 48 additions & 0 deletions dotnet/src/webdriver/Internal/Logging/ILogHandlerList.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// <copyright file="ILogHandlerList.cs" company="WebDriver Committers">
// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The SFC licenses this file
// to you under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>

using System.Collections.Generic;

namespace OpenQA.Selenium.Internal.Logging
{
/// <summary>
/// Represents a list of log handlers.
/// </summary>
public interface ILogHandlerList : IEnumerable<ILogHandler>
{
/// <summary>
/// Adds a log handler to the list.
/// </summary>
/// <param name="handler">The log handler to add.</param>
/// <returns>The log context.</returns>
ILogContext Add(ILogHandler handler);

/// <summary>
/// Removes a log handler from the list.
/// </summary>
/// <param name="handler">The log handler to remove.</param>
/// <returns>The log context.</returns>
ILogContext Remove(ILogHandler handler);

/// <summary>
/// Clears all log handlers from the list.
/// </summary>
/// <returns>The log context.</returns>
ILogContext Clear();
}
}
68 changes: 68 additions & 0 deletions dotnet/src/webdriver/Internal/Logging/ILogger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// <copyright file="ILogger.cs" company="WebDriver Committers">
// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The SFC licenses this file
// to you under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>

using System;

namespace OpenQA.Selenium.Internal.Logging
{
/// <summary>
/// Defines the interface through which log messages are emitted.
/// </summary>
internal interface ILogger
{
/// <summary>
/// Writes a trace-level log message.
/// </summary>
/// <param name="message">The log message.</param>
void Trace(string message);

/// <summary>
/// Writes a debug-level log message.
/// </summary>
/// <param name="message">The log message.</param>
void Debug(string message);

/// <summary>
/// Writes an info-level log message.
/// </summary>
/// <param name="message">The log message.</param>
void Info(string message);

/// <summary>
/// Writes a warning-level log message.
/// </summary>
/// <param name="message">The log message.</param>
void Warn(string message);

/// <summary>
/// Writes an error-level log message.
/// </summary>
/// <param name="message">The log message.</param>
void Error(string message);

/// <summary>
/// Gets or sets the log event level.
/// </summary>
LogEventLevel Level { get; set; }
nvborisenko marked this conversation as resolved.
Show resolved Hide resolved

/// <summary>
/// Gets the type of the logger issuer.
/// </summary>
Type Issuer { get; }
}
}
Loading
Loading