LogViewer 组件 — sgcHTML | eSeGeCe

LogViewer

TsgcHTMLComponent_LogViewer — 一个带级别过滤、搜索、自动滚动和深色/浅色主题的流式日志/终端查看器,适用于 Delphi、C++ Builder 和 .NET。

TsgcHTMLComponent_LogViewer

使用 AddLine 推送行,它们会保存在容量受限的环形缓冲区中,然后读取 HTML 属性,或使用 GetLastLineFragmentHTML 将新行流式传输给已连接的客户端。

组件类

TsgcHTMLComponent_LogViewer

渲染为

工具栏 + 终端样式日志主体 + 作用域 CSS

语言

Delphi, C++ Builder, .NET

添加行、渲染它、流式更新

为每个条目调用 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 清空它。

级别

TsgcHTMLLogLevelllTracellDebugllInfollWarningllErrorllFatal — 每个级别都按 Theme 进行了颜色编码。

工具栏

ShowSearchShowLevelFilterTitle 控制工具栏;过滤和高亮在客户端运行,无需往返请求。

自动滚动

AutoScroll 跟随最新一行;ShowAutoScrollToggle 添加一个复选框,让读者在向上滚动查看历史时可以暂停跟随。

流式更新

GetLastLineFragmentHTML / GetLineFragmentHTML(aIndex) 渲染一个带外片段,供 TsgcHTMX_Engine_Server.PushFragment / BroadcastFragment 使用。

外观

ThemeltDark / ltLight)、WrapLinesHeightTimeFormatEmptyText 用于调整外观。

继续探索

在线帮助此组件的完整 API 参考和使用指南。
所有 sgcHTML 组件浏览 80 多个组件的完整功能矩阵。
下载免费试用版30 天试用版附带 60.HTML 演示项目。
价格Single、Team 和 Site 授权,均含完整源代码。

准备好开始了吗?

下载免费试用版,为您的 Delphi、C++ Builder 或 .NET Web 应用添加实时日志查看器。