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

@offirmo/practical-logger-browser

v3.1.0

Published

Browser implementation of Offirmo’s practical logger

Downloads

28

Readme

This is a browser implementation of Offirmo’s practical logger.

Demo

TODO codepen

On Firefox:

firefox demo

On Chrome:

firefox demo

On Safari:

firefox demo

On IE11:

TODO

Usage

Important note

This lib may not be what you're looking for! It's a component of the much more complete (and awesome!!) Offirmo’s Universal Debug API (which includes this lib) This lib does just one thing and does it well: logging in the console. However using the full Offirmo’s Universal Debug API will gives you:

  • ability to locally override the log level (through localstorage, optional UI available)
  • singleton loggers (get API instead of create)
  • complementing extra dev features
  • lower bundle size, no need to bundle the full version!! can be injected locally it through a browser extension, Chrome+FF available
  • UI to control the dev features, in the web extension

Check it out!

Killer feature: no visible logs for your customers, but logs can be enabled at run time if needed!

basic usage

If you're really sure you want to use this lib directly:

import { createLogger } from '@offirmo/practical-logger-browser'

const logger = createLogger()
logger.log('hello from logger!')

const fooLogger = createLogger({
	// all params are optional
	name: 'Foo', // default: 'root'. This name is displayed on the log line and can be use for filtering
	suggestedLevel: 'silly' // default: 'error'. Your code is free to suggest a level, but should expect it to be dynamically overriden (see Universal Debug API)
	commonDetails: { channel: 'staging' }, // default: empty. details that'll be merged with all log invocations
	sinkOptions: { sink: ...} // default: empty. options specifically targeted at the sink, usually platform dependent

	// usage not recommended
	forcedLevel: 'silly' // default: undef. use only if you provide your own mechanism for dynamically setting the level
})
fooLogger.log('hello from fooLogger!', { bar: 42, baz: 33 })

sink options

const logger = createLogger({
	name: 'Foo',
	sinkOptions: {
		useCss: false, // default: true. set to false to not use console styling, ex. if cause problem in a new browser version?
		betterGroups: false, // default: true. See below
		explicitBrowser: 'chromium', // default: (undef=auto) use this to force browser detection. Should never be needed.
    }
})
fooLogger.log('hello from fooLogger!', { bar: 42, baz: 33 })

Global magic: groups improvements

Groups are great! However the default behavior is a bit crude. So when the 1st logger is created, it will globally improve the console.group(...)/groupCollapsed(...)/groupEnd() API, in order to bring:

  • errors can't be hidden in a collapsed group (will auto break out to be sure the error is visible)
  • groups won't appear until they have content. Vital to not pollute the console when filtering low-level traces

The drawback: you can't easily reach the call site of a log line anymore. It's a tradeoff.

You can disable this improvement by passing sinkOptions: { betterGroups: false } in the first logger creation.