mirror of
https://github.com/PepperDash/PepperDashCore.git
synced 2026-01-11 19:44:44 +00:00
feat: added --devices all flag for console debug context
This commit is contained in:
@@ -124,7 +124,7 @@ namespace PepperDash.Core
|
|||||||
if (supportsRemovableDrive)
|
if (supportsRemovableDrive)
|
||||||
DefaultLoggerConfiguration.WriteTo.Sink(new DebugCrestronLoggerSink());
|
DefaultLoggerConfiguration.WriteTo.Sink(new DebugCrestronLoggerSink());
|
||||||
|
|
||||||
var storedConsoleLevel = DebugContext.GetDataForKey(ConsoleLevelStoreKey, LogEventLevel.Information);
|
var storedConsoleLevel = DebugContext.GetOrCreateDataForKey(ConsoleLevelStoreKey, LogEventLevel.Information);
|
||||||
ConsoleLoggingLevelSwitch.MinimumLevel = storedConsoleLevel.Level;
|
ConsoleLoggingLevelSwitch.MinimumLevel = storedConsoleLevel.Level;
|
||||||
CrestronConsole.PrintLine("Beginning console logging with level:{0}", storedConsoleLevel.Level);
|
CrestronConsole.PrintLine("Beginning console logging with level:{0}", storedConsoleLevel.Level);
|
||||||
|
|
||||||
@@ -202,9 +202,17 @@ namespace PepperDash.Core
|
|||||||
.ToArray()
|
.ToArray()
|
||||||
: [];
|
: [];
|
||||||
|
|
||||||
|
|
||||||
if (LogLevels.TryGetValue(level, out var logEventLevel))
|
if (LogLevels.TryGetValue(level, out var logEventLevel))
|
||||||
{
|
{
|
||||||
SetConsoleDebugLevel(logEventLevel, devices);
|
if (devices.Length == 1 && devices[0].ToLower() == "all")
|
||||||
|
{
|
||||||
|
SetConsoleDebugLevel(logEventLevel, true, []);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SetConsoleDebugLevel(logEventLevel, false, devices);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -222,10 +230,10 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SetConsoleDebugLevel(LogEventLevel level, string[] includedDevices = null)
|
public static void SetConsoleDebugLevel(LogEventLevel level, bool logAllDevices = false, string[] includedDevices = null)
|
||||||
{
|
{
|
||||||
ConsoleLoggingLevelSwitch.MinimumLevel = level;
|
ConsoleLoggingLevelSwitch.MinimumLevel = level;
|
||||||
DebugContext.SetDataForKey(ConsoleLevelStoreKey, level, includedDevices);
|
DebugContext.SetDataForKey(ConsoleLevelStoreKey, level, logAllDevices, includedDevices);
|
||||||
|
|
||||||
var includedDevicesMessage = includedDevices == null || includedDevices.Length == 0 ? "all" : string.Join(",", includedDevices);
|
var includedDevicesMessage = includedDevices == null || includedDevices.Length == 0 ? "all" : string.Join(",", includedDevices);
|
||||||
CrestronConsole.ConsoleCommandResponse($"Success: set console debug level to {level} with devices:{includedDevicesMessage}");
|
CrestronConsole.ConsoleCommandResponse($"Success: set console debug level to {level} with devices:{includedDevicesMessage}");
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System.IO;
|
using System;
|
||||||
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using Crestron.SimplSharp;
|
using Crestron.SimplSharp;
|
||||||
@@ -57,21 +58,21 @@ namespace PepperDash.Core.Logging
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (@event.Properties.TryGetValue("Key", out var value) && value is ScalarValue { Value: string rawValue }
|
if (@event.Level >= LogEventLevel.Error)
|
||||||
&& DebugContext.TryGetDataForKey(Debug.ConsoleLevelStoreKey, out var data)
|
|
||||||
&& data.Devices != null)
|
|
||||||
{
|
{
|
||||||
if (data.Devices.Length == 0)
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (@event.Properties.TryGetValue("Key", out var value) && value is ScalarValue { Value: string rawValue }
|
||||||
|
&& DebugContext.TryGetDataForKey(Debug.ConsoleLevelStoreKey, out var ctx))
|
||||||
|
{
|
||||||
|
if (ctx.LogAllDevices)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.Devices.Any(d => d == rawValue))
|
return ctx.Devices is not null
|
||||||
{
|
&& ctx.Devices.Any(deviceKey => string.Equals(deviceKey, rawValue, StringComparison.OrdinalIgnoreCase));
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -49,21 +49,20 @@ namespace PepperDash.Core.Logging
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static bool TryGetDataForKey(string key, out DebugContextData data) =>
|
public static bool TryGetDataForKey(string key, out DebugContextData data) =>
|
||||||
CurrentData.TryGetValue(key, out var data);
|
CurrentData.TryGetValue(key, out data);
|
||||||
|
|
||||||
public static DebugContextData GetOrCreateDataForKey(string key, LogEventLevel defaultLevel) =>
|
public static DebugContextData GetOrCreateDataForKey(string key, LogEventLevel defaultLevel) =>
|
||||||
CurrentData.TryGetValue(key, out var data) ? data : new DebugContextData(defaultLevel);
|
CurrentData.TryGetValue(key, out var data) ? data : new DebugContextData(defaultLevel, false, []);
|
||||||
|
|
||||||
|
public static void SetDataForKey(string key, LogEventLevel defaultLevel, bool logAllDevices = false, string[] devices = null)
|
||||||
public static void SetDataForKey(string key, LogEventLevel defaultLevel, string[] devices = null)
|
|
||||||
{
|
{
|
||||||
if (CurrentData.ContainsKey(key))
|
if (CurrentData.ContainsKey(key))
|
||||||
{
|
{
|
||||||
CurrentData[key] = new DebugContextData(defaultLevel, devices);
|
CurrentData[key] = new DebugContextData(defaultLevel, logAllDevices, devices);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
CurrentData.Add(key, new DebugContextData(defaultLevel, devices));
|
CurrentData.Add(key, new DebugContextData(defaultLevel, logAllDevices, devices));
|
||||||
}
|
}
|
||||||
|
|
||||||
SaveTimer.Reset(5000);
|
SaveTimer.Reset(5000);
|
||||||
@@ -103,5 +102,5 @@ namespace PepperDash.Core.Logging
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
///
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public record DebugContextData(LogEventLevel Level, string[] Devices = null);
|
public record DebugContextData(LogEventLevel Level, bool LogAllDevices = false, string[] Devices = null);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user