initial commit
This commit is contained in:
68
Lab505.Client/Services/LogFormat.cs
Normal file
68
Lab505.Client/Services/LogFormat.cs
Normal file
@@ -0,0 +1,68 @@
|
||||
namespace Lab505.Client.Services;
|
||||
|
||||
/// <summary>
|
||||
/// Single source of truth for output-log HTML rendering.
|
||||
/// Badges: INFO · DONE · ERR · WARN · DEV
|
||||
/// Columns: [ts]=75px BADGE=46px DEVICE=54px COMMAND=220px STATUS=flexible
|
||||
/// </summary>
|
||||
public static class LogFormat
|
||||
{
|
||||
// ── Severity colors (MudBlazor-aligned) ──────────────────────────────
|
||||
public const string CInfo = "#42a5f5"; // INFO blue
|
||||
public const string CWarn = "#ffa726"; // WARN orange
|
||||
public const string CSuccess = "#66bb6a"; // DONE green
|
||||
public const string CError = "#ef5350"; // ERR red
|
||||
public const string CDev = "#9575cd"; // DEV purple
|
||||
|
||||
// ── Column styles ─────────────────────────────────────────────────────
|
||||
public const string ColTs = "display:inline-block;width:75px;color:#484848";
|
||||
public const string ColDev = "display:inline-block;width:54px;color:#9e9e9e";
|
||||
public const string ColCmd = "display:inline-block;width:350px;color:#c8c8c8";
|
||||
|
||||
public static string Ts() => DateTime.Now.ToString("HH:mm:ss");
|
||||
|
||||
// ── Level → (color, badge) ────────────────────────────────────────────
|
||||
public static (string color, string badge) LevelBadge(string level) => level switch
|
||||
{
|
||||
"success" => (CSuccess, "DONE"),
|
||||
"error" => (CError, "ERR"),
|
||||
"warning" => (CWarn, "WARN"),
|
||||
"dev" => (CDev, "DEV"),
|
||||
"heartbeat" => (CInfo, "HB"),
|
||||
_ => (CInfo, "INFO"),
|
||||
};
|
||||
|
||||
// ── Level → status HTML ───────────────────────────────────────────────
|
||||
public static string LevelStatus(string level) => level switch
|
||||
{
|
||||
"success" => $"<span style='color:{CSuccess}'>✓</span>",
|
||||
"error" => $"<span style='color:{CError}'>✗</span>",
|
||||
"warning" => $"<span style='color:{CWarn}'>⚠</span>",
|
||||
_ => "",
|
||||
};
|
||||
|
||||
/// <summary>5-column line: [ts] BADGE DEVICE COMMAND STATUS │ detail</summary>
|
||||
public static string Line(string color, string badge, string device, string command, string status, string? detail = null)
|
||||
{
|
||||
var badgeStyle = $"display:inline-block;width:46px;color:{color};font-weight:700";
|
||||
var detPart = detail != null
|
||||
? $"<span style='color:#606060'> │ </span><span style='color:#a0a0a0'>{detail}</span>"
|
||||
: "";
|
||||
return $"<span style='{ColTs}'>[{Ts()}]</span>" +
|
||||
$"<span style='{badgeStyle}'>{badge}</span>" +
|
||||
$"<span style='{ColDev}'>{device}</span>" +
|
||||
$"<span style='{ColCmd}'>{command}</span>" +
|
||||
$"<span style='color:#c8c8c8'>{status}</span>" +
|
||||
detPart;
|
||||
}
|
||||
|
||||
/// <summary>3-column line for DEV state changes: [ts] BADGE DEVICE message</summary>
|
||||
public static string LineRaw(string color, string badge, string device, string msg)
|
||||
{
|
||||
var badgeStyle = $"display:inline-block;width:46px;color:{color};font-weight:700";
|
||||
return $"<span style='{ColTs}'>[{Ts()}]</span>" +
|
||||
$"<span style='{badgeStyle}'>{badge}</span>" +
|
||||
$"<span style='{ColDev}'>{device}</span>" +
|
||||
$"<span style='color:#c8c8c8'>{msg}</span>";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user