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

@slipmatio/logger

v0.3.0

Published

Better console logging with TypScript support

Downloads

193

Readme

Better Logger

Easy and lightweight console logging for your JavaScript and TypeScript projects. Control log levels in development vs production, integrate with third-party log tools and debug Vue applications.

Features

  • Log levels that follow and extend browser console log levels
  • success, critical and run methods for more secure and informative logging
  • Nice looking and fully configurable output
  • Custom formatter for Vue
  • Full TypeScript support
  • Good test coverage

Installation

pnpm add @slipmatio/logger

Basic Usage

The easiest way to use this logger is to use the useLogger or useVueLogger helpers. The helpers are configured to print only errors in production and print all but debug messages in development mode unless called with debug=true. You can also set the logger name attribute. Both arguments are optional:

import { useLogger } from '@slipmatio/logger'

const logger = useLogger()

Then just use logger wherever you want:

logger.log('Hello World!')
// > Hello world!

logger.run()
// > 🚀 [main.ts]

Vue Logger

Vue logger uses a special logger function that pretty prints ref, reactive, and computed objects for you so instead of unreadable garble you can read the logs easily.

import { ref, computed } from 'vue'
import { useVueLogger } from '@slipmatio/logger'

const logger = useVueLogger('vuelogger')

const num = ref(1)
const timesTwo = computed(() => num.value * 2)

console.log('proxy objects', num, timesTwo)
// > proxy objects  Object { __v_isShallow: false, dep: undefined, __v_isRef: true, _rawValue: 1, _value: 1 } Object { _setter: setter(), dep: undefined, __v_isRef: true, __v_isReadonly: true, _dirty: true, effect: {…}, _cacheable: true }
logger.log('proxy objects', num, timesTwo)
// > [vuelogger] proxy objects (ref): 1 (computed): 2

Automatic Imports

Tip: use something like unplugin-auto-import with your bundler to automagically import your logger instance wherever you need it.

Setting Up Manually

You can also instantiate and import the logger manually. It works as you'd expect:

import { Logger, LogLevel } from '@slipmatio/logger'

const logger = new Logger({
  // Log levels: DEBUG, INFO, WARN, ERROR, CRITICAL, OFF
  logLevel: process.env.NODE_ENV !== 'production' ? LogLevel.INFO : LogLevel.ERROR,
  name: 'mylogger',
  logFn: myLogFn, // see source for implementation
})

Status

This project was originally born around 2016 and has been copy-pasted in various formats from project to project. As it has been helpful in so many projects, I finally decided to clean it up, convert to TypeScript and release as open source. Some parts of the code are a bit ugly, but it works well enough for most production needs. Contributions welcome!

Elsewhere

Follow @uninen on Twitter