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

lj-log4js-pm2intercom

v1.1.2

Published

pm2-intercom is problematic with PM2 2.x, this is a mimic version to temporarily resolve some problem in our own project

Downloads

211

Readme

To fix pm2-intercom in PM2 2.x

Refer to log4js API doc https://log4js-node.github.io/log4js-node/api.html, regarding pm2: true

Problems of pm2-intercom and log4js:

  • Duplicate log messages PM2 v2.10.4 somehow runs multiple instances of pm2-intercom for cluster mode.

    While you start with pm2 install pm2-intercom then start your application in cluster mode, it runs multiple instances which leads to duplicate log messages.

    I am guessing it is PM2 module system's fault, so I write this simple version which is not supposed to be run as pm2 install module anymore.

  • Not supporting multiple applications in single PM2 box If you have 2 applications with difference names, and both in cluster mode, all of your log will go to first cluster instance/process of your first application's log appender.

1. Start lj-log4js-pm2intercom

Run this package as a normal PM2 application at first place,

It must be the first application to be started in PM2 (fork mode)

npm i lj-log4js-pm2intercom
pm2 start node_modules/.bin/log4js-pm2 --name log4js-intercom

Or you can: Clone this repo, go to root directory and run command:

yarn install # or npm install
pm2 start encosystem.conf.js

2. Change your application source code

In your application source where you configure log4js, add following code:

const pm2InstanceId = process.env.NODE_APP_INSTANCE;
// Only log4js master process need to handle all log appenders
if (pm2InstanceId === '0') {
	// Tell lj-log4js-pm2intercom: I am the log4js master process
	// lj-log4js-pm2intercom will need to know my process id and application name
	process.send({topic: 'log4js:master'});
}

then you start your applications in pm2 cluster mode as normal:

pm2 start app.js -i 2 --name <your application name>

Be aware to always use --name to specify a name

Now run pm2 ls, you should see something like below

┌───────────────────┬────┬─────────┬───────┬────────┬─────────┬────────┬─────┬───────────┬─────────┬──────────┐
│ App name          │ id │ mode    │ pid   │ status │ restart │ uptime │ cpu │ mem       │ user    │ watching │
├───────────────────┼────┼─────────┼───────┼────────┼─────────┼────────┼─────┼───────────┼─────────┼──────────┤
│ credit-appl-local │ 1  │ cluster │ 67022 │ online │ 0       │ 10m    │ 0%  │ 59.4 MB   │ liujing │ disabled │
│ credit-appl-local │ 2  │ cluster │ 67023 │ online │ 0       │ 10m    │ 0%  │ 62.2 MB   │ liujing │ disabled │
│ log4js-intercom   │ 0  │ fork    │ 67011 │ online │ 0       │ 10m    │ 0%  │ 29.6 MB   │ liujing │ disabled │
└───────────────────┴────┴─────────┴───────┴────────┴─────────┴────────┴─────┴───────────┴─────────┴──────────┘