1.1.0 • Published 2 years ago

console-log-to-file v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Save console.log/warn/error/info to file for NodeJS

Installation

npm install console-log-to-file

Usage

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):

alt log-file-screenshot

API

  • consoleLogToFile(options), where options accepts:
    • logFilePath (string): file path to save log content
    • formatter (function(level, args) => string): level is one of log/warn/error/info, args is log content. See default formatter.
    • includes (array of log, warn, error, info): if defined, will only save to file for included console methods. See example here.
    • flags passed to fs.createWriteStream
1.1.0

2 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago