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

bj-logger

v1.0.1

Published

A simple logger which can support multiple transports and log levels.

Readme

BJ Logger

A centralized logger for Node.js applications. This package provides a simple way to log messages to CloudWatch Logs, as well as to a file. It also supports multiple transports, allowing you to log to multiple destinations.

Installation

To install the package, run the following command:

npm install bj-logger

Usage

Basic Usage

To use the package, you need to create an instance of the Logger class and pass in the service name and any transports you want to use. Here's an example:

import { Logger, ConsoleTransport, CloudWatchTransport } from 'bj-logger'

const logger = new Logger('MyService', [
    new ConsoleTransport(),
    new CloudWatchTransport({
        region: process.env.AWS_REGION,
        accessKeyId: process.env.AWS_ACCESS_KEY_ID,
        secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
        logGroupName: 'MyLogGroup',
        logStreamName: 'MyLogStream'
    })
])

logger.info('This is a log message')

In this example, we're creating a Logger instance with the service name "MyService". We're also passing in two transports: a ConsoleTransport and a CloudWatchTransport. The ConsoleTransport logs to the console, while the CloudWatchTransport logs to CloudWatch Logs.

Logging to a File

You can also log to a file by creating a FileTransport and passing in the path to the log file. Here's an example:

import { Logger, FileTransport } from 'bj-logger'

const logger = new Logger('MyService', [new FileTransport('log/app.log')])

logger.info('This is a log message')

In this example, we're creating a Logger instance with the service name "MyService". We're also passing in a FileTransport that logs to a file named "app.log" in the "log" directory.

Logging to Multiple Transports

You can log to multiple transports by passing in an array of transports to the Logger constructor. Here's an example:

import { Logger, ConsoleTransport, CloudWatchTransport, FileTransport } from 'bj-logger'

const logger = new Logger('MyService', [
    new ConsoleTransport(),
    new CloudWatchTransport({
        region: process.env.AWS_REGION,
        accessKeyId: process.env.AWS_ACCESS_KEY_ID,
        secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
        logGroupName: 'MyLogGroup',
        logStreamName: 'MyLogStream'
    }),
    new FileTransport('log/app.log')
])

logger.info('This is a log message')

In this example, we're creating a Logger instance with the service name "MyService". We're also passing in three transports: a ConsoleTransport, a CloudWatchTransport, and a FileTransport. The ConsoleTransport logs to the console, the CloudWatchTransport logs to CloudWatch Logs, and the FileTransport logs to a file named "app.log" in the "log" directory.

Logging with Structured Data

You can log structured data by passing in an object with the message, service, traceId, timestamp, and body properties to the Logger constructor. Here's an example:

import { Logger, ConsoleTransport, CloudWatchTransport, FileTransport } from 'bj-logger'

const logger = new Logger('MyService', [
    new ConsoleTransport(),
    new CloudWatchTransport({
        region: process.env.AWS_REGION,
        accessKeyId: process.env.AWS_ACCESS_KEY_ID,
        secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
        logGroupName: 'MyLogGroup',
        logStreamName: 'MyLogStream'
    }),
    new FileTransport('log/app.log')
])

logger.info({
    message: 'This is a log message',
    service: 'MyService',
    traceId: '12345678-1234-1234-1234-123456789012',
    timestamp: new Date().toISOString(),
    body: {
        key1: 'value1',
        key2: 'value2'
    }
})

In this example, we're creating a Logger instance with the service name "MyService". We're also passing in three transports: a ConsoleTransport, a CloudWatchTransport, and a FileTransport. The ConsoleTransport logs to the console, the CloudWatchTransport logs to CloudWatch Logs, and the FileTransport logs to a file named "app.log" in the "log" directory.

Logging with Custom Levels

You can log with custom levels by passing in a string or an object with the level property to the Logger constructor. Here's an example:

import { Logger, ConsoleTransport, CloudWatchTransport, FileTransport } from 'bj-logger'

const logger = new Logger('MyService', [
    new ConsoleTransport(),
    new CloudWatchTransport({
        region: process.env.AWS_REGION,
        accessKeyId: process.env.AWS_ACCESS_KEY_ID,
        secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
        logGroupName: 'MyLogGroup',
        logStreamName: 'MyLogStream'
    }),
    new FileTransport('log/app.log')
])

logger.info('This is a log message')
logger.warn('This is a warning message')
logger.error('This is an error message')

In this example, we're creating a Logger instance with the service name "MyService". We're also passing in three transports: a ConsoleTransport, a CloudWatchTransport, and a FileTransport. The ConsoleTransport logs to the console, the CloudWatchTransport logs to CloudWatch Logs, and the FileTransport logs to a file named "app.log" in the "log" directory.

The Logger instance has methods for logging at different log levels, such as info, warn, and error. Each method takes a string or an object as its argument. If you pass a string, it will be treated as the message to log. If you pass an object, it will be treated as the log entry.