Skip to content

ServerKit is a lightweight, modern server control panel for managing web applications, databases, and services on your VPS or dedicated server. Built with Python/Flask backend and React frontend.

feat(logs): full-bleed Terminal/Logs with follow-tail + LIVE badge

Juan Denisad4d7eb8bf26
diff --git a/frontend/src/components/log-viewer/LogContent.jsx b/frontend/src/components/log-viewer/LogContent.jsx
index 6494ab4f..a27518bb 100644
--- a/frontend/src/components/log-viewer/LogContent.jsx
+++ b/frontend/src/components/log-viewer/LogContent.jsx
@@ -1,4 +1,4 @@
-import { forwardRef, useMemo } from 'react';
+import { forwardRef, useMemo, useRef, useCallback, useLayoutEffect } from 'react';
import { severityOf, splitOnMatch } from './logHelpers';
const LogContent = forwardRef(function LogContent({
@@ -8,10 +8,44 @@ const LogContent = forwardRef(function LogContent({
showLineNumbers,
wrapLines,
searchPattern,
+ live = false,
+ scrollKey,
}, ref) {
- const lines = useMemo(() => {
- if (!content) return [];
- return content.split('\n');
+ const innerRef = useRef(null);
+ // Whether the viewer is parked at the bottom (following the tail). Starts
+ // true so a freshly opened log lands on its newest line.
+ const followRef = useRef(true);
+
+ // Merge our internal ref with the forwarded ref so the parent keeps its
+ // direct scroll access (jump-to-end button, etc.) while we manage tailing.
+ const setRefs = useCallback((node) => {
+ innerRef.current = node;
+ if (typeof ref === 'function') ref(node);
+ else if (ref) ref.current = node;
+ }, [ref]);
+
+ const lines = useMemo(() => (content ? content.split('\n') : []), [content]);
+
+ // Stop following once the user scrolls up; resume when they return to the
+ // bottom — so live updates don't yank them away while reading history.
+ const handleScroll = useCallback(() => {
+ const el = innerRef.current;
+ if (!el) return;
+ followRef.current = el.scrollHeight - el.scrollTop - el.clientHeight < 48;
+ }, []);
+
+ // New selection (different file / unit / service): jump to the newest line
+ // and re-arm follow.
+ useLayoutEffect(() => {
+ followRef.current = true;
+ const el = innerRef.current;
+ if (el) el.scrollTop = el.scrollHeight;
+ }, [scrollKey]);
+
+ // New content while following: stick to the last record.
+ useLayoutEffect(() => {
+ const el = innerRef.current;
+ if (el && followRef.current) el.scrollTop = el.scrollHeight;
}, [content]);
if (loading) {
@@ -27,33 +61,42 @@ const LogContent = forwardRef(function LogContent({
}
return (
- <div
- ref={ref}
- className={`lv-content ${wrapLines ? 'wrap' : 'nowrap'} ${showLineNumbers ? 'with-line-numbers' : ''}`}
- >
- <div className="lv-lines" role="presentation">
- {lines.map((line, idx) => {
- const sev = severityOf(line);
- const segments = searchPattern ? splitOnMatch(line, searchPattern) : null;
- return (
- <div key={idx} className={`lv-line ${sev ? `sev-${sev}` : ''}`}>
- {showLineNumbers && (
- <span className="lv-line-no">{idx + 1}</span>
- )}
- <span className="lv-line-text">
- {segments
- ? segments.map((seg, i) =>
- seg.match ? (
- <mark key={i} className="lv-match">{seg.text}</mark>
- ) : (
- <span key={i}>{seg.text}</span>
+ <div className="lv-content-wrap">
+ {live && (
+ <span className="lv-live-badge" title="Following the live tail">
+ <span className="lv-live-dot" />
+ LIVE
+ </span>
+ )}
+ <div
+ ref={setRefs}
+ onScroll={handleScroll}
+ className={`lv-content ${wrapLines ? 'wrap' : 'nowrap'} ${showLineNumbers ? 'with-line-numbers' : ''}`}
+ >
+ <div className="lv-lines" role="presentation">
+ {lines.map((line, idx) => {
+ const sev = severityOf(line);
+ const segments = searchPattern ? splitOnMatch(line, searchPattern) : null;
+ return (
+ <div key={idx} className={`lv-line ${sev ? `sev-${sev}` : ''}`}>
+ {showLineNumbers && (
+ <span className="lv-line-no">{idx + 1}</span>
+ )}
+ <span className="lv-line-text">
+ {segments
+ ? segments.map((seg, i) =>
+ seg.match ? (
+ <mark key={i} className="lv-match">{seg.text}</mark>
+ ) : (
+ <span key={i}>{seg.text}</span>
+ )
)
- )
- : (line || ' ')}
- </span>
- </div>
- );
- })}
+ : (line || ' ')}
+ </span>
+ </div>
+ );
+ })}
+ </div>
</div>
</div>
);
diff --git a/frontend/src/pages/Terminal.jsx b/frontend/src/pages/Terminal.jsx
index 4f63f991..79426f98 100644
--- a/frontend/src/pages/Terminal.jsx
+++ b/frontend/src/pages/Terminal.jsx
@@ -27,7 +27,7 @@ const Terminal = () => {
const [activeTab, setActiveTab] = useTabParam('/terminal', VALID_TABS);
return (
- <div className="page-container terminal-page">
+ <div className="page-container page-container--full-bleed terminal-page">
<PageTopbar
icon={<TerminalIcon size={18} />}
title="Terminal / Logs"
@@ -452,6 +452,8 @@ const LogFilesTab = () => {
<LogContent
ref={contentRef}
+ live={autoRefresh}
+ scrollKey={selectedLog}
content={selectedLog ? logContent : ''}
loading={loadingContent}
emptyMessage={
@@ -803,6 +805,8 @@ const JournalTab = () => {
<LogContent
ref={contentRef}
+ live={autoRefresh}
+ scrollKey={unit || source}
content={logContent}
loading={loading}
emptyMessage={
@@ -1655,6 +1659,8 @@ const ServicesTab = () => {
<div className="preview-drawer-body">
<LogContent
ref={logContentRef}
+ live={logAutoRefresh}
+ scrollKey={selectedService?.name}
content={serviceLogs}
loading={logsLoading}
emptyMessage="No log output."
diff --git a/frontend/src/styles/pages/_terminal.scss b/frontend/src/styles/pages/_terminal.scss
index e613d946..caff4c82 100644
--- a/frontend/src/styles/pages/_terminal.scss
+++ b/frontend/src/styles/pages/_terminal.scss
@@ -758,6 +758,89 @@ $lk-default: #646b7a;
}
}
+// Wrapper around the scroll area so the floating LIVE badge can pin to the
+// corner while the log content scrolls underneath.
+.lv-content-wrap {
+ position: relative;
+ flex: 1;
+ min-height: 0;
+ display: flex;
+}
+
+// "Pulling live" indicator shown while a log auto-follows its tail.
+.lv-live-badge {
+ position: absolute;
+ top: 10px;
+ right: 16px;
+ z-index: 4;
+ display: inline-flex;
+ align-items: center;
+ gap: 6px;
+ padding: 3px 10px;
+ border-radius: 999px;
+ font-size: 10.5px;
+ font-weight: 700;
+ letter-spacing: 0.1em;
+ color: #fff;
+ background: var(--red, #dc2626);
+ box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
+ pointer-events: none;
+}
+
+.lv-live-dot {
+ width: 7px;
+ height: 7px;
+ border-radius: 50%;
+ background: #fff;
+ animation: lv-live-pulse 1.3s ease-in-out infinite;
+}
+
+@keyframes lv-live-pulse {
+ 0%, 100% { opacity: 1; transform: scale(1); }
+ 50% { opacity: 0.35; transform: scale(0.65); }
+}
+
+// Full-bleed terminal/logs: fill the content region like the Servers ops view
+// instead of a fixed `calc(100vh - …)`. The page is a flex column; the Radix
+// Tabs panel and the inner panes stretch to fill the available height.
+.terminal-page.page-container--full-bleed {
+ height: 100%;
+ min-height: 0;
+ display: flex;
+ flex-direction: column;
+ padding: $space-3 $space-4;
+ overflow: hidden;
+
+ > .sk-topbar { flex-shrink: 0; }
+
+ > [data-orientation] {
+ flex: 1;
+ min-height: 0;
+ display: flex;
+ flex-direction: column;
+ }
+
+ .tab-content {
+ flex: 1;
+ min-height: 0;
+ display: flex;
+ flex-direction: column;
+ }
+
+ .tab-content > [role="tabpanel"] {
+ flex: 1;
+ min-height: 0;
+ }
+
+ .term-shell,
+ .lv-page:not(.fullscreen),
+ .proc-page,
+ .svc-page {
+ height: 100%;
+ min-height: 0;
+ }
+}
+
.lv-content-loading,
.lv-content-empty {
display: flex;