nodejs-logging-mat

logging package for nodejs

Usage no npm install needed!

<script type="module">
  import nodejsLoggingMat from 'https://cdn.skypack.dev/nodejs-logging-mat';
</script>

README

Installation

npm install nodejs-logging-mat --save

or using yarn

yarn add nodejs-logging-mat

Description

All the file will automatically save to app root directory's logs folder.
Info Log Debug will save to stdlog.log
Error will save to stderr.log

Usage

import LoggerRegister from "nodejs-logging-mat";

// rolling: "daily" / "weekly" / "monthly"
const logger = new LoggerRegister({ saveToFile: true, rolling: "monthly", timezone: "Asia/Hong_Kong" });
// The context is optional.
const idx = logger.getLogger("IndexClass");
// once you have assigned the register in pervious step
// you can use the static method getInstance() to get the instance
const ts = LoggerRegister.getInstance().getLogger("TestClass");
// You can also do this
const noContext = logger.getLogger();

const ary = [1, 2, 3, 4, 5];
const error = new Error("test error");

idx.info(ary);
idx.log(ary, { a: 1, b: [1, 2, 3, 4] });
idx.error(error);
ts.debug("Test Debug");
noContext.info("No Class Tag")

Result