I'm trying to setup some loggers for an app. I have a console
handler which write every log to the console. And a app
handler which should write any log to some file.
The logs are writen correctly to the console, but none of the files are writen, and I can't get why.
import { setup as loggerSetup, getLogger } from "https://deno.land/std/log/mod.ts";
import {
ConsoleHandler,
FileHandler,
} from "https://deno.land/std/log/handlers.ts";
import { ensureDir } from "https://deno.land/std/fs/ensure_dir.ts";
const logDir = Deno.env.get("LOG_DIR") || "./logs";
await ensureDir(logDir);
const consoleLoggerHandler = new ConsoleHandler("DEBUG");
const applicationLoggerHandler = new FileHandler("DEBUG", {
filename: logDir + "/application.log",
formatter: "{msg}",
});
const errorLoggerHandler = new FileHandler("WARNING", {
filename: logDir + "/errors.log",
});
await loggerSetup({
handlers: {
console: consoleLoggerHandler,
app: applicationLoggerHandler,
errors: errorLoggerHandler,
},
loggers: {
default: {
level: "DEBUG",
handlers: ["console", "app"],
},
app: {
level: "INFO",
handlers: ["app"],
},
error: {
level: "WARNING",
handlers: ["errors"],
},
},
});
export const logger = getLogger();
export const appLogger = getLogger("app");
export const errorLogger = getLogger("error");
you have to call applicationLoggerHandler.flush()
method in order to write on file.