Миграция оркестратора на Debian 13: platform layer, preflight, status/diagnostics и structured logging
This commit is contained in:
@@ -1,11 +1,45 @@
|
||||
let operationId = "";
|
||||
|
||||
function nowIso(): string {
|
||||
return new Date().toISOString();
|
||||
}
|
||||
|
||||
function ensureOperationId(): string {
|
||||
if (!operationId) {
|
||||
operationId = `op-${Date.now().toString(36)}`;
|
||||
}
|
||||
return operationId;
|
||||
}
|
||||
|
||||
export function setOperationContext(id: string): void {
|
||||
operationId = id;
|
||||
}
|
||||
|
||||
function emit(level: "STEP" | "INFO" | "ERROR", message: string, stepName?: string, status?: "start" | "ok" | "fail"): void {
|
||||
const payload = {
|
||||
ts: nowIso(),
|
||||
op_id: ensureOperationId(),
|
||||
level,
|
||||
step: stepName ?? null,
|
||||
status: status ?? null,
|
||||
message
|
||||
};
|
||||
console.log(`[hy2xs] ${JSON.stringify(payload)}`);
|
||||
}
|
||||
|
||||
export function step(name: string): void {
|
||||
console.log(`\n[hy2xs] ==> ${name}`);
|
||||
emit("STEP", `==> ${name}`, name, "start");
|
||||
}
|
||||
|
||||
export function stepDone(name: string): void {
|
||||
emit("STEP", `<== ${name}`, name, "ok");
|
||||
}
|
||||
|
||||
export function info(message: string): void {
|
||||
console.log(`[hy2xs] ${message}`);
|
||||
emit("INFO", message);
|
||||
}
|
||||
|
||||
export function fail(message: string): never {
|
||||
emit("ERROR", message, undefined, "fail");
|
||||
throw new Error(message);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user