npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@novigi/logger

v1.0.0-0

Published

Simple and minimalist logger for Node.js applications 🪵

Downloads

19

Readme

npm (scoped) NPM Statements Branches Functions Lines

@novigi/logger

Simple and minimalist logger for Node.js applications 🪵

🐿 Features

  • Supports log message templating → 'Hi ${name}!'
  • Color enabled log messages on terminal
  • Standard log levels → INFO, WARN, ERROR, DEBUG and TRACE
  • Append log lines to file or to a callback function

📦 Getting Started

  1. Install the dependency
npm install @novigi/logger
  1. Import the library
const lib = require('@novigi/logger');

📖 Documentation

logger

This library contains a collection of standard logging helper methods including logger.info,logger.error etc.

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

logger.setLevel(level)

Using to set the loglevel to describe which message level will be logged by the relevant logger to standard output.

Kind: static method of logger

| Param | Type | Description | | --- | --- | --- | | level | string | required log level TRACE, DEBUG, INFO, WARN, ERROR or SILENT |

Example

logger.setLevel('DEBUG')

logger.setCallback(cb)

Sets a callback function to call for each log line. This can use to redirect log messages to another destination (i.e., to a custom file). Passing a falsy value to the method will reset the callback.

Kind: static method of logger

| Param | Type | Description | | --- | --- | --- | | cb | function | When a new log line appends callback function will invoke. |

Example

logger.setCallback((line) => { appendToCustomFile(line) })   // appending lines to custom method
logger.setCallback(null)                                     // reset the callback

logger.setColors(flag)

Sets log color preference to standard output

Kind: static method of logger

| Param | Type | Description | | --- | --- | --- | | flag | boolean | required log color setting |

Example

logger.setColors(false) // disable printing logs with colors
logger.setColors(true)  // enable printing logs with colors

logger.setLogPath(path)

Sets log path to append log lines to a file

Kind: static method of logger

| Param | Type | Description | | --- | --- | --- | | path | string | required log file path |

Example

logger.setLogPath('path/to/file.log')
logger.setLogPath(null)                 // Stop printing to a file

logger.info([...messages], context)

Log message at info level

Kind: static method of logger

| Param | Type | Description | | --- | --- | --- | | [...messages] | string | object | message arguments list accepts any number of log message strings and expects the last argument to be context object. If there are multiple log messages passed as arguments, method joins them with a space. | | context | object | context variables for the templated messages |

Example

var context = { ans: 'A', name: 'Timmy' }
logger.info('log message')                             // 2022-10-17 13:19:34.568 - INFO - log message
logger.info('Hi ${name}!', context)                    // 2022-10-17 13:19:34.568 - INFO - Hi Timmy!
logger.info('Answer: ${ans}.', 'Yes ${ans}!', context) // 2022-10-17 13:19:34.568 - INFO - Correct: A. Yes A!

logger.error([...messages], context)

Log message at error level

Kind: static method of logger

| Param | Type | Description | | --- | --- | --- | | [...messages] | string | object | message arguments list accepts any number of log message strings and expects the last argument to be context object. If there are multiple log messages passed as arguments, method joins them with a space. | | context | object | context variables for the templated messages |

Example

var context = { ans: 'A', name: 'Timmy' }
logger.error('log message')                             // 2022-10-17 13:19:34.568 - ERROR - log message
logger.error('Hi ${name}!', context)                    // 2022-10-17 13:19:34.568 - ERROR - Hi Timmy!
logger.error('Answer: ${ans}.', 'Yes ${ans}!', context) // 2022-10-17 13:19:34.568 - ERROR - Correct: A. Yes A!

logger.debug([...messages], context)

Log message at debug level

Kind: static method of logger

| Param | Type | Description | | --- | --- | --- | | [...messages] | string | object | message arguments list accepts any number of log message strings and expects the last argument to be context object. If there are multiple log messages passed as arguments, method joins them with a space. | | context | object | context variables for the templated messages |

Example

var context = { ans: 'A', name: 'Timmy' }
logger.debug('log message')                             // 2022-10-17 13:19:34.568 - DEBUG - log message
logger.debug('Hi ${name}!', context)                    // 2022-10-17 13:19:34.568 - DEBUG - Hi Timmy!
logger.debug('Answer: ${ans}.', 'Yes ${ans}!', context) // 2022-10-17 13:19:34.568 - DEBUG - Correct: A. Yes A!

logger.trace([...messages], context)

Log message at trace level

Kind: static method of logger

| Param | Type | Description | | --- | --- | --- | | [...messages] | string | object | message arguments list accepts any number of log message strings and expects the last argument to be context object. If there are multiple log messages passed as arguments, method joins them with a space. | | context | object | context variables for the templated messages |

Example

var context = { ans: 'A', name: 'Timmy' }
logger.trace('log message')                             // 2022-10-17 13:19:34.568 - TRACE - log message
logger.trace('Hi ${name}!', context)                    // 2022-10-17 13:19:34.568 - TRACE - Hi Timmy!
logger.trace('Answer: ${ans}.', 'Yes ${ans}!', context) // 2022-10-17 13:19:34.568 - TRACE - Correct: A. Yes A!

This is an auto generated file. Please don't make changes manually