mirror of
https://gitea.toothfairyai.com/ToothFairyAI/tf_code.git
synced 2026-04-01 14:52:25 +00:00
sync
This commit is contained in:
@@ -2,16 +2,24 @@ import path from "path"
|
||||
import fs from "fs/promises"
|
||||
import { Global } from "../global"
|
||||
export namespace Log {
|
||||
const Default = create()
|
||||
|
||||
export interface Options {
|
||||
print: boolean
|
||||
}
|
||||
|
||||
let logpath = ""
|
||||
|
||||
export function file() {
|
||||
return logpath
|
||||
}
|
||||
|
||||
export async function init(options: Options) {
|
||||
const dir = path.join(Global.Path.data, "log")
|
||||
await fs.mkdir(dir, { recursive: true })
|
||||
cleanup(dir)
|
||||
if (options.print) return
|
||||
const logpath = path.join(dir, new Date().toISOString() + ".log")
|
||||
logpath = path.join(dir, new Date().toISOString().split(".")[0] + ".log")
|
||||
const logfile = Bun.file(logpath)
|
||||
await fs.truncate(logpath).catch(() => {})
|
||||
const writer = logfile.writer()
|
||||
@@ -20,6 +28,7 @@ export namespace Log {
|
||||
writer.flush()
|
||||
return true
|
||||
}
|
||||
Default.info("initialized", { file: logpath })
|
||||
}
|
||||
|
||||
async function cleanup(dir: string) {
|
||||
|
||||
Reference in New Issue
Block a user