Skip to content

hankadler/mjs-loguno

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

loguno

Log beautiful messages easily.

npm-version npm-downloads

Features:

  • Simple design: one Logger (uno!), many outlets (no need to instantiate anything!)

  • Stack traces shown in the tree format our brain expects

  • Method names follow the sane convention of specifying an action, i.e. logInfo (verb ➡️ function) and NOT info (noun ➡️ property)

  • Default colors work on dark & light consoles alike

    colors-vs-console

👎? Please tell me why.

❤️? I'd relish an expresso ☕!

Table of Contents

Setup

npm i loguno

⚠️ loguno is an ES package. It only works on projects whose package.json specify the "type": "module" property.

Examples

import Logger from "loguno"; // Logger has one outlet by default; stdout

Logger.logTrace("Shows intuitive stacktrace.");
Logger.logDebug("Standard six logging levels included: TRACE, DEBUG, INFO, WARN, ERROR, FATAL");
Logger.logInfo("Logger has one important property: `outlets`, an array of output config objects.");
Logger.logWarn("`Logger.outlets[0].threshold` is determined by `NODE_ENV`.");
Logger.logInfo("Thus TRACE, DEBUG & INFO are only visible if process.NODE_ENV != 'production'.");

// let's hide TRACE, DEBUG and INFO from stdout...
Logger.outlets[0].threshold = Logger.LEVELS.WARN;

// and let's add another all-inclusive outlet pointing to file 'demo.log'
Logger.addOutlet("demo.log", {
  isExclusive: false, // so it receives messages originating from modules other than this one
  threshold: Logger.LEVELS.TRACE, // so it shows all messages
  template: Logger.TEMPLATES.dlnm // so format -> {duration} {level} {name} : {message}
});

Logger.logError(
  "Logs to both stdout and 'demo.log', but given threshold settings, only 'demo.log' shows trace."
);

Logger.logFatal("Highest level message. Terminates the process.");
  • stdout

    stdout

More Examples

git clone https://github.com/hankadler/js-loguno loguno

npm i

# so node works fine with ES modules, consider adding to ~/.bashrc
export NODE_OPTIONS='--experimental-specifier-resolution=node'
export NODE_NO_WARNINGS='1'

basic-logging

  • stdout

    stdout

  • basic.log

    file

change-colors

  • stdout

    stdout

    stdout

complex-logging

  • stdout

    stdout

  • app.log

    stdout

  • module-a.log

    stdout

  • module-b.log

    stdout

Docs

Logger structure:

logger-structure

Outlet defaults

License

MIT

About

Log beautiful messages easily

Resources

License

Stars

Watchers

Forks

Packages

No packages published