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

@gholk/tt-logger

v0.3.1

Published

Tag and Template literal Logger

Downloads

7

Readme

Tag Template literal Logger

A Logger let you name every log and turn it on or off, and provides a confortable template literal logging syntax.

import {log, ttLogger, TtLogger} from 'tt-logger'

log `debug a debug message`
// [debug] a debug message

ttLogger.exclude `debug argv argv-length`

log `debug this will not show`

const argv = process.argv

// no show too
log `argv ${argv}`
log `argv-length ${argv.length}`

// this do show
log `first-arg ${argv[2]}`

ttLogger.include `argv argv-length`

// these will show
log `argv ${argv}`
log `argv-length ${argv.length}`

multiple line log

// multi-line
log `some-line ${argv.join('\n')}`
// [some-line]
// /usr/bin/node
// /path/to/file.js
// ...
// [/some-line]

log `some-line-2 literal
literal line 2`
// [some-line-2]
// literal
// literal line 2
// [/some-line-2]

normal function version

const log = ttLogger.bind('log')
log('debug', 'a debug message')
// [debug] a debug message

ttLogger.excludeTag('debug')
ttLogger.excludeTag('argv')
ttLogger.excludeTag('argv-length')

log(`debug`, `this will not show`)

const argv = process.argv

// no show too
log(`argv`, argv)
log(`argv-length`, argv.length)

// this do show
log(`first-arg`, argv[2])

ttLogger.includeTag(`argv`)
ttLogger.includeTag('argv-length')

// these will show
log(`argv`, argv)
log(`argv-length`, argv.length)

Tag

A tag is a string excluding [].*+? character. In Template Literal log, the string before the first space is the tag. In function version log, first argument is tag.

All tags are enabled by default.

ttLogger.bind

ttLogger.bind('x') is same to ttLogger['x'].bind(ttLogger). ttLogger.bind(func) is same to func.bind(ttLogger).

lazy evaluation

const ttl = ttLogger
ttl.exclude `skip`

// expensiveWork will not execute
log `skip ${_=>expensiveWork()}`

log `no-skip ${_=>'this will get execute'}`

The variable _ can be any other values. The callback will called without argument.

Function version lazy: ttl.log('skip', x=>expensiveWork()).

dynamic tag name

variable expantion in tag name is supported.

let myTag = 'my-tag'

log `${myTag} my tag log`
// [my-tag] my tag log

log `${myTag}-debug my tag debug`
// [my-tag-debug] my tag debug

the tag name can not be lazy evaluation, this make no sense.

log `${()=>'my-tag'} this will not work`
// throw a error

install

download the index.js and import it with es module syntax. you can git clone it or download the tarball and extract it.

in browser, figure out its url and import it directly in browser if it was served with correct content-type, or download it and put it on your web server.

with npm

download the tarball *.tar.gz or *.tgz from release and npm i tt-logger-*.tgz.

todo

  • support stderr
  • support a default tag
  • tag driven debugging docs
  • built-in excluded tag like debug/verbose?
  • read env
  • how to override exclude in file with env or some what
  • set glob should update existing keymap