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

@launchquest/log

v1.0.1

Published

Structured, colourful, and configurable logging library

Downloads

31

Readme

@launchquest/log

License: LQL 1.0 NPM Version NPM Downloads

@launchquest/log is a customizable logging library for Node.js, designed to provide a structured, colorful, and configurable logging experience. It supports multiple log levels and customizable options to fit various logging needs.

Preview

This project is brought to you by Launch Quest.

Installation

To install @launchquest/log, run:

npm install @launchquest/log

Basic Usage

To use @launchquest/log, first import it into your project:

import { @launchquest/log } from '@launchquest/log'

const log = new @launchquest/log()
log.info('This is an informational message')
log.warn('This is a warning message')
log.error('This is an error message')

Log Levels

@launchquest/log supports six log levels, each with its own label and color:

  • trace: TRC (gray background)
  • debug: DBG (white background)
  • info: INF (blue background)
  • warn: WRN (yellow background)
  • error: ERR (red background)
  • fatal: FTL (red background, bold text, triggers process.exit by default)
log.trace('This is a trace message')
log.debug('This is a debug message')
log.info('This is an informational message')
log.warn('This is a warning message')
log.error('This is an error message')
log.fatal('This is a fatal error message')

Customization Options

When creating a new @launchquest/log instance, you can customize various options:

  • name: A name to prefix all log messages (default: '')
  • timestamp: The timestamp format (default: 'HH:mm:ss.SSS')
  • logLevel: The minimum log level to display (default: 'info')
  • exitOnFatal: Whether to exit the process on a fatal error (default: true)
const log = new @launchquest/log({
  name: 'myApp',
  timestamp: 'YYYY-MM-DD HH:mm:ss',
  logLevel: 'debug',
  exitOnFatal: false
})

log.info('This is an informational message with custom settings')

Named Loggers

You can create named child loggers using the extend method:

const log = new @launchquest/log({ name: 'app' })
const dbLog = log.extend('database')

dbLog.info('Database connected')
log.info('App started')

Output:

09:44:32.010 INF [app:database] Database connected
09:44:32.010 INF [app] App started

Full Example

Here’s a complete example showcasing various features:

import { @launchquest/log } from '@launchquest/log'

const log = new @launchquest/log({
  name: 'myService',
  timestamp: 'HH:mm:ss.SSS',
  logLevel: 'trace',
  exitOnFatal: true
})

log.trace('Initialized')

log.info('This is a string test', 'Hello, world!')
log.info('This is a number test', 42)
log.info('This is a boolean test', true)
log.info('This is a null test', null)
log.info('This is an undefined test', undefined)
log.info('This is a function test', () => {})
log.info('This is an array test', [1, 2, 3])
log.info('This is an object test', { a: 1, b: 'two', c: [3, 4, 5], d: { e: 6, f: 7 } })

const authLog = log.extend('auth')
authLog.debug('User login attempt')

const dbLog = log.extend('database')
dbLog.info('Database connected')

This will output:

10:07:09.766 TRC [myService] Initialized
10:07:09.767 INF [myService] This is a string test Hello, world!
10:07:09.767 INF [myService] This is a number test 42
10:07:09.767 INF [myService] This is a boolean test true
10:07:09.767 INF [myService] This is a null test null
10:07:09.767 INF [myService] This is an undefined test undefined
10:07:09.767 INF [myService] This is a function test [Function (anonymous)]
10:07:09.768 INF [myService] This is an array test [ 1, 2, 3 ]
10:07:09.768 INF [myService] This is an object test { a: 1, b: 'two', c: [ 3, 4, 5 ], d: { e: 6, f: 7 } }
10:07:09.768 DBG [myService:auth] User login attempt
10:07:09.768 INF [myService:database] Database connected
10:07:09.768 WRN [myService] uh oh
10:07:09.768 ERR [myService] aaahhh
10:07:09.768 FTL [myService] goodbye cruel world

License

This project is licensed under the LQL-1.0 License. See the LICENSE file for details.