Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
chore(): add different logging levels
  • Loading branch information
Sid200026 committed Oct 17, 2024
commit 00e6f595fdf9dc8789376e21b3b0c12dbc28a4b0
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ internal class Constants
// Default constants
internal static readonly string s_default_os = ServiceOs.Linux;
internal static readonly string s_default_expose_network = "<loopback>";
internal static readonly string s_pLAYWRIGHT_SERVICE_DEBUG = "PLAYWRIGHT_SERVICE_DEBUG";
internal static readonly string s_pLAYWRIGHT_SERVICE_DEBUG = "Logging__LogLevel__MicrosoftPlaywrightTesting";

// Entra id access token constants
internal static readonly int s_entra_access_token_lifetime_left_threshold_in_minutes_for_rotation = 15;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@ internal enum LogLevel

internal class Logger : ILogger
{
internal static bool EnableDebug { get { return !string.IsNullOrEmpty(Environment.GetEnvironmentVariable(Constants.s_pLAYWRIGHT_SERVICE_DEBUG)); } set { } }
internal static string SdkLogLevel => Environment.GetEnvironmentVariable(Constants.s_pLAYWRIGHT_SERVICE_DEBUG);

#pragma warning disable CA1822 // Mark members as static
private void Log(LogLevel level, string message)
#pragma warning restore CA1822 // Mark members as static
{
if (EnableDebug)
if (Enum.TryParse(SdkLogLevel, out LogLevel configuredLevel) && level >= configuredLevel)
{
Console.WriteLine($"{DateTime.Now} [{level}]: {message}");
System.IO.TextWriter writer = level == LogLevel.Error || level == LogLevel.Warning ? Console.Error : Console.Out;
writer.WriteLine($"{DateTime.Now} [{level}]: {message}");
}
}

Expand Down