Skip to content

Commit

Permalink
add log group to output
Browse files Browse the repository at this point in the history
  • Loading branch information
ctacke committed Jul 4, 2024
1 parent f337e69 commit adfbd00
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions Source/Meadow.Logging/lib/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ public static class MessageGroup
/// Represents the application-specific log messages.
/// </summary>
public const string Application = "application";

/// <summary>
/// Represents the log messages related to the ESP coprocessor.
/// </summary>
public const string Esp = "esp";
}

private readonly LogProviderCollection _providers = new();
Expand All @@ -44,7 +49,12 @@ public static class MessageGroup
/// <remarks>
/// To show message from all groups, either use `MessageGroup.All` <i>or</i> clear the ShowsGroups list
/// </remarks>
public List<string> ShowGroups { get; } = new();
public List<string> GroupsToShow { get; } = new();

/// <summary>
/// Gets or sets a value indicating whether to show message groups in log messages
/// </summary>
public bool ShowGroup { get; set; } = true;

/// <summary>
/// Gets or sets a value indicating whether to show ticks in log messages
Expand All @@ -62,7 +72,7 @@ public static class MessageGroup
/// <param name="providers">A collection of providers to add to the Logger</param>
public Logger(params ILogProvider[] providers)
{
ShowGroups.Add(MessageGroup.Application);
GroupsToShow.Add(MessageGroup.Application);

foreach (var p in providers)
{
Expand Down Expand Up @@ -220,10 +230,10 @@ private void Log(LogLevel level, string message, string? messageGroup)

if (messageGroup == null) messageGroup = MessageGroup.Application;

if (ShowGroups.Count > 0)
if (GroupsToShow.Count > 0)
{
if (!ShowGroups.Contains(MessageGroup.All)
&& !ShowGroups.Contains(messageGroup))
if (!GroupsToShow.Contains(MessageGroup.All)
&& !GroupsToShow.Contains(messageGroup))
{
return;
}
Expand All @@ -238,6 +248,11 @@ private void Log(LogLevel level, string message, string? messageGroup)
now = TimeSpan.FromMilliseconds(Environment.TickCount - _startupTicks);
}

if (ShowGroup && messageGroup != null)
{
message = $"[{messageGroup}] {message}";
}

foreach (var p in _providers)
{
if (now != null)
Expand Down

0 comments on commit adfbd00

Please sign in to comment.