-
Notifications
You must be signed in to change notification settings - Fork 4
Implement Structured Console Logging #83
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
Merged
Merged
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
a2bd575
init
c4634e2
dont print indents without --tree-logging paramter
b4496f3
removed name from scope, added usings
500b67d
working log-levels
7517a57
refactor
826e12c
fixes
3a5a945
removed reqeusts json
0b3a446
stack to immutable
9ad0e47
public to internal
18b40d9
simplified TreeScopeStateStore
de40d74
refactor TreeConsoleSink.Emit
66f1cf3
closing bracket level matches opening bracket lvl
5d12642
opening/closing bracket refactor
c2f0ed2
refactored scopes counting
e67b7be
allocating serilgo parser once
dc8e718
log template
0997265
coderabbitai recommended changes
cda0b87
removed redundant BuildIndentPrefix
63b8092
removed TreeScopeStateStore.cs, updated TreeScope.cs
ebb8155
resolved merge conflicts
2c93d3c
refactored request logging in ExecuteRequestStep
d93ed9f
AppendLine to Append for last line of print
47b9297
enhanced log formatting
c584002
refactor logging methods for improved clarity and consistency
7fac23e
added structured logging for pipeline steps and test case collections
820c905
added colors to tree logging
2f4b346
refactor logging implementation for improved clarity and structure
6e3b2d1
moved to new folder
e7fe799
remove unused usings
93f4b6c
removed redundant allocations and tolist() calls
db26c72
Merge branch 'master' into feature/visual-logs
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,118 @@ | ||
| using Serilog.Events; | ||
|
|
||
| namespace TeaPie.Logging.Tree; | ||
|
|
||
| internal static class TreeConsoleFormatter | ||
| { | ||
| private static readonly ConsoleColor[] _treeColors = [ | ||
| ConsoleColor.Gray, | ||
| ConsoleColor.DarkGray, | ||
| ConsoleColor.Cyan, | ||
| ConsoleColor.Yellow, | ||
| ConsoleColor.DarkGray, | ||
| ConsoleColor.DarkGray | ||
| ]; | ||
|
|
||
| private static readonly Dictionary<Func<string, bool>, string> _symbolMappings = new() | ||
| { | ||
| { msg => msg.StartsWith("Test Passed:") || msg.StartsWith("Test passed during retry"), "β " }, | ||
| { msg => msg.StartsWith("Test '") && msg.Contains("failed"), "β " }, | ||
| { msg => msg.StartsWith("Skipping test:") || (msg.StartsWith("Test '") && msg.Contains("already executed")), "β " }, | ||
| { msg => msg.StartsWith("Reason:"), " " } | ||
| }; | ||
|
|
||
| internal static string PrependSymbol(string message) | ||
| { | ||
| foreach (var (predicate, symbol) in _symbolMappings) | ||
| { | ||
| if (predicate(message)) | ||
| { | ||
| return symbol + message; | ||
| } | ||
| } | ||
|
|
||
| return message; | ||
| } | ||
|
|
||
| internal static void WriteMessageWithSymbolColor(string message) | ||
| { | ||
| if (string.IsNullOrEmpty(message)) | ||
| { | ||
| Console.Out.WriteLine(); | ||
| return; | ||
| } | ||
|
|
||
| switch (message[0]) | ||
| { | ||
| case 'β': | ||
| WriteColorText("β", ConsoleColor.Green); | ||
| Console.Out.WriteLine(message[1..]); | ||
| break; | ||
| case 'β': | ||
| WriteColorText("β", ConsoleColor.Red); | ||
| Console.Out.WriteLine(message[1..]); | ||
| break; | ||
| case 'β': | ||
| WriteColorText("β", ConsoleColor.Blue); | ||
| Console.Out.WriteLine(message[1..]); | ||
| break; | ||
| default: | ||
| Console.Out.WriteLine(message); | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| internal static void WriteColorizedHeader(string header, string? levelShort) | ||
| { | ||
| if (string.IsNullOrWhiteSpace(header)) | ||
| { | ||
| Console.Out.Write(header); | ||
| return; | ||
| } | ||
|
|
||
| if (header.Length >= TreeConsoleWriter.ExpectedMinHeaderLength && header[TreeConsoleWriter.BracketStartIndex] == '[') | ||
| { | ||
| WriteColorText("[", ConsoleColor.DarkGray); | ||
| WriteColorText(header.Substring(TreeConsoleWriter.TimestampStartIndex, TreeConsoleWriter.ExpectedTimestampLength), ConsoleColor.Gray); | ||
| Console.Out.Write(" "); | ||
| WriteColorText(header.Substring(TreeConsoleWriter.LevelStartIndex, TreeConsoleWriter.ExpectedLevelLength), GetLevelColor(levelShort ?? "UNK")); | ||
| WriteColorText(header.Substring(TreeConsoleWriter.BracketEndIndex), ConsoleColor.DarkGray); | ||
| } | ||
| else | ||
| { | ||
| Console.Out.Write(header); | ||
| } | ||
| } | ||
|
|
||
| internal static void WriteColorText(string text, ConsoleColor color) | ||
| { | ||
| Console.ForegroundColor = color; | ||
| Console.Out.Write(text); | ||
| Console.ResetColor(); | ||
| } | ||
|
|
||
| internal static ConsoleColor GetTreeColor(int index) | ||
| => _treeColors[Math.Max(0, index) % _treeColors.Length]; | ||
|
|
||
| private static ConsoleColor GetLevelColor(string levelShort) => levelShort switch | ||
| { | ||
| "FTL" => ConsoleColor.Magenta, | ||
| "ERR" => ConsoleColor.Red, | ||
| "WRN" => ConsoleColor.Yellow, | ||
| "INF" => ConsoleColor.Green, | ||
| "DBG" => ConsoleColor.Cyan, | ||
| "VRB" => ConsoleColor.DarkGray, | ||
| _ => ConsoleColor.White | ||
| }; | ||
|
|
||
| internal static string LevelToShort(LogEventLevel level) => level switch | ||
| { | ||
| LogEventLevel.Verbose => "VRB", | ||
| LogEventLevel.Debug => "DBG", | ||
| LogEventLevel.Information => "INF", | ||
| LogEventLevel.Warning => "WRN", | ||
| LogEventLevel.Error => "ERR", | ||
| LogEventLevel.Fatal => "FTL", | ||
| _ => "UNK", | ||
| }; | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.