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

@codecademy/next-logger

v2.2.0

Published

JSON logging patcher for Next.js

Downloads

4

Readme

next-logger

JSON logging patcher for Next.js

Description

This is a library to patch the logging functions used by Next.js, to have them output to stdout as newline-delimited JSON. This allows a Next.js application to log service events in a format that's compatible with log aggregators, without needing a custom Next.js server.

This works by importing Next.js' inbuilt logger via require, and replacing the logging methods with custom ones. It uses pino to output JSON formatted logs, preserving Next.js' message and prefix, but adding timestamp, hostname and more.

From v2.0.0 onwards, this library also patches the global console methods, to catch additional logs that Next.js makes directly to console. While pino logging remains intact, this may cause issues with other libraries which patch or use console methods. Use the next-only preset to opt-out of this patching.

Example Logs

Before:

ready - started server on http://localhost:3000
info  - Using external babel configuration from .babelrc
event - compiled successfully

After:

{"level":30,"time":1609160882850,"pid":18493,"hostname":"MyHostname","name":"next.js","msg":"started server on http://localhost:3000","prefix":"ready"}
{"level":30,"time":1609160883607,"pid":18493,"hostname":"MyHostname","name":"next.js","msg":"Using external babel configuration from .babelrc","prefix":"info"}
{"level":30,"time":1609160885675,"pid":18493,"hostname":"MyHostname","name":"next.js","msg":"compiled successfully","prefix":"event"}

Usage

First, install this package. You can do this with whatever Node package manager you're using in your project.

npm install next-logger

# or for Yarn

yarn add next-logger

Then add a NODE_OPTIONS string to your Next.js start script, to require in the logger.

NODE_OPTIONS='-r next-logger' next start

Adding to package.json Scripts

You can add this directly to your package.json scripts, to make it easier to start your service.

"scripts": {
  "start": "NODE_OPTIONS='-r next-logger' next start",
  // ...your other scripts
},

Presets

To support opting out of some patches, this library supports "presets". These can be used as above, with /presets/<PRESET_NAME> appended, for example: NODE_OPTIONS='-r next-logger/presets/next-only'.

The following presets are supported:

  • next-logger/presets/all - this includes all the patches this library supports. Using the library without a preset specified will use this preset.
  • next-logger/presets/next-only - this only includes patches specifically for the Next.js logger object.

Breaking Changes on >=1.0.0

This package name, next-logger has been inherited from @frank47, who had deprecated their published logging middleware for Next.js. The original package and this one aim to solve similar problems for JSON logging in Next.js. However, the implementation and usage of this solution is significantly different from the original, which was published up to v0.4.0. To minimise unexpected issues for previous users of the original next-logger, the new package begins at major v1.0.0.