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

quark-log

v1.2.1

Published

Simple configurable logging module

Downloads

36

Readme

build status stability npm version js-standard-style semantic-release

Simple configurable logging module.

This package is part of quark framework but it can be used independently.

Preview

Features

  • Levels : Defaults (log, info, warn, error) and custom
  • Plugins : Defaults and custom
  • Styling : Per level/plugin
  • More : Timer, group, reset...

Installation

NPM

npm install quark-log --save

Usage

Basic

import { Logger } from 'quark-log'

const logger = new Logger()

logger.log('Test')
logger.log('Test', { test: true })
logger.log('Test', 10, true)

Enable/disable logging

import { Logger } from 'quark-log'

const logger = new Logger()

logger.off()
logger.log('This test will not be logged')
logger.on()

Grouping

import { Logger } from 'quark-log'

const logger = new Logger()

logger.group('Group')
logger.log('Test grouping')
logger.groupEnd()

Timer

import { Logger } from 'quark-log'

const logger = new Logger()

logger.time('timer')
// ...
logger.timeEnd('timer')

Handler

import { Logger } from 'quark-log'

const logger = new Logger()

logger.setHandler(msgs => {
  // msgs = ['Test', true]
})

logger.log('Test', true)

Reset

Reset levels and plugins.

import { Logger, plugins } from 'quark-log'

const logger = new Logger()
logger.plugin('time', plugins.time)

logger.log('Test') // [15:00:00] Test
logger.reset()
logger.log('Test') // Test

Line break

import { Logger } from 'quark-log'

const logger = new Logger()
logger.br()

Levels

Defaults levels

import { Logger } from 'quark-log'

const logger = new Logger()
logger.log('Log')
logger.info('Info')
logger.warn('Warn')
logger.error('Error')

Add a custom level

import { Logger } from 'quark-log'

const logger = new Logger()
logger.level('custom')

logger.custom('My custom level')

Configure level options

import { Logger } from 'quark-log'

const logger = new Logger()
logger.level('custom', {
  styles: {
    color: 'blue'
  }
})

logger.custom('Test') // Will be logged in blue

Plugins

Defaults plugins list

  • time : Append current time before user message
  • namespace : Append a custom namespace before user message

Use a default plugin

import { Logger, plugins } from 'quark-log'

const logger = new Logger()
logger.plugin('time', plugins.time)

logger.log('Test') // [15:00:00] Test

Configure plugin options

import { Logger, plugins } from 'quark-log'

const logger = new Logger()
logger.plugin('namespace', plugins.namespace, { name: 'test' })
logger.log('Test') // [test] Test

logger.plugin('namespace', { enabled: false })
logger.log('Test') // Test

Create a custom plugin

import { Logger } from 'quark-log'

/**
 * Plugin callback signature
 * 
 * @param {Array} msgs User messages
 * @param {Object} options Plugin options
 * @param {Object} level Level
 * @param {String} level.name Level name
 * @param {Object} level.options Level options
 */
const myPlugin = (msgs, options, level) => {
  return { before: `${options.myOption}:`, msgs, after: '', styles: {} }
}

const logger = new Logger()
logger.plugin('myPlugin', myPlugin, { myOption: 'My plugin' }) // This plugin append a custom string before each message

logger.log('Test') // My plugin: Test

API

See https://fm-ph.github.io/quark-log/

Build

To build the sources with babel in ./lib directory :

npm run build

Documentation

To generate the JSDoc :

npm run docs

To generate the documentation and deploy on gh-pages branch :

npm run docs:deploy

To serve the JSDoc :

npm run docs:serve

Testing

To run the tests, first clone the repository and install its dependencies :

git clone https://github.com/fm_ph/quark-log.git
cd quark-log
npm install

Then, run the tests :

npm test

To watch (test-driven development) :

npm run test:watch

For coverage :

npm run test:coverage

License

MIT License © Patrick Heng Fabien Motte