mirror of
https://github.com/versia-pub/server.git
synced 2025-12-06 08:28:19 +01:00
fix: 🔊 Automatically create logs folder if it doesn't exist
This commit is contained in:
parent
457a4054b7
commit
764061b4be
|
|
@ -1,17 +1,6 @@
|
|||
import {
|
||||
type Stats,
|
||||
appendFileSync,
|
||||
closeSync,
|
||||
existsSync,
|
||||
mkdirSync,
|
||||
openSync,
|
||||
renameSync,
|
||||
statSync,
|
||||
} from "node:fs";
|
||||
import {
|
||||
type RotatingFileSinkDriver,
|
||||
getRotatingFileSink,
|
||||
} from "@logtape/file";
|
||||
import { mkdir } from "node:fs/promises";
|
||||
import { dirname } from "node:path";
|
||||
import { getRotatingFileSink } from "@logtape/file";
|
||||
import {
|
||||
type LogLevel,
|
||||
type LogRecord,
|
||||
|
|
@ -22,6 +11,9 @@ import {
|
|||
import chalk from "chalk";
|
||||
import { config } from "~/config.ts";
|
||||
|
||||
// config.logging.log_file_path is a path to a file, create the directory if it doesn't exist
|
||||
await mkdir(dirname(config.logging.log_file_path), { recursive: true });
|
||||
|
||||
const levelAbbreviations: Record<LogLevel, string> = {
|
||||
debug: "DBG",
|
||||
info: "INF",
|
||||
|
|
@ -74,35 +66,6 @@ export function defaultConsoleFormatter(record: LogRecord): string[] {
|
|||
];
|
||||
}
|
||||
|
||||
export const nodeDriver: RotatingFileSinkDriver<number> = {
|
||||
openSync(path: string): number {
|
||||
return openSync(path, "a");
|
||||
},
|
||||
writeSync(fd, chunk): void {
|
||||
appendFileSync(fd, chunk, {
|
||||
flush: true,
|
||||
});
|
||||
},
|
||||
flushSync(): void {
|
||||
// ...
|
||||
},
|
||||
closeSync(fd): void {
|
||||
closeSync(fd);
|
||||
},
|
||||
statSync(path): Stats {
|
||||
// If file does not exist, create it
|
||||
if (!existsSync(path)) {
|
||||
// Mkdir all directories in path
|
||||
const dirs = path.split("/");
|
||||
dirs.pop();
|
||||
mkdirSync(dirs.join("/"), { recursive: true });
|
||||
appendFileSync(path, "");
|
||||
}
|
||||
return statSync(path);
|
||||
},
|
||||
renameSync,
|
||||
};
|
||||
|
||||
export const configureLoggers = (silent = false): Promise<void> =>
|
||||
configure({
|
||||
reset: true,
|
||||
|
|
|
|||
Loading…
Reference in a new issue