1.0.4 • Published 8 months ago

moologger v1.0.4

Weekly downloads
-
License
ISC
Repository
github
Last release
8 months ago

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!

1.0.4

8 months ago

1.0.3

8 months ago

1.0.2

9 months ago

1.0.1

9 months ago

1.0.0

9 months ago