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

nest-logging-transport

v1.3.0

Published

Custom NestJS logger allowing you to attach custom transports

Downloads

18,772

Readme

Nest-logging-transport

Logger for NestJS framework allowing you to use custom transports (or use predefined ones).

Installation

yarn:

yarn add nest-logging-transport

npm:

npm i nest-logging-transport

Usage

Nest-logging-transport allows you to either define your own transport, or use predefined ones.

Example with predefined transport:

import { NestTransportLogger, DefaultTransportConsole } from 'nest-logging-transport';

const customLogger = new NestTransportLogger({
    transports: [new DefaultTransportConsole()],
});

const bootstrap = async () => {
    const logger = new Logger('Bootstrap');
    const app = await NestFactory.create(ExampleModule, { logger: customLogger });
    logger.log('Application ready');
    [...]
    await app.listen(3334, () => logger.log('Server listening'));
};

From this moment all log calls will be redirected to NestTransportLogger instance and then to each transport defined in instance constructor.

Creating own transport

Creating own transport required implementing all methods from interface Transport. To do it, simply create new object (or class):

import { Transport, LogEvent, LogEventWithReplacedNulls } from 'nest-logging-transport';

const customTransport = {
  log(event: LogEvent, eventWithoutNulls: LogEventWithReplacedNulls) {
    // [...]
  },
  // [...]
};

You can find examples in src/transports.

Difference between log events

To make operating on logs easier there is event with nulls replaced with empty strings ''. Normal log:

{
  additionalContext: null,
  stacktrace: null,
  baseContext: 'Bootstrap',
  type: 'log',
  timestamp: 2022-03-23T19:26:59.295Z,
  message: 'Server listening'
}

Log with replaced nulls:

{
  additionalContext: '',
  stacktrace: '',
  baseContext: 'Bootstrap',
  type: 'log',
  timestamp: 2022-03-23T19:26:59.295Z,
  message: 'Server listening'
}

Log functions in your logger can take event with nulls as first argument and without nulls as the second one.

Examples

Logs from default (console) transport looks like this:

image showing example log output

You can also use preview script, available after cloning the repository:

yarn preview

Publishing package (for package maintainers and forks)

Publishing this package is semi-automated. Steps to do that:

  1. Clone repository and checkout branch you want to release
  2. Install dependencies from current lockfile yarn install --frozen-lockfile
  3. Use release scripts:
    1. yarn release- in most cases, release script will take care of giving package the right number
    2. yarn release:patch- when you want to change only last part of semver (x.x.X)
    3. yarn release:minor- when you want to change middle part of semver (x.X.x)
    4. yarn release:major- when you want to change first part of semver (X.x.x)
  4. Push created tags using git push --follow-tags origin master. Don't use npm publish.

You can read more about semver on semver.org page.

This project will follow semver from first major release (versions starting with 0 will be considered beta versions and will not follow semver).