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

@fontanus/logger

v1.5.18

Published

Logger service

Downloads

3

Readme

Usage

The logger implements the loglevel API

  • logger.info(msg: string, data?: any)
  • logger.debug(msg: string, data?: any)
  • logger.warn(msg: string, data?: any)
  • logger.error(msg: string, data?: any)
  • logger.trace(msg: string, data?: any)
  • logger.setLevel(msg: string, data?: any)
  • logger.getLoggers(msg: string, data?: any)
  • logger.getLogger(msg: string, data?: any)

Logger adds the following features:

  • using a the URL search string lr switches on remote logging, saved in the SessionStorage
  • using the URL search string ll=LOGLEVEL sets all log levels to LOGLEVEL
  • using the URL search string lc passes an initial context, mostly used in iframes
  • creates window.logger=loglevel
  • logger.setupLogger: The remote log url can be set by calling logger.setupLogger(url, defaultLogger="default", logContextGetter=false)
  • logger.getSetupString: returns a query string to be passed on into iframes

Extra API methods

logger.setupLogger

setupLogger(url, defaultLogger="default", logContextGetter=false) is used set up remote logging.

  • defaultLogger- string, specifies the loggerName for the default logger of loglevel. e.g: com-webapp. You can start new loggers using logget.getLogger("mylogger"). A recommended logger naming convention is to use defaultLogger.myLogger for custom loggers.
  • logContextGetter - function or false, takes a function that returns extra data to be passed as context for the log message. By default no context is passed with the log message. If loglevel.<method> is called with a second data attribute that has a context key, then the logContextGetter is ignored and data.context is passed on as the log context.

logger.getSetupString

logger.getSetupString() is used to retrieve the current logger settings as a search query url.

The primary usecase of getSetupString is to pass it to an iframe to retain the same remote logging and loglevel settings that the main frame has.

Example

import * as log from "@nagyv/logger"

log.setupLogger('https://www.example.com', 'example-logs', () => ({hello: 'world'}))
log.warn('A warning')
/*
posts the following to https://www.example.com when remote logging is enabled:
{
  'message': 'A warning',
  'loggerName': 'example-logs',
  'context': {
    'hello': 'world'
  }
}
*/

log.warn('A warning', {context: 'mycontext'})
/*
posts the following to https://www.example.com when remote logging is enabled:
{
  'message': 'A warning',
  'loggerName': 'example-logs',
  'context': 'mycontext',
  'data': {'context': 'mycontext'}
}
*/

const otherLog = log.getLogger('otherLog')
log.warn('A warning')
/*
posts the following to https://www.example.com when remote logging is enabled:
{
  'message': 'A warning',
  'loggerName': 'otherLog',
  'context': {
    'hello': 'world'
  }
}
*/