{"id":18654708,"url":"https://github.com/camus-design/pm2-intercom-log4js","last_synced_at":"2025-07-23T23:04:18.970Z","repository":{"id":42085356,"uuid":"475298536","full_name":"camus-design/pm2-intercom-log4js","owner":"camus-design","description":"A tool to solve log4js log synchronization in PM2's multi-process mode.  ","archived":false,"fork":false,"pushed_at":"2023-09-03T07:50:08.000Z","size":225,"stargazers_count":11,"open_issues_count":0,"forks_count":2,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-04-11T20:42:59.833Z","etag":null,"topics":["cluster","fe","frontend","intercom","log","log4js","logging","multiprocess","multithreading","node","nodejs","pm2","protect","rpc","safe","synchronize"],"latest_commit_sha":null,"homepage":"https://npmjs.com/package/@camus-design/pm2-intercom-log4js","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/camus-design.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-03-29T05:49:37.000Z","updated_at":"2023-10-18T02:29:57.000Z","dependencies_parsed_at":"2024-09-13T18:16:26.248Z","dependency_job_id":null,"html_url":"https://github.com/camus-design/pm2-intercom-log4js","commit_stats":null,"previous_names":["billionbottle/pm2-intercom-log4js"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/camus-design/pm2-intercom-log4js","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/camus-design%2Fpm2-intercom-log4js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/camus-design%2Fpm2-intercom-log4js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/camus-design%2Fpm2-intercom-log4js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/camus-design%2Fpm2-intercom-log4js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/camus-design","download_url":"https://codeload.github.com/camus-design/pm2-intercom-log4js/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/camus-design%2Fpm2-intercom-log4js/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266764573,"owners_count":23980585,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-23T02:00:09.312Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cluster","fe","frontend","intercom","log","log4js","logging","multiprocess","multithreading","node","nodejs","pm2","protect","rpc","safe","synchronize"],"created_at":"2024-11-07T07:16:15.975Z","updated_at":"2025-07-23T23:04:18.941Z","avatar_url":"https://github.com/camus-design.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pm2-intercom-log4js\n\n[![build](https://img.shields.io/github/workflow/status/camus-design/pm2-intercom-log4js/Build%20And%20Publish)](https://github.com/camus-design/pm2-intercom-log4js)\n[![npm](https://img.shields.io/npm/v/@camus-design/pm2-intercom-log4js)](https://www.npmjs.com/package/@camus-design/pm2-intercom-log4js)\n[![node](https://img.shields.io/node/v/@camus-design/pm2-intercom-log4js)](https://www.npmjs.com/package/@camus-design/pm2-intercom-log4js)\n[![license](https://img.shields.io/github/license/camus-design/pm2-intercom-log4js)](https://github.com/camus-design/pm2-intercom-log4js)\n\nA tool to solve [log4js](https://github.com/log4js-node/log4js-node) log synchronization in \u003ca href=\"https://github.com/Unitech/pm2\" title=\"PM2\"\u003ePM2\u003c/a\u003e's multiprocess mode.\n\nEnglish | [简体中文](README.zh-CN.md)\n\n## Table of Contents\n\n- [pm2-intercom-log4js](#pm2-intercom-log4js)\n  - [Table of Contents](#table-of-contents)\n  - [Background](#background)\n  - [Get Started](#get-started)\n    - [Install](#install)\n    - [Usage](#usage)\n    - [API](#api)\n  - [Example](#example)\n  - [Contributing](#contributing)\n  - [License](#license)\n\n## Background\n\nHave you encountered a failure when you were executing `pm2 install pm2-intercom`? If you want to use log4js for stable log output in PM2's multiprocess mode, then using ***pm2-intercom-log4js*** for multiprocess log synchronization will be a good choice. It imitates the cooperation method of pm2-intercom + log4js, and aggregates the logs of the sub-processes to the main process for unified output, so as to avoid unpredictable exceptions in file reading or writing in multiprocess mode.\n\n## Get Started\n\npm2-intercom-log4js only exports one function, which is very convenient to use.\n\n### Install\n\nThis project uses [node](http://nodejs.org) and [npm](https://npmjs.com). Make sure that you have installed them locally.\n\n```sh\nnpm install @camus-design/pm2-intercom-log4js\n```\n\n### Usage\n\nWhen running the program in PM2 multiprocess mode, pm2-intercom-log4js will automatically find and use PM2 to handle the communication between the processes. This process is asynchronous, so you need to wait for this process to finish before initializing log4js.\n\n```javascript\nconst pm2Intercom = require('@camus-design/pm2-intercom-log4js');\n\npm2Intercom().catch((err) =\u003e {\n  // If the initialization fails, you can check the reason according to the error log. If it still cannot be solved, you can submit an issue.\n}).finally(() =\u003e {\n  // Be sure to wait for the process communication to be initialized before initializing log4js.\n  log4js.getLogger();\n  log4js.configure({\n    // Make sure logs4js has PM2 mode enabled.\n    pm2: true,\n  });\n});\n```\n\n### API\n\nThe `pm2Intercom` function above supports passing in an optional parameters object (like `pm2Intercom({ nodeModulesPath: '/root/xxx' })`), the parameters in the object are as follows:\n\n| Attributes            | Descriptions                                                         | Type   | Default |\n| --------------- | ------------------------------------------------------------ | ------ | ------ |\n| nodeModulesPath | Manually specify the absolute path to the node_modules folder where PM2 is located (if auto finding PM2 fails) | String | -      |\n\n## Example\n\nWe use PM2 to run the script in the `examples` directory and start two processes.\n\n```sh\npm2 start ./examples/index.js -i 2\n```\n\nWhen we don't use the `pm2Intercom` function (ie, comment out the `await pm2Intercom();` in the script), we see only one process successfully printing the log through the `pm2 logs` command.\n\n```\nxxx\\.pm2\\logs\\index-error-0.log last 15 lines:\nxxx\\.pm2\\logs\\index-out-1.log last 15 lines:\nxxx\\.pm2\\logs\\index-error-1.log last 15 lines:\nxxx\\.pm2\\logs\\index-out-0.log last 15 lines:\n0|index    | [2022-03-11T14:50:21.335] [INFO] default - Log from process 0\n```\n\nWhen we use the `pm2Intercom` function, we see that both processes successfully print logs, and both output to the log file of the main process.\n\n```\nxxx\\.pm2\\logs\\index-error-0.log last 15 lines:\nxxx\\.pm2\\logs\\index-error-1.log last 15 lines:\nxxx\\.pm2\\logs\\index-out-1.log last 15 lines:\n1|index    | Process 1 is waiting main process ready...\n1|index    | Process 1 is ready to log.\n\nxxx\\.pm2\\logs\\index-out-0.log last 15 lines:\n0|index    | Start pm2 intercom for log4js...\n0|index    | [2022-03-11T14:53:14.804] [INFO] default - Log from process 0\n0|index    | Intercom's main process started. (0: index)\n0|index    | [2022-03-11T14:53:14.883] [INFO] default - Log from process 1\n```\n\n## Contributing\n\nYou are very welcome to join us! [Submit an issue](https://github.com/camus-design/pm2-intercom-log4js/issues/new) or submit a pull request.\n\n## License\n\n[MIT](LICENSE) © Camus Design\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcamus-design%2Fpm2-intercom-log4js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcamus-design%2Fpm2-intercom-log4js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcamus-design%2Fpm2-intercom-log4js/lists"}