Giter VIP home page Giter VIP logo

js-logger's Introduction

js-logger

A stupidly simple, console-only logger with message timestamping, configurable identity, and standard syslog-inspired logging levels.

To use it, require the library and call the functions on the exported object:

const logger = require('@niftylogic/logger');

logger.show('all')
      .as('an-example');

logger.debug('this is a debug message');
logger.info('this is an info message');
logger.warn('this is a warning message');
logger.error('this is an error message');
logger.info('here is an %O', {ob:'ject'});

The above outputs:

[2022-07-23T19:26:29.700Z] an-example | DEBUG | this is a debug message
[2022-07-23T19:26:29.702Z] an-example | INFO  | this is an info message
[2022-07-23T19:26:29.702Z] an-example | WARN  | this is a warning message
[2022-07-23T19:26:29.702Z] an-example | ERROR | this is an error message
[2022-07-23T19:26:29.702Z] an-example | INFO  | here is an { ob: 'ject' }

The log format uses util.format() under the hood, so you can use standard(-ish) %-style format specifiers, like sprintf and friends.

All methods can be chained, primarily so that you can do this:

logger.show('warnings')
      .as('my-program');

Environmental configuration is strongly encouraged, but not provided directly by the library. Here's an idea to get you started:

logger.show(process.env.LOG_LEVEL)
      .as(process.env.LOG_IDENTITY);

You can also use the as() function to include build numbers and such, probably sourced from your CI pipelines:

const { version } = require('./version.json');
logger.show(process.env.LOG_LEVEL)
      .as(`my-program/${version}`);

Happy Hacking!

js-logger's People

Contributors

jhunt avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.