feat(scenario): split log args into message/data and add debug level
CI / changes (pull_request) Successful in 12s
CI / version (pull_request) Skipped
CI / server (pull_request) Successful in 1m4s
CI / client (pull_request) Successful in 1m33s
CI / image (pull_request) Skipped

- context.log/warn/error and console.* split arguments: strings join
  into message, object/array args are kept out of it and stored as
  the log entry's new data column (JSON), so message stays a stable
  string regardless of an object's shape
- added a debug log level alongside log/warn/error, including
  context.debug() and console.debug() (previously folded into log)
- CSV/Markdown run log export include the data column/block
- LogOutput renders data pretty-printed in a separate block below
  the message, and dims debug entries with a dedicated grey token
  calibrated to the WCAG AA contrast floor
This commit is contained in:
ars9 committed 2026-10-01 14:09:45 +03:00
1 parent 6cba785e2f
commit 1273491eee
13 files changed
+204 -45

No files matched your search

@@ -9,7 +9,7 @@ import {
import { ScenarioRunStepEntity } from "./scenario-run-step.entity";
import { ScenarioRunEntity } from "./scenario-run.entity";
export type LogLevel = "log" | "warn" | "error";
export type LogLevel = "debug" | "log" | "warn" | "error";
@Entity("scenario_run_logs")
export class ScenarioRunLogEntity {
@@ -43,6 +43,11 @@ export class ScenarioRunLogEntity {
@Column({ type: "text" })
message: string;
// JSON payload attached to the message (e.g. a created file's metadata),
// kept separate so message stays a stable, human-readable string.
@Column({ type: "text", nullable: true })
data: string | null;
// Assigned in call order per run, since concurrent unawaited writes can
// otherwise persist out of order (createdAt alone isn't a reliable tiebreaker).
@Column({ type: "int", default: 0 })
@@ -149,21 +149,30 @@ export class ScenarioSchedulerService implements OnModuleInit {
private persistLog(
runId: string,
stepRunId: string | null,
level: "log" | "warn" | "error",
level: "debug" | "log" | "warn" | "error",
message: string,
context: string | null = null,
data: unknown = null,
): void {
const seq = (this.runLogSeq.get(runId) ?? 0) + 1;
this.runLogSeq.set(runId, seq);
void this.runLogRepo.save(
this.runLogRepo.create({ runId, stepRunId, level, message, context, seq }),
this.runLogRepo.create({
runId,
stepRunId,
level,
message,
context,
data: data != null ? JSON.stringify(data) : null,
seq,
}),
);
}
private stepLogger(stepRunId: string, runId: string): ScriptLogger {
return (level, msg, context) => {
return (level, msg, context, data) => {
this.logger[level](`StepRun #${stepRunId} script: ${msg}`);
this.persistLog(runId, stepRunId, level, msg, context ?? null);
this.persistLog(runId, stepRunId, level, msg, context ?? null, data ?? null);
};
}
+9 -6
View File
@@ -611,9 +611,9 @@ export class ScenarioService implements OnModuleInit {
const escapeCsv = (value: string): string =>
/[",\n]/.test(value) ? `"${value.replace(/"/g, '""')}"` : value;
const rows = [
["Timestamp", "Level", "Context", "Message"].map(escapeCsv).join(","),
["Timestamp", "Level", "Context", "Message", "Data"].map(escapeCsv).join(","),
...logs.map((l) =>
[l.createdAt.toISOString(), l.level, l.context ?? "", l.message]
[l.createdAt.toISOString(), l.level, l.context ?? "", l.message, l.data ?? ""]
.map((v) => escapeCsv(String(v)))
.join(","),
),
@@ -621,10 +621,13 @@ export class ScenarioService implements OnModuleInit {
return rows.join("\n");
}
const sections = logs.map(
(l) =>
`## [${l.level}]${l.context ? ` (${l.context})` : ""} ${l.createdAt.toISOString()}\n\n${l.message}`,
);
const sections = logs.map((l) => {
const header = `## [${l.level}]${l.context ? ` (${l.context})` : ""} ${l.createdAt.toISOString()}`;
const data = l.data
? `\n\n\`\`\`json\n${JSON.stringify(JSON.parse(l.data), null, 2)}\n\`\`\``
: "";
return `${header}\n\n${l.message}${data}`;
});
return [`# Run ${runId} logs`, ...sections].join("\n\n");
}