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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@hbkapps/logger

v3.1.4

Published

Here it lies, the great HBK Logger for Node.

Downloads

12

Readme

HBK Logger

Here it lies, the great HBK Logger for Node.

This is a basic logger, extracted out of chartroom-api, that makes it very easy to format logs in a Cloudwatch/ElasticSearch/Kibana-friendly way, as an extension of our logging pipeline.

Usage

The quick copypasta to include the logger is to npm install --save @hbkapps/logger and initialize by requiring the file with

var log = require('@hbkapps/logger')(__filename)

wherever you need a logger.

You can also specify an options object, like so:

var log = require('@hbkapps/logger')({
    nameSpace: __filename,
    printWithColors: false
})

The function takes two arguments. The first, if it is a string, is a module path. The second is an options hash. The options can also be provided as the first and only argument.

Accompanying this module is a requestContext module, which can set the global.CONTEXT variable. Anything contained within the global.CONTEXT module will be logged along with the meta data by the logger.

Features

This module is a trimmed down logger, doing pretty much only the essentials. It can be called by by logger.method(msg, meta), or log.log('method', msg, meta)

Module Path Support

By including the __filename when we include the logger, we get to see exactly what module produced that log. That makes it much easier to trace logs across different module. We automatically drop the current working directory of the running process from this string to make it easier to digest (thus all paths are relative to the server's CWD).

Context Support (e.g. API Gateway/Lambda Support via CLS)

The requestContext module allows to set certain context variables such as AWS request id and user agent. It is a standalone module from logger. And whatever is set in the global.CONTEXT will be included in the log output as context. e.g. userId can be set in globalContext.

Automatic STAGE/NODE_ENV logging

If the STAGE or NODE_ENV environmental variables are set, this module will include them in its output. By default, our Serverless configuration automatically sets the STAGE variable, so this should work OOTB.

N.B: For at least chartroom-api, there is no need to fiddle with the NODE_ENV as it should not be used.

Optional File Logging (not yet implemented)

If there is an logOutputPath in the options, the logs will write to disk at the logOutputPath. Note that this module will not create any necessary directories for you.

Object Logging

Need to log an object? Just pass the option as the second parameter to the logger instance, like so:

log.debug('blah', object)

Log Output Structure

With all options filled, the logger will output JSON that looks something like:

 {
    "timestamp": "1507582665044",
    "message": "blah",
    "meta": {
        "ayy": "lmao",
        "lmao": "ayy",
    },
    "userId": "bneese",
    "modulePath": "@crapi-orm/index.js",
    "stage": "STAGING",
    "apiRequestId": "1010101",
    "lambdaRequestId": "1010101"
  };

This object's structure is also documented on line 46-56 of index.js.

Note again that all falsy values will automatically be trimmed from the output.

Full Environmental Variable Documentation

For now, refer to config.json.