mirror of
https://github.com/Stone-Red-Code/RemSox.git
synced 2026-09-04 00:56:19 +02:00
40 lines
1.0 KiB
C#
40 lines
1.0 KiB
C#
using RemSox.Logging;
|
|
using RemSox.Processing;
|
|
|
|
namespace RemSox.UI.CLI.Commands;
|
|
|
|
public class ViewProcessLogs : ICommand
|
|
{
|
|
public string Name => "logs";
|
|
|
|
public string Description => "View logs for a process";
|
|
|
|
public Task ExecuteAsync(string? arguments, Action<string> printLine)
|
|
{
|
|
if (int.TryParse(arguments, out int processId))
|
|
{
|
|
IEnumerable<LogEntry> logs = ProcessManager.GetProcessLogs(processId);
|
|
PrintLogs(logs, printLine);
|
|
}
|
|
else
|
|
{
|
|
IEnumerable<LogEntry> logs = ProcessManager.GetLogs();
|
|
PrintLogs(logs, printLine);
|
|
}
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
private static void PrintLogs(IEnumerable<LogEntry> logs, Action<string> printLine)
|
|
{
|
|
if (!logs.Any())
|
|
{
|
|
printLine("No logs found!");
|
|
return;
|
|
}
|
|
|
|
foreach (LogEntry log in logs)
|
|
{
|
|
printLine($"[{log.Timestamp:HH:mm:ss}] [{log.Severity}] {log.Message}");
|
|
}
|
|
}
|
|
} |