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

@tree-house/logger

v4.0.1

Published

Simple and fast JSON logging library for node.js services.

Downloads

10

Readme

Tree House Logger

Custom NodeJS error classes and definitions with an error parser utility function.

Installation

Install via npm

npm install @tree-house/logger

or via yarn

yarn add @tree-house/logger

Usage

Setup

Service name & version (required for GCP Error Reporting) are determined by:

  1. Environment variables npm_package_name and npm_package_version.
  2. The options passed into the setup function.

The options passed into the setup function will override the values provided by the environment variables (if they were populated to begin with).

To use the setup function to populate name & version of your service, add the following to your startup code before using NSLogger:

import { setup } from '@tree-house/logger';

// NOTE: Name & version should ideally be grabbed from `package.json`
setup({ name: 'my-service', version: '1.2.3' })

Namespaces

You can use this logger with or without namespaces - namespaces help during debugging & are logged to stdout:

import { NSLogger, logger } from '@tree-house/logger';

NSLogger('my-namespace').info('tree house logger');
logger.info('tree house logger');

Debug

You can enable/disable all/some debug logs based on LOG_LEVEL and DEBUG environment variables. If you set LOG_LEVEL to debug (the default), you can use the DEBUG environment variable to enable these based on comma-delimited names.

To skip a specific namespace: DEBUG=*,-not_this To log a specific namespace: DEBUG=this:* To log multiple namespaces: DEBUG=this:*,that:*

Errors

LOG_FORMAT = simple

When LOG_FORMAT environment variable is not set, it defaults to simple. When using simple log format, log messages are outputted on one line, while parameters are outputted on the subsequent lines. This is ideal for a development environment.

LOG_FORMAT = json

When LOG_FORMAT environment variable is set to json, logs are in JSON format. Error log entries are following GCP Error Reporting format. To use it, you must pass an error object while calling .error. You can also provide httpRequest if you are logging an HTTP error:

import { NSLogger } from '@tree-house/logger';

NSlogger('my-namespace').error(
  'tree house logger',
  new Error('Something went wrong'),
  {
    httpRequest: { responseStatusCode: 404, url: 'https://google.com', method: 'GET' },
  },
)

Bugs

When you find issues, please report them:

Be sure to include all of the output from the npm command that didn't work as expected. The npm-debug.log file is also helpful to provide.

Authors

See the list of contributors who participated in this project.

License

This project is licensed under the ISC License - see the LICENSE.md file for details