New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

moologger

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

moologger

A simple, beautiful and easy to use logger!

latest
Source
npmnpm
Version
1.0.4
Version published
Maintainers
1
Created
Source

MooLogger

Version License PRs Prettier

A simple, beautiful, and easy-to-use logger!

Getting Started

It's pretty straightforward:

const { MooLogger } = require("moologger")

const logger = new MooLogger()
logger.info("Hello world!")

Configuration can be done in the constructor:

new MooLogger({
  logLevel: 4,
  /*
      0: disabled,
      1: fatal,
      2: error,
      3: warn,
      4: info,
      5: debug,
      default: 4
    */
  logFolder: "path/to/folder", // The directory where the logger stores logs
  timestamp: true, // Display timestamp? (true by default)
  lang: {
    debug: "DEBUG",
    info: "INFO",
    warn: "WARN",
    error: "ERROR",
    fatal: "FATAL",
  }, // You can customize badge strings like this
})

Available functions

logger.debug(...data)
logger.info(...data)
logger.warn(...data)
logger.error(...data)
logger.fatal(...data)

It just works:tm:, like the built-in console.

Examples

The most simple usage you can possibly think of:

const logger = new MooLogger()

// info & debug
logger.info("Important", "data")
logger.debug("$ Pay Taxes $")

// warn
logger.warn(
  "`--global`, `--local` are deprecated.",
  {
    reason: "I'm telling you anyway."
  }
)

// error & fatal
const error = new Error("I don't know what happened")
logger.error(error, "This error was not my fault!")

try {
  (function shake() {shake()})()
} catch (earthquakeError) {
  logger.fatal(earthquakeError, "EARTHQUAKE DETECTED! STOPPING PROGRAM...")
}

Setting the log level — you can think of it as "filtering" levels.

const { LogLevel } = require("moologger")

const logger = new MooLogger({
  /*
    {
      DISABLED: 0,
      FATAL: 1,
      ERROR: 2,
      WARN: 3,
      INFO: 4,
      DEBUG: 5
    }
  */

  logLevel: LogLevel.WARN
  // levels below WARN (INFO, DEBUG) won't be logged
})

logger.warn("Hello!") // logged
logger.fatal("ANOTHER EARTHQUAKE!") // logged
logger.info("Paid taxes") // not logged

You can set the badge text that corresponds to the log level.

If a field is not set, it'll be replaced with the default one.

const lang = {
  /* It's just like i18n */
  debug: "Bug Killer",
  info: "πληροφορίες",
  warn: "uyarı",
  error: "ข้อผิดพลาด",
  fatal: "致命的な誤り"
}

new MooLogger({ lang }) // register it

As the name implies, a log folder (directory) stores logs from MooLogger. Log files are named as the current timestamp.

If not set, MooLogger will disable this feature.

new MooLogger({
  logFolder: "path/to/dir"
})

If you prefer logging into one fixed (singular) file, use logFile instead.

Same as logFolder, MooLogger will disable this feature if not set.

new MooLogger({
  logFile: "my.log"
})

Note that DO NOT set logFolder and logFile at the same time, you have to choose between them. Life is so cruel!

Keywords

logger

FAQs

Package last updated on 27 Aug 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts