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

@searchspring/snap-logger

v0.61.5

Published

Snap Logger

Downloads

13,685

Readme

Snap Logger

Simple logger for debugging

logger.image({
	url: 'https://searchspring.com/wp-content/uploads/2020/01/SearchSpring-Primary-FullColor-800-1-1-640x208.png',
	width: '90px',
	height: '30px'
});

logger.error('error');

logger.warn('warn');

logger.imageText({
	url: 'https://searchspring.com/wp-content/themes/SearchSpring-Theme/dist/images/favicons/favicon.svg',
}, 'imageText');

logger.debug('debug');

logger.dev(`%c ${logger.emoji.vortex} %c${logger.prefix}%c${'magical text'}`,
`color: ${logger.colors.blue}; font-weight: bold; font-size: 10px; line-height: 12px;`,
`color: ${logger.colors.bluegreen}; font-weight: normal;`,
`color: ${logger.colors.bluegreen}; font-weight: bold;`);

Dependency

Snap Logger is a dependency of @searchspring/snap-controller

Installation

npm install --save @searchspring/snap-logger

Import

import { Logger } from '@searchspring/snap-logger';

Config

Snap Logger accepts an optional string prefix which when set is prepended to all logs.

const prefix = 'Log:';
const logger = new Logger(prefix)

Controller usage

Snap Logger is a dependency of Snap Controller and it is recommended to use logging methods of the controller in place of console methods.

Standalone usage

const logger = new Logger();

logger.warn('this is a warning');

setNamespace method

Sets prefix instead of defining a prefix in the constructor.

const logger = new Logger();

logger.warn('Hello');
// 'Hello'

logger.setNamespace('search');

logger.warn('Hello');
// ' [search] :: Hello'

setMode method

The default logging mode is production.

When set to production, logs using dev will not be visible. This also includes image, imageText, debug, and profile.

When set to development, all logging methods will be visible.

import { Logger, LogMode } from '@searchspring/snap-logger';

const logger = new Logger();
logger.setMode(LogMode.DEVELOPMENT);
enum LogMode {
	PRODUCTION = 'production',
	DEVELOPMENT = 'development',
}

error method

This method takes any number of parameters and logs them to the console. It is best to use this method for error handling.

logger.error('error!!!');
logger.error('text about the error', errorObject, 'more', 'text');

warn method

This method takes any number of parameters and logs them to the console. It is best to use this method for displaying warnings.

logger.warn('warning!!!');
logger.warn('warning', warningObject, 'more text');

dev method

This method takes any number of parameters and logs them to the console. If mode is set to LogMode.PRODUCTION, the dev logs will not be displayed.

logger.dev('dev')

debug method

This method takes any number of parameters and logs them to the console. If mode is set to LogMode.PRODUCTION, debug logs will not be displayed.

logger.debug('debug');

image method

This method takes any number of parameters and logs them to the console. The first parameter is special and takes properties that specify the image details. If mode is set to LogMode.PRODUCTION, image logs will not be displayed.

logger.image({ 
		url: 'https://searchspring.com/wp-content/uploads/2020/01/SearchSpring-Primary-FullColor-800-1-1-640x208.png',
		width: '30px', 
		height: '30px'
});

imageText method

This method takes any number of parameters and logs them to the console. The first parameter is special and takes properties that specify the image details. If mode is set to LogMode.PRODUCTION, imageText logs will not be displayed.

logger.imageText({
	url: 'https://searchspring.com/wp-content/uploads/2020/01/SearchSpring-Primary-FullColor-800-1-1-640x208.png',
	text: `imageText`,
	style: `color: #4c3ce2; font-weight: bold;`,
});

profile method

This method takes any number of parameters and logs them to the console. The first parameter is special and takes a Snap profile. If mode is set to LogMode.PRODUCTION, profile logs will not be displayed.

See @searchspring/snap-profiler

import { Profiler } from '@searchspring/snap-profiler';
import { Logger } from '@searchspring/snap-logger';

const logger = new Logger();
const profiler = new Profiler();

const searchProfile = profiler.create({ 
	type: 'event', 
	name: 'search', 
	context: {} 
});

searchProfile.start();

// code to profile

searchProfile.stop();

logger.profile(searchProfile)

emoji property

The emoji property contains various emojis that can be used

The following emojis are available:

const emoji = {
	bang: String.fromCodePoint(0x203c),
	bright: String.fromCodePoint(0x1f506),
	check: String.fromCodePoint(0x2714),
	clock: String.fromCodePoint(0x1f556),
	cloud: String.fromCodePoint(0x2601),
	dim: String.fromCodePoint(0x1f505),
	gear: String.fromCodePoint(0x2699),
	interobang: String.fromCodePoint(0x2049),
	lightning: String.fromCodePoint(0x26a1),
	magic: String.fromCodePoint(0x2728),
	rocket: String.fromCodePoint(0x1f680),
	search: String.fromCodePoint(0x1f50d),
	snap: String.fromCodePoint(0x1f4a5),
	ufo: String.fromCodePoint(0x1f6f8),
	vortex: String.fromCodePoint(0x1f300),
	warning: String.fromCodePoint(0x26a0),
};

colors property

The colors property contains various colors that can be used

The following colors are available:

const colors = {
	blue: '#3379c1',
	bluelight: '#688BA3',
	bluedark: '#1B3141',
	bluegreen: '#318495',

	grey: '#61717B',

	green: '#507B43',
	greendark: '#63715F',
	greenblue: '#46927D',

	indigo: '#4c3ce2',

	orange: '#ecaa15',
	orangelight: '#ff6600',
	orangedark: '#c59600',

	red: '#cc1212',
	redlight: '#f30707',
	reddark: '#8E111C',

	yellow: '#d1d432',
};