@xan105/log
TypeScript icon, indicating that this package has built-in type declarations

2.0.1 • Public • Published

About

A very simple logger.

Install

npm install @xan105/log

Usage example

import Logger from "@xan105/log";
const debug = new Logger({
  console: true,
  file: "./example.log",
  appendToFile: false //create a new file
});

debug.log("this is a string");
debug.log("this is a string","info");
debug.info("this is a string");
debug.warn("this is a warning");
debug.error("this is an error");

Log in the same file from different places

//Wrapper "log.js"
import Logger from "@xan105/log";
const debug = new Logger({
  console: true,
  file: "./example.log"
});
export { debug };

//file a "a.js"
import { debug } from "./log.js";
debug.log("this is a");

//file b "b.js"
import { debug } from "./log.js";
debug.log("this is b");

//Both output in ./example.log

API

⚠️ This module is only available as an ECMAScript module (ESM) starting with version 2.0.0.
Previous version(s) are CommonJS (CJS) with an ESM wrapper.

Default export

(option?: obj): class

option ⚙️

name type default description
console bool false log to the console
file string/null null log to given filePath
appendToFile bool false write mode: append to file or create new

Return an instance of the Logger class with the following methods:

log(event: any, level: string): void

Accepted level: "info", "warn", "error".
Default to "info".

info(event: any): void

Alias of log level info

warn(event: any): void

Alias of log level warn

error(event: any): void

Alias of log level error

Package Sidebar

Install

npm i @xan105/log

Weekly Downloads

5

Version

2.0.1

License

MIT

Unpacked Size

8.99 kB

Total Files

5

Last publish

Collaborators

  • xan105