mirror of
https://github.com/aljazceru/opencode.git
synced 2025-12-22 10:14:22 +01:00
sync
This commit is contained in:
@@ -1,4 +1,27 @@
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import { AppPath } from "../app/path";
|
||||
export namespace Log {
|
||||
const write = {
|
||||
out: (msg: string) => {
|
||||
process.stdout.write(msg);
|
||||
},
|
||||
err: (msg: string) => {
|
||||
process.stderr.write(msg);
|
||||
},
|
||||
};
|
||||
|
||||
export function file(directory: string) {
|
||||
const out = Bun.file(
|
||||
path.join(AppPath.data(directory), "opencode.out.log"),
|
||||
);
|
||||
const err = Bun.file(
|
||||
path.join(AppPath.data(directory), "opencode.err.log"),
|
||||
);
|
||||
write["out"] = (msg) => out.write(msg);
|
||||
write["err"] = (msg) => err.write(msg);
|
||||
}
|
||||
|
||||
export function create(tags?: Record<string, any>) {
|
||||
tags = tags || {};
|
||||
|
||||
@@ -9,14 +32,14 @@ export namespace Log {
|
||||
})
|
||||
.map(([key, value]) => `${key}=${value}`)
|
||||
.join(" ");
|
||||
return [prefix, message];
|
||||
return [prefix, message].join(" ");
|
||||
}
|
||||
const result = {
|
||||
info(message?: any, extra?: Record<string, any>) {
|
||||
console.log(...build(message, extra));
|
||||
write.out(build(message, extra));
|
||||
},
|
||||
error(message?: any, extra?: Record<string, any>) {
|
||||
console.error(...build(message, extra));
|
||||
write.err(build(message, extra));
|
||||
},
|
||||
tag(key: string, value: string) {
|
||||
if (tags) tags[key] = value;
|
||||
|
||||
Reference in New Issue
Block a user