|
@@ -2,16 +2,24 @@ import path from "path"
|
|
|
import fs from "fs/promises"
|
|
import fs from "fs/promises"
|
|
|
import { Global } from "../global"
|
|
import { Global } from "../global"
|
|
|
export namespace Log {
|
|
export namespace Log {
|
|
|
|
|
+ const Default = create()
|
|
|
|
|
+
|
|
|
export interface Options {
|
|
export interface Options {
|
|
|
print: boolean
|
|
print: boolean
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ let logpath = ""
|
|
|
|
|
+
|
|
|
|
|
+ export function file() {
|
|
|
|
|
+ return logpath
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
export async function init(options: Options) {
|
|
export async function init(options: Options) {
|
|
|
const dir = path.join(Global.Path.data, "log")
|
|
const dir = path.join(Global.Path.data, "log")
|
|
|
await fs.mkdir(dir, { recursive: true })
|
|
await fs.mkdir(dir, { recursive: true })
|
|
|
cleanup(dir)
|
|
cleanup(dir)
|
|
|
if (options.print) return
|
|
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)
|
|
const logfile = Bun.file(logpath)
|
|
|
await fs.truncate(logpath).catch(() => {})
|
|
await fs.truncate(logpath).catch(() => {})
|
|
|
const writer = logfile.writer()
|
|
const writer = logfile.writer()
|
|
@@ -20,6 +28,7 @@ export namespace Log {
|
|
|
writer.flush()
|
|
writer.flush()
|
|
|
return true
|
|
return true
|
|
|
}
|
|
}
|
|
|
|
|
+ Default.info("initialized", { file: logpath })
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
async function cleanup(dir: string) {
|
|
async function cleanup(dir: string) {
|