-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prints grouped log messages to console
- Loading branch information
1 parent
a4289b4
commit 01aa0cb
Showing
9 changed files
with
237 additions
and
296 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License | ||
|
||
// from https://github.com/dotnet/runtime/blob/e1c671760e23de03ee4be74eeb26831813488100/src/libraries/Microsoft.Extensions.Logging.Console/src/AnsiParser.cs | ||
|
||
namespace Microsoft.DevProxy.Logging; | ||
|
||
internal static class AnsiParser | ||
{ | ||
internal const string DefaultForegroundColor = "\x1B[39m\x1B[22m"; // reset to default foreground color | ||
internal const string DefaultBackgroundColor = "\x1B[49m"; // reset to the background color | ||
|
||
internal static string GetForegroundColorEscapeCode(ConsoleColor color) | ||
{ | ||
return color switch | ||
{ | ||
ConsoleColor.Black => "\x1B[30m", | ||
ConsoleColor.DarkRed => "\x1B[31m", | ||
ConsoleColor.DarkGreen => "\x1B[32m", | ||
ConsoleColor.DarkYellow => "\x1B[33m", | ||
ConsoleColor.DarkBlue => "\x1B[34m", | ||
ConsoleColor.DarkMagenta => "\x1B[35m", | ||
ConsoleColor.DarkCyan => "\x1B[36m", | ||
ConsoleColor.Gray => "\x1B[37m", | ||
ConsoleColor.Red => "\x1B[1m\x1B[31m", | ||
ConsoleColor.Green => "\x1B[1m\x1B[32m", | ||
ConsoleColor.Yellow => "\x1B[1m\x1B[33m", | ||
ConsoleColor.Blue => "\x1B[1m\x1B[34m", | ||
ConsoleColor.Magenta => "\x1B[1m\x1B[35m", | ||
ConsoleColor.Cyan => "\x1B[1m\x1B[36m", | ||
ConsoleColor.White => "\x1B[1m\x1B[37m", | ||
_ => DefaultForegroundColor // default foreground color | ||
}; | ||
} | ||
|
||
internal static string GetBackgroundColorEscapeCode(ConsoleColor color) | ||
{ | ||
return color switch | ||
{ | ||
ConsoleColor.Black => "\x1B[40m", | ||
ConsoleColor.DarkRed => "\x1B[41m", | ||
ConsoleColor.DarkGreen => "\x1B[42m", | ||
ConsoleColor.DarkYellow => "\x1B[43m", | ||
ConsoleColor.DarkBlue => "\x1B[44m", | ||
ConsoleColor.DarkMagenta => "\x1B[45m", | ||
ConsoleColor.DarkCyan => "\x1B[46m", | ||
ConsoleColor.Gray => "\x1B[47m", | ||
_ => DefaultBackgroundColor // Use default background color | ||
}; | ||
} | ||
} |
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,15 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License | ||
|
||
namespace Microsoft.Extensions.Logging; | ||
|
||
public static class ILoggerExtensions | ||
{ | ||
public static IDisposable? BeginScope(this ILogger logger, string method, string url, int requestId) => | ||
logger.BeginScope(new Dictionary<string, object> | ||
{ | ||
{ nameof(method), method }, | ||
{ nameof(url), url }, | ||
{ nameof(requestId), requestId } | ||
}); | ||
} |
Oops, something went wrong.