mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-12 23:40:45 +00:00
25 lines
591 B
TypeScript
25 lines
591 B
TypeScript
import { format } from "node:util";
|
|
import type { RuntimeEnv } from "../runtime.js";
|
|
|
|
type LoggerLike = {
|
|
info: (message: string) => void;
|
|
error: (message: string) => void;
|
|
};
|
|
|
|
export function createLoggerBackedRuntime(params: {
|
|
logger: LoggerLike;
|
|
exitError?: (code: number) => Error;
|
|
}): RuntimeEnv {
|
|
return {
|
|
log: (...args) => {
|
|
params.logger.info(format(...args));
|
|
},
|
|
error: (...args) => {
|
|
params.logger.error(format(...args));
|
|
},
|
|
exit: (code: number): never => {
|
|
throw params.exitError?.(code) ?? new Error(`exit ${code}`);
|
|
},
|
|
};
|
|
}
|