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

pelias-mock-logger

v1.7.0

Published

Mock logger for testing logging behavior in Pelias projects

Downloads

1,895

Readme

Pelias Mock Logger

Greenkeeper badge

Travis CI Status

This module is used for testing logging events in Pelias projects. proxyquire is the supported module for overriding dependencies in which this module is used.

Installation

$ npm install pelias-mock-logger --save-dev

NPM

NPM Module

The pelias-mock-logger npm module can be found here:

https://npmjs.org/package/pelias-mock-logger

Usage

Traditionally, testing logging events required quite a bit of setup with proxyquire:

const errorMessages = [];

var service = proxyquire('../../../service/interpolation', {
  'pelias-logger': {
    get: () => {
      return {
        error: (msg) => { errorMessages.push(msg); },
        info: (msg) => {}
      };
    }
  }
}).search();

t.deepEquals(errorMessages, ['RequireTransport: failed to connect to interpolation service']);

Using the pelias-mock-logger module, this code can be shortened to:

const logger = require('pelias-mock-logger')();

var adapter = proxyquire('../../../service/interpolation', {
  'pelias-logger': logger
}).search();

t.deepEquals(logger.getErrorMessages(), ['RequireTransport: failed to connect to interpolation service']);

Functions

  • logging events
    • error(msg)
    • warn(msg)
    • info(msg)
    • verbose(msg)
    • debug(msg)
    • silly(msg)
  • getLayer(): returns the value passed to .get() in require( 'pelias-logger' ).get( 'api' )
  • getLevels(): returns the supported logging levels: error, warn, info, verbose, debug, and silly
  • getMessages(level, pattern): returns all messages logged at a level, optionally matching a pattern
    • Examples:
      • getMessages('error')
      • getMessages('error', /backend error occurred/)
  • hasMessages(level, pattern): returns whether messages were logged at a level, optionally matching a pattern
    • Examples:
      • hasMessages('error')
      • hasMessages('error', /backend error occurred/)
  • isMessage(level, pattern): returns whether the supplied pattern matches or is equal to any messages logged at the specified level
    • Examples
      • isMessage('error', /backend error occurred)
      • isMessage('error', 'a backend error occurred, contact the Pelias team for assistance')
  • level-specific functions
    • getMessages: returns all messages logged at the level specified in function name, optionally matching a pattern
      • getErrorMessages(pattern)
      • getWarnMessages(pattern)
      • getInfoMessages(pattern)
      • getVerboseMessages(pattern)
      • getDebugMessages(pattern)
      • getSillyMessages(pattern)
    • hasMessages: returns whether messages were logged at the level specified in function name, optionally matching a pattern
      • hasErrorMessages(pattern)
      • hasWarnMessages(pattern)
      • hasInfoMessages(pattern)
      • hasVerboseMessages(pattern)
      • hasDebugMessages(pattern)
      • hasSillyMessages(pattern)
    • isMessage: returns whether the supplied pattern matches or is equal to any messages logged at the level specified in the function name
      • isErrorMessages(pattern)
      • isWarnMessages(pattern)
      • isInfoMessages(pattern)
      • isVerboseMessages(pattern)
      • isDebugMessages(pattern)
      • isSillyMessages(pattern)

Contributing

Please fork and pull request against upstream master on a feature branch.

Provide unit tests in the test directory.

Running Unit Tests

$ npm test