mirror of
https://github.com/kmc7468/arkvault.git
synced 2026-02-04 16:16:55 +00:00
데모를 위해 파일 용량 제한 추가, 비밀번호 변경 기능 삭제, 악용될 수 있는 API에 로깅 추가
This commit is contained in:
37
src/lib/server/modules/logger.ts
Normal file
37
src/lib/server/modules/logger.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import { appendFileSync, existsSync, mkdirSync } from "fs";
|
||||
import { env } from "$env/dynamic/private";
|
||||
|
||||
const LOG_DIR = env.LOG_DIR || "log";
|
||||
|
||||
const getLogFilePath = () => {
|
||||
const date = new Date().toISOString().slice(0, 10); // YYYY-MM-DD
|
||||
return `${LOG_DIR}/arkvault-${date}.log`;
|
||||
};
|
||||
|
||||
const ensureLogDir = () => {
|
||||
if (!existsSync(LOG_DIR)) {
|
||||
mkdirSync(LOG_DIR, { recursive: true });
|
||||
}
|
||||
};
|
||||
|
||||
const formatLogLine = (type: string, data: Record<string, unknown>) => {
|
||||
const timestamp = new Date().toISOString();
|
||||
return JSON.stringify({ timestamp, type, ...data });
|
||||
};
|
||||
|
||||
export const demoLogger = {
|
||||
log: (type: string, data: Record<string, unknown>) => {
|
||||
const line = formatLogLine(type, data);
|
||||
|
||||
// Output to stdout
|
||||
console.log(line);
|
||||
|
||||
// Output to file
|
||||
try {
|
||||
ensureLogDir();
|
||||
appendFileSync(getLogFilePath(), line + "\n", { encoding: "utf-8" });
|
||||
} catch (e) {
|
||||
console.error("Failed to write to log file:", e);
|
||||
}
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user