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

@smarterservices/smarter-logging

v1.0.0

Published

Sends logs to BetterStack

Readme

SmarterLogging

Build Status Test Coverage npm version License: ISC Node.js Version Private Package

Unified logging package for back end services that sends logs to BetterStack. This library provides a consistent logging interface across all services with support for different log levels, custom labels, and structured logging.

Installation

npm install @smarterservices/smarter-logging --save

Configuration

The library requires BetterStack credentials to be set as environment variables:

BETTERSTACK_SOURCE_TOKEN=your_source_token
BETTERSTACK_HOST=your_betterstack_host

Usage

Initialization

Before using any logging methods, you must initialize the logger with your application name:

const logging = require('@smarterservices/smarter-logging');

// Initialize with application name
logging.init('MyServiceName');

// Optionally add custom labels
logging.init('MyServiceName', {
  API: 'API',
  AUTH: 'Authentication',
  DB: 'Database'
});

Basic Logging

The library provides four logging levels:

// Error logging
logging.error('AUTH', 'Failed to authenticate user', errorObject);

// Info logging
logging.info('API', 'Request processed successfully', { requestId: '123', duration: 45 });

// Warning logging
logging.warn('DB', 'Database connection slow', { latency: 500 });

// Debug logging (only works in stage environment)
logging.debug('API', 'Processing request', { payload: req.body });

Parameters

All logging methods accept the same parameters:

  1. label (string, optional): A category for the log. If not provided, defaults to 'Generic'.
  2. message (string, required): The main log message.
  3. object (any, optional): Additional data to include with the log. Can be an error object or any JSON-serializable data.

Custom Labels

You can define custom labels during initialization and use them throughout your application:

logging.init('MyServiceName', {
  AUTH: 'Authentication',
  PAYMENT: 'Payment Processing',
  USER: 'User Management'
});

// Later in your code
logging.info('AUTH', 'User logged in successfully');
logging.error('PAYMENT', 'Payment failed', errorObject);

Environment-specific Behavior

  • Debug logs are only sent in the stage environment to prevent cluttering production logs.
  • All logs include the current environment ([production], [stage], etc.) in the message.

Error Handling

The library handles errors internally:

  • If the logger is not initialized, it logs an error to the console.
  • If BetterStack credentials are missing, it logs an error during initialization.
  • If sending a log to BetterStack fails, it logs the error to the console without throwing exceptions.

Testing

To run the tests:

npm test

For test coverage:

npm run test:coverage

Development

Adding New Features

When adding new features, make sure to:

  1. Add appropriate tests in the tests directory
  2. Update this documentation
  3. Follow the existing code style

Running Linting

npm run lint

Code Coverage

This library maintains high test coverage (>94%) to ensure reliability. The coverage badge at the top of this README reflects the current branch coverage. You can generate a detailed coverage report by running:

npm run test:coverage

This will create a coverage report in the coverage directory that you can view in your browser.

Releasing and Versioning

This package follows semantic versioning (SemVer). To release a new version:

  1. Update the version in package.json according to SemVer rules:

    • MAJOR version for incompatible API changes (x.0.0)
    • MINOR version for added functionality in a backward compatible manner (0.x.0)
    • PATCH version for backward compatible bug fixes (0.0.x)
  2. Commit the version change:

    git add package.json
    git commit -m "Bump version to x.y.z"
  3. Create and push a new tag:

    git tag vx.y.z
    git push origin master --tags
  4. The Bitbucket Pipeline will automatically:

    • Run tests to verify the build
    • Publish the new version to the private NPM registry

Note: This package is published as a private NPM package, accessible only to authorized users within the organization.

Badges

The badges at the top of this README provide at-a-glance information about:

  • Build Status: Shows if the latest build on the master branch is passing
  • Test Coverage: Current branch test coverage percentage
  • NPM Version: The latest version published to NPM
  • License: The license under which this package is distributed
  • Node.js Version: Shows the minimum required Node.js version (18+)
  • Private Package: Indicates this is a private NPM package