{
"tasks": {
- "dev": "deno run --allow-net --allow-env --allow-read --env-file --unstable-kv main.ts",
- "start": "deno run --allow-net --allow-env --allow-read --env-file --unstable-kv main.ts"
+ "dev": "deno run --allow-net --allow-env --allow-read --allow-write --env-file --unstable-kv main.ts",
+ "start": "deno run --allow-net --allow-env --allow-read --allow-write --env-file --unstable-kv main.ts"
},
"imports": {
"hono": "npm:hono@^4",
--- /dev/null
+// Patches global console so every log/warn/error is written to logs/YYYY-MM-DD.log
+// Import once at the top of main.ts — no other changes needed anywhere.
+
+const LOG_DIR = "./logs";
+
+try {
+ Deno.mkdirSync(LOG_DIR, { recursive: true });
+} catch { /* already exists */ }
+
+const enc = new TextEncoder();
+let currentDate = "";
+let file: Deno.FsFile | null = null;
+
+function getFile(): Deno.FsFile {
+ const today = new Date().toISOString().slice(0, 10); // YYYY-MM-DD
+ if (today !== currentDate) {
+ file?.close();
+ file = Deno.openSync(`${LOG_DIR}/${today}.log`, { create: true, append: true });
+ currentDate = today;
+ }
+ return file!;
+}
+
+function write(level: string, args: unknown[]) {
+ const ts = new Date().toISOString();
+ const body = args
+ .map((a) => (typeof a === "string" ? a : JSON.stringify(a, null, 2)))
+ .join(" ");
+ try {
+ getFile().writeSync(enc.encode(`[${ts}] [${level}] ${body}\n`));
+ } catch { /* don't let a log failure crash the app */ }
+}
+
+const _log = console.log.bind(console);
+const _info = console.info.bind(console);
+const _warn = console.warn.bind(console);
+const _error = console.error.bind(console);
+
+console.log = (...a: unknown[]) => { _log(...a); write("INFO", a); };
+console.info = (...a: unknown[]) => { _info(...a); write("INFO", a); };
+console.warn = (...a: unknown[]) => { _warn(...a); write("WARN", a); };
+console.error = (...a: unknown[]) => { _error(...a); write("ERROR", a); };