mirror of
https://github.com/Studio-Saelix/sencho.git
synced 2026-08-21 07:36:40 +00:00
feat: show container name in structured log output (#1452)
* feat: show container name in structured log output Prepend a normalized container name prefix to each line in ComposeService.streamLogs() so both the structured log viewer and the raw terminal identify which container produced each entry. - Backend: prepend displayName (normalized via normalizeContainerName) before LogFormatter.process() in sendOutput and flushBuffer. - LogFormatter: refactor process() to handle both prefix-first and timestamp-first input orders via a while-loop; widen PREFIX_REGEX to accept dotted service names. - Frontend: add containerName to LogRow, extract prefix in parseLine, render as an inline mono chip in the message column, and include the name in downloaded logs (omitting the bracket prefix when null). - Tests: 14 new tests across log-formatter, compose-service streamLogs, and StructuredLogViewer chip rendering + download formatting. * fix: guard LogFormatter loop to at most one prefix and one timestamp The while-loop refactored for order-agnostic prefix/timestamp parsing could continue matching beyond the intended single prefix and timestamp. A log line like "redis | 2024-...Z api | started" would falsely colorize "api |" as a second container prefix in raw terminal output. Add prefixFound/timestampFound boolean guards so the loop stops after one prefix and one timestamp, regardless of input order. * feat: per-service color alternation for log container chips Add an Appearance setting that lets users switch between unified cyan and per-service label-token colors for the container name chips in the structured log viewer. - Extract HUE_VARS and hashLabel() from NodeLabelPill into a shared utility at frontend/src/lib/label-colors.ts. - Add useLogChipColorMode hook (browser-local localStorage, sencho.log-chip-color-mode key, unified by default). - Add SegmentedControl in Settings > Appearance > Display. - Apply inline label-token styles via style attribute in per-service mode; keep current text-brand/80 bg-brand/10 classes in unified mode. - 14 new tests across label-colors, hook, and viewer chip rendering.
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { HUE_VARS, hashLabel } from '@/lib/label-colors';
|
||||
|
||||
describe('HUE_VARS', () => {
|
||||
it('has exactly 10 entries', () => {
|
||||
expect(HUE_VARS).toHaveLength(10);
|
||||
});
|
||||
});
|
||||
|
||||
describe('hashLabel', () => {
|
||||
it('returns a valid hue from HUE_VARS', () => {
|
||||
const hue = hashLabel('redis');
|
||||
expect(HUE_VARS).toContain(hue);
|
||||
});
|
||||
|
||||
it('returns the same hue for the same input', () => {
|
||||
expect(hashLabel('redis')).toBe(hashLabel('redis'));
|
||||
});
|
||||
|
||||
it('returns different hues for different inputs (typical case)', () => {
|
||||
// Not a strict guarantee, but highly likely with 10 buckets.
|
||||
const a = hashLabel('redis');
|
||||
const b = hashLabel('postgres');
|
||||
// They may collide, but the function must be stable.
|
||||
expect(HUE_VARS).toContain(a);
|
||||
expect(HUE_VARS).toContain(b);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,15 @@
|
||||
export const HUE_VARS = [
|
||||
'teal', 'blue', 'purple', 'rose', 'amber',
|
||||
'green', 'orange', 'pink', 'cyan', 'slate',
|
||||
] as const;
|
||||
|
||||
export type LabelHue = typeof HUE_VARS[number];
|
||||
|
||||
/** djb2-style hash that maps a string to a stable LabelHue. */
|
||||
export function hashLabel(label: string): LabelHue {
|
||||
let h = 0;
|
||||
for (let i = 0; i < label.length; i += 1) {
|
||||
h = (h * 31 + label.charCodeAt(i)) | 0;
|
||||
}
|
||||
return HUE_VARS[Math.abs(h) % HUE_VARS.length];
|
||||
}
|
||||
Reference in New Issue
Block a user