refactor: migrate src/util/log.ts from Bun.file() to Node.js fs module (#14136)
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import path from "path"
|
import path from "path"
|
||||||
import fs from "fs/promises"
|
import fs from "fs/promises"
|
||||||
|
import { createWriteStream } from "fs"
|
||||||
import { Global } from "../global"
|
import { Global } from "../global"
|
||||||
import z from "zod"
|
import z from "zod"
|
||||||
|
|
||||||
@@ -63,13 +64,15 @@ export namespace Log {
|
|||||||
Global.Path.log,
|
Global.Path.log,
|
||||||
options.dev ? "dev.log" : new Date().toISOString().split(".")[0].replace(/:/g, "") + ".log",
|
options.dev ? "dev.log" : new Date().toISOString().split(".")[0].replace(/:/g, "") + ".log",
|
||||||
)
|
)
|
||||||
const logfile = Bun.file(logpath)
|
|
||||||
await fs.truncate(logpath).catch(() => {})
|
await fs.truncate(logpath).catch(() => {})
|
||||||
const writer = logfile.writer()
|
const stream = createWriteStream(logpath, { flags: "a" })
|
||||||
write = async (msg: any) => {
|
write = async (msg: any) => {
|
||||||
const num = writer.write(msg)
|
return new Promise((resolve, reject) => {
|
||||||
writer.flush()
|
stream.write(msg, (err) => {
|
||||||
return num
|
if (err) reject(err)
|
||||||
|
else resolve(msg.length)
|
||||||
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user