1.1.0 • Published 3 years ago
console-log-to-file v1.1.0
Save console.log/warn/error/info to file for NodeJS
Installation
npm install console-log-to-fileUsage
Add this to very begining of your app:
import { consoleLogToFile } from "console-log-to-file";
// or `const { consoleLogToFile } = require("console-log-to-file/dist/index.cjs.js")`
consoleLogToFile({
logFilePath: "/log/default.log",
});
// below will both log to console and to file:
console.log("Now ", "is", new Date());
console.info("Here", "is", { name: "abc" });
console.warn(new Error("this is an expected warning"), { debugObj: true });
console.error(new Error("this is an expected error"));Output to file by default (you can format it by define options.formatter):

API
consoleLogToFile(options), whereoptionsaccepts:logFilePath(string): file path to save log contentformatter(function(level, args) => string): level is one oflog/warn/error/info,argsis log content. See default formatter.includes(array oflog,warn,error,info): if defined, will only save to file for included console methods. See example here.flagspassed tofs.createWriteStream