mirror of
https://github.com/PepperDash/PepperDashCore.git
synced 2026-01-11 19:44:44 +00:00
fix: reworks how the console debug level is set
This commit is contained in:
@@ -197,7 +197,7 @@ namespace PepperDash.Core.JsonToSimpl
|
||||
/// Sets the debug level
|
||||
/// </summary>
|
||||
/// <param name="level"></param>
|
||||
public void setDebugLevel(int level)
|
||||
public void setDebugLevel(uint level)
|
||||
{
|
||||
Debug.SetDebugLevel(level);
|
||||
}
|
||||
|
||||
@@ -134,7 +134,7 @@ namespace PepperDash.Core.JsonToSimpl
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="level"></param>
|
||||
public void setDebugLevel(int level)
|
||||
public void setDebugLevel(uint level)
|
||||
{
|
||||
Debug.SetDebugLevel(level);
|
||||
}
|
||||
|
||||
@@ -12,6 +12,8 @@ using Serilog;
|
||||
using Serilog.Core;
|
||||
using Serilog.Events;
|
||||
using Serilog.Formatting.Json;
|
||||
using Crestron.SimplSharp.CrestronDataStore;
|
||||
using System.Linq;
|
||||
|
||||
namespace PepperDash.Core
|
||||
{
|
||||
@@ -30,15 +32,15 @@ namespace PepperDash.Core
|
||||
/// </summary>
|
||||
public static class Debug
|
||||
{
|
||||
//private static Dictionary<int, Action<string>> _logActions = new Dictionary<int, Action<string>>()
|
||||
//{
|
||||
// {0, (s) => _logger.Information(s) },
|
||||
// {1, (s) => _logger.Warning(s) },
|
||||
// {2, (s) => _logger.Error(s) },
|
||||
// {3, (s) => _logger.Fatal(s) },
|
||||
// {4, (s) => _logger.Debug(s) },
|
||||
// {5, (s) => _logger.Verbose(s) },
|
||||
//};
|
||||
private static Dictionary<uint, LogEventLevel> _logLevels = new Dictionary<uint, LogEventLevel>()
|
||||
{
|
||||
{0, LogEventLevel.Information },
|
||||
{1, LogEventLevel.Warning },
|
||||
{2, LogEventLevel.Error },
|
||||
{3, LogEventLevel.Fatal },
|
||||
{4, LogEventLevel.Debug },
|
||||
{5, LogEventLevel.Verbose },
|
||||
};
|
||||
|
||||
private static Logger _logger;
|
||||
|
||||
@@ -157,7 +159,7 @@ namespace PepperDash.Core
|
||||
"donotloadonnextboot:P [true/false]: Should the application load on next boot", ConsoleAccessLevelEnum.AccessOperator);
|
||||
|
||||
CrestronConsole.AddNewConsoleCommand(SetDebugFromConsole, "appdebug",
|
||||
"appdebug:P [0-2]: Sets the application's console debug message level",
|
||||
"appdebug:P [0-5]: Sets the application's console debug message level",
|
||||
ConsoleAccessLevelEnum.AccessOperator);
|
||||
CrestronConsole.AddNewConsoleCommand(ShowDebugLog, "appdebuglog",
|
||||
"appdebuglog:P [all] Use \"all\" for full log.",
|
||||
@@ -252,14 +254,15 @@ namespace PepperDash.Core
|
||||
{
|
||||
if (levelString.Trim() == "?")
|
||||
{
|
||||
CrestronConsole.ConsoleCommandResponse(
|
||||
CrestronConsole.ConsoleCommandResponse(
|
||||
$@"Used to set the minimum level of debug messages to be printed to the console:
|
||||
{eDebugLevel.Information.ToString()} = {eDebugLevel.Information}
|
||||
{eDebugLevel.Warning.ToString()} = {eDebugLevel.Warning}
|
||||
{eDebugLevel.Error.ToString()} = {eDebugLevel.Error}
|
||||
{eDebugLevel.Fatal.ToString()} = {eDebugLevel.Fatal}
|
||||
{eDebugLevel.Debug.ToString()} = {eDebugLevel.Debug}
|
||||
{eDebugLevel.Verbose.ToString()} = {eDebugLevel.Verbose}");
|
||||
{eDebugLevel.Information} = 0
|
||||
{eDebugLevel.Warning} = 1
|
||||
{eDebugLevel.Error} = 2
|
||||
{eDebugLevel.Fatal} = 3
|
||||
{eDebugLevel.Debug} = 4
|
||||
{eDebugLevel.Verbose} = 5");
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(levelString.Trim()))
|
||||
@@ -268,7 +271,10 @@ $@"Used to set the minimum level of debug messages to be printed to the console:
|
||||
return;
|
||||
}
|
||||
|
||||
SetDebugLevel(Convert.ToInt32(levelString));
|
||||
var level = Convert.ToUInt32(levelString);
|
||||
|
||||
if (_logLevels.ContainsKey(level))
|
||||
SetDebugLevel(level);
|
||||
}
|
||||
catch
|
||||
{
|
||||
@@ -276,15 +282,33 @@ $@"Used to set the minimum level of debug messages to be printed to the console:
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetConsoleDebugLevel(LogEventLevel level)
|
||||
/// <summary>
|
||||
/// Sets the debug level
|
||||
/// </summary>
|
||||
/// <param name="level"> Valid values 0-5</param>
|
||||
public static void SetDebugLevel(uint level)
|
||||
{
|
||||
_consoleLoggingLevelSwitch.MinimumLevel = level;
|
||||
if (_logLevels.ContainsKey(level))
|
||||
_consoleLoggingLevelSwitch.MinimumLevel = _logLevels[level];
|
||||
|
||||
CrestronConsole.ConsoleCommandResponse("[Application {0}], Debug level set to {1}",
|
||||
InitialParametersClass.ApplicationNumber, _consoleLoggingLevelSwitch.MinimumLevel);
|
||||
|
||||
var err = CrestronDataStoreStatic.SetLocalUintValue("ConsoleDebugLevel", level);
|
||||
if (err != CrestronDataStore.CDS_ERROR.CDS_SUCCESS)
|
||||
CrestronConsole.PrintLine("Error saving console debug level setting: {0}", err);
|
||||
}
|
||||
|
||||
public static void SetWebSocketMinimumDebugLevel(LogEventLevel level)
|
||||
{
|
||||
_websocketLoggingLevelSwitch.MinimumLevel = level;
|
||||
|
||||
var levelInt = _logLevels.FirstOrDefault((l) => l.Value.Equals(level)).Key;
|
||||
|
||||
var err = CrestronDataStoreStatic.SetLocalUintValue("WebsocketDebugLevel", levelInt);
|
||||
if (err != CrestronDataStore.CDS_ERROR.CDS_SUCCESS)
|
||||
Console(0, "Error saving websocket debug level setting: {0}", err);
|
||||
|
||||
Console(0, "Websocket debug level set to {0}", _websocketLoggingLevelSwitch.MinimumLevel);
|
||||
}
|
||||
|
||||
@@ -390,25 +414,7 @@ $@"Used to set the minimum level of debug messages to be printed to the console:
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Sets the debug level
|
||||
/// </summary>
|
||||
/// <param name="level"> Valid values 0 (no debug), 1 (critical), 2 (all messages)</param>
|
||||
public static void SetDebugLevel(int level)
|
||||
{
|
||||
_consoleLoggingLevelSwitch.MinimumLevel = (LogEventLevel)level;
|
||||
|
||||
//if (level <= 5)
|
||||
//{
|
||||
|
||||
// CrestronConsole.ConsoleCommandResponse("[Application {0}], Debug level set to {1}",
|
||||
// InitialParametersClass.ApplicationNumber, _consoleLoggingLevelSwitch.MinimumLevel);
|
||||
|
||||
// //var err = CrestronDataStoreStatic.SetLocalUintValue("DebugLevel", level);
|
||||
// //if (err != CrestronDataStore.CDS_ERROR.CDS_SUCCESS)
|
||||
// // CrestronConsole.PrintLine("Error saving console debug level setting: {0}", err);
|
||||
//}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// sets the settings for a device or creates a new entry
|
||||
|
||||
Reference in New Issue
Block a user