This commit is contained in:
Dax Raad
2025-06-09 15:00:48 -04:00
parent d8510ab452
commit 60faa26a15
3 changed files with 16 additions and 2 deletions

View File

@@ -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) {