Files
structrail-design/tracers.ts/src/tracers/log-tracer.ts
2026-02-04 01:20:20 +08:00

45 lines
848 B
TypeScript

import { getTracerContext } from '../context';
interface LogTracerCreateOptions {
description?: string;
}
export const createLogTracer = (options: LogTracerCreateOptions) => {
const { description = 'LogTracer' } = options;
const tracer = crypto.randomUUID();
const { command } = getTracerContext();
command({
type: 'LogTracer',
tracer: tracer,
action: 'create',
params: {
description: description,
},
});
const log = (...args: unknown[]) => {
const parsed = args.map((arg) => {
if (typeof arg === 'string') {
return arg;
}
return JSON.stringify(arg);
});
const message = parsed.join(' ');
command({
type: 'LogTracer',
tracer: tracer,
action: 'log',
params: {
message: message,
},
});
};
return {
log,
};
};