logging-pretty
TypeScript icon, indicating that this package has built-in type declarations

1.8.8 • Public • Published

LOGGING-PRETTY

GitHub top language Made by Repository size GitHub last commit


Awesome logging with option save to file


💻 Step to install :

npm install logging-pretty

✏️ Example :

Typescript

import init from "logging-pretty";
const log = init(null, "anything");
log.info("hello world"); // output = [0000-00-00 00:00:00:000] [INFO] #anything hello world

ESM (import)

import init from "logging-pretty";
const log = init.default(null, "anything");
log.info("hello world"); // output = [0000-00-00 00:00:00:000] [INFO] #anything hello world

CommonJs (require)

const { default: init } = require("logging-pretty");
const log = init(null, "anything");
log.info("hello world"); // output = [0000-00-00 00:00:00:000] [INFO] #anything hello world

Usage

const { default: init } = require("logging-pretty");

let countTask = 16;
let countTaskCompleted = 0;
let percent = 0;

/**
 * @param pathFile [optional] example "./db.log" if path dont have file, script will create and write new file
 * @param uniqTag [optional] unique tag for each log, if this is set then the log output will start with this #....
 * @param force [optional] force mode, if "pathFile" is set but this is set to "console" it will not write to the log file.
 * @param mid [optional] middleware before write to console and file, must be return string
 * @returns object
 */
const log = init(null, "anything", "all", (msg) => {
  if (tag == "INFO") {
    countTaskCompleted += 1;
    percent = (countTaskCompleted / countTask) * 100;
    return `${percent}%. ${msg}`;
  }

  return msg;
});

log.info("task writeFile completed"); // output = [0000-00-00 00:00:00:000] [INFO] #anything 6.25%. task completed
log.info("task appendFile completed"); // output = [0000-00-00 00:00:00:000] [INFO] #anything 12.5%. task completed

🧾 Pre-Requisistes :

node.js

📝 License :

Licensed under the MIT License.

Package Sidebar

Install

npm i logging-pretty

Weekly Downloads

2

Version

1.8.8

License

MIT

Unpacked Size

15.4 kB

Total Files

7

Last publish

Collaborators

  • damartripamungkas