Socket
Socket
Sign inDemoInstall

@gholk/tt-logger

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@gholk/tt-logger

Tag and Template literal Logger


Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

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

Keywords

FAQs

Package last updated on 18 Jul 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc