LogViewer
TsgcHTMLComponent_LogViewer — 一个带级别过滤、搜索、自动滚动和深色/浅色主题的流式日志/终端查看器,适用于 Delphi、C++ Builder 和 .NET。
TsgcHTMLComponent_LogViewer — 一个带级别过滤、搜索、自动滚动和深色/浅色主题的流式日志/终端查看器,适用于 Delphi、C++ Builder 和 .NET。
使用 AddLine 推送行,它们会保存在容量受限的环形缓冲区中,然后读取 HTML 属性,或使用 GetLastLineFragmentHTML 将新行流式传输给已连接的客户端。
为每个条目调用 AddLine,读取 HTML 进行初始渲染,然后使用 GetLastLineFragmentHTML 将新行推送给已打开的 WebSocket 客户端。
uses
sgcHTML_Component_LogViewer;
var
oLog: TsgcHTMLComponent_LogViewer;
begin
oLog := TsgcHTMLComponent_LogViewer.Create(nil);
try
oLog.LogID := 'applog';
oLog.Theme := ltDark;
oLog.MaxLines := 500;
oLog.Height := '400px';
oLog.AddLine(llInfo, 'Service started', 'app');
oLog.AddLine(llWarning, 'Low disk space', 'monitor');
oLog.AddLine(llError, 'Connection refused', 'db');
WebModule.Response := oLog.HTML; // toolbar + log body + inline script
finally
oLog.Free;
end;
end;
// Push one more line to every connected client, no full re-render:
oLog.AddLine(llInfo, 'New order received', 'orders');
TsgcHTMX_Engine_Server.BroadcastFragment(oLog.GetLastLineFragmentHTML);
// includes: sgcHTML_Component_LogViewer.hpp
TsgcHTMLComponent_LogViewer *oLog = new TsgcHTMLComponent_LogViewer(NULL);
try
{
oLog->LogID = "applog";
oLog->Theme = ltDark;
oLog->MaxLines = 500;
oLog->Height = "400px";
oLog->AddLine(llInfo, "Service started", "app");
oLog->AddLine(llWarning, "Low disk space", "monitor");
oLog->AddLine(llError, "Connection refused", "db");
String html = oLog->HTML; // toolbar + log body + inline script
// Push one more line to every connected client:
oLog->AddLine(llInfo, "New order received", "orders");
TsgcHTMX_Engine_Server::BroadcastFragment(oLog->GetLastLineFragmentHTML());
}
__finally
{
delete oLog;
}
using esegece.sgcWebSockets;
var log = new TsgcHTMLComponent_LogViewer();
log.LogID = "applog";
log.Theme = TsgcHTMLLogTheme.ltDark;
log.MaxLines = 500;
log.Height = "400px";
log.AddLine(TsgcHTMLLogLevel.llInfo, "Service started", "app");
log.AddLine(TsgcHTMLLogLevel.llWarning, "Low disk space", "monitor");
log.AddLine(TsgcHTMLLogLevel.llError, "Connection refused", "db");
string html = log.HTML; // toolbar + log body + inline script
// Push one more line to every connected client, no full re-render:
log.AddLine(TsgcHTMLLogLevel.llInfo, "New order received", "orders");
TsgcHTMX_Engine_Server.BroadcastFragment(log.GetLastLineFragmentHTML());
您最常使用的成员。
AddLine(aLevel, aText, aSource) 追加一条带时间戳的条目;MaxLines(默认 500)限制环形缓冲区大小并丢弃最旧的行。Clear 清空它。
TsgcHTMLLogLevel — llTrace、llDebug、llInfo、llWarning、llError、llFatal — 每个级别都按 Theme 进行了颜色编码。
ShowSearch、ShowLevelFilter 和 Title 控制工具栏;过滤和高亮在客户端运行,无需往返请求。
AutoScroll 跟随最新一行;ShowAutoScrollToggle 添加一个复选框,让读者在向上滚动查看历史时可以暂停跟随。
GetLastLineFragmentHTML / GetLineFragmentHTML(aIndex) 渲染一个带外片段,供 TsgcHTMX_Engine_Server.PushFragment / BroadcastFragment 使用。
Theme(ltDark / ltLight)、WrapLines、Height、TimeFormat 和 EmptyText 用于调整外观。