mirror of
https://github.com/PepperDash/PepperDashCore.git
synced 2026-02-16 05:04:48 +00:00
feat: add public LogMessage methods
Also add logic to allow using string like `Information` with `appdebug` console command.
This commit is contained in:
@@ -280,11 +280,25 @@ namespace PepperDash.Core
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var level = Convert.ToUInt32(levelString);
|
if(int.TryParse(levelString, out var levelInt))
|
||||||
|
{
|
||||||
|
if(levelInt < 0 || levelInt > 5)
|
||||||
|
{
|
||||||
|
CrestronConsole.ConsoleCommandResponse($"Error: Unable to parse {levelString} to valid log level. If using a number, value must be between 0-5");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
SetDebugLevel((LogEventLevel)levelInt);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (_logLevels.ContainsKey(level))
|
if(Enum.TryParse<LogEventLevel>(levelString, out var levelEnum))
|
||||||
SetDebugLevel(level);
|
{
|
||||||
}
|
SetDebugLevel(levelEnum);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
CrestronConsole.ConsoleCommandResponse($"Error: Unable to parse {levelString} to valid log level");
|
||||||
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
CrestronConsole.ConsoleCommandResponse("Usage: appdebug:P [0-5]");
|
CrestronConsole.ConsoleCommandResponse("Usage: appdebug:P [0-5]");
|
||||||
@@ -297,15 +311,28 @@ namespace PepperDash.Core
|
|||||||
/// <param name="level"> Valid values 0-5</param>
|
/// <param name="level"> Valid values 0-5</param>
|
||||||
public static void SetDebugLevel(uint level)
|
public static void SetDebugLevel(uint level)
|
||||||
{
|
{
|
||||||
if (_logLevels.ContainsKey(level))
|
if(!_logLevels.TryGetValue(level, out var logLevel))
|
||||||
_consoleLoggingLevelSwitch.MinimumLevel = _logLevels[level];
|
{
|
||||||
|
logLevel = LogEventLevel.Information;
|
||||||
|
|
||||||
|
CrestronConsole.PrintLine($"{level} not valid. Setting level to {logLevel}");
|
||||||
|
|
||||||
|
SetDebugLevel(logLevel);
|
||||||
|
}
|
||||||
|
|
||||||
|
SetDebugLevel(logLevel);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void SetDebugLevel(LogEventLevel level)
|
||||||
|
{
|
||||||
|
_consoleLoggingLevelSwitch.MinimumLevel = level;
|
||||||
|
|
||||||
CrestronConsole.ConsoleCommandResponse("[Application {0}], Debug level set to {1}",
|
CrestronConsole.ConsoleCommandResponse("[Application {0}], Debug level set to {1}",
|
||||||
InitialParametersClass.ApplicationNumber, _consoleLoggingLevelSwitch.MinimumLevel);
|
InitialParametersClass.ApplicationNumber, _consoleLoggingLevelSwitch.MinimumLevel);
|
||||||
|
|
||||||
var err = CrestronDataStoreStatic.SetLocalUintValue("ConsoleDebugLevel", level);
|
var err = CrestronDataStoreStatic.SetLocalUintValue("ConsoleDebugLevel", (uint) level);
|
||||||
if (err != CrestronDataStore.CDS_ERROR.CDS_SUCCESS)
|
if (err != CrestronDataStore.CDS_ERROR.CDS_SUCCESS)
|
||||||
CrestronConsole.PrintLine("Error saving console debug level setting: {0}", err);
|
CrestronConsole.PrintLine($"Error saving console debug level setting: {err}");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SetWebSocketMinimumDebugLevel(LogEventLevel level)
|
public static void SetWebSocketMinimumDebugLevel(LogEventLevel level)
|
||||||
@@ -470,6 +497,18 @@ namespace PepperDash.Core
|
|||||||
CrestronConsole.ConsoleCommandResponse(l + CrestronEnvironment.NewLine);
|
CrestronConsole.ConsoleCommandResponse(l + CrestronEnvironment.NewLine);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void LogMessage(LogEventLevel level, string message, params object[] args)
|
||||||
|
{
|
||||||
|
_logger.Write(level, message, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void LogMessage(LogEventLevel level, IKeyed keyed, string message, params object[] args)
|
||||||
|
{
|
||||||
|
var log = _logger.ForContext("Key", keyed.Key);
|
||||||
|
|
||||||
|
log.Write(level, message, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private static void LogMessage(uint level, string format, params object[] items)
|
private static void LogMessage(uint level, string format, params object[] items)
|
||||||
{
|
{
|
||||||
@@ -477,7 +516,7 @@ namespace PepperDash.Core
|
|||||||
|
|
||||||
var logLevel = _logLevels[level];
|
var logLevel = _logLevels[level];
|
||||||
|
|
||||||
_logger.Write(logLevel, format, items);
|
LogMessage(logLevel, format, items );
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void LogMessage(uint level, IKeyed keyed, string format, params object[] items)
|
private static void LogMessage(uint level, IKeyed keyed, string format, params object[] items)
|
||||||
@@ -485,9 +524,8 @@ namespace PepperDash.Core
|
|||||||
if (!_logLevels.ContainsKey(level)) return;
|
if (!_logLevels.ContainsKey(level)) return;
|
||||||
|
|
||||||
var logLevel = _logLevels[level];
|
var logLevel = _logLevels[level];
|
||||||
|
|
||||||
var logger = _logger.ForContext("Key", keyed.Key);
|
LogMessage(logLevel, keyed, format, items);
|
||||||
logger.Write(logLevel, format, items);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user