From 483b14bea8c09a57885f38003c9d9020297a4a94 Mon Sep 17 00:00:00 2001 From: e-dot Date: Fri, 28 Aug 2020 10:55:51 +0200 Subject: [PATCH 1/3] Update app.js Handle file extension properly : if the extension is not .log, use the same extension for rotated files (e.g. if you rotate .error file, it will keep the .error extension). --- app.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app.js b/app.js index 9277400..3988b1a 100644 --- a/app.js +++ b/app.js @@ -104,7 +104,12 @@ function proceed(file) { // use default } } - var final_name = file.substr(0, file.length - 4) + '__' + final_time + '.log'; + // Get base file name - i.e. without file extension : remove everything after the last dot (up to then end of string) + var base_file_name = file.replace(/\.[^\.]+$/, '') + // Get file extension : replace everything by string after the last dot + var file_ext = file.replace(/^.*\.([^\.]*)$/i, '$1') + // Build final filename with base + time + extension + var final_name = base_file_name + '__' + final_time + '.' + file_ext; // if compression is enabled, add gz extention and create a gzip instance if (COMPRESSION) { var GZIP = zlib.createGzip({ level: zlib.Z_BEST_COMPRESSION, memLevel: zlib.Z_BEST_COMPRESSION }); From 788623f13027b71f1feaaeb0102840f7a8bdaafb Mon Sep 17 00:00:00 2001 From: e-dot Date: Fri, 28 Aug 2020 11:48:24 +0200 Subject: [PATCH 2/3] Update README.md --- README.md | 41 ++--------------------------------------- 1 file changed, 2 insertions(+), 39 deletions(-) diff --git a/README.md b/README.md index 32151d5..91d0820 100644 --- a/README.md +++ b/README.md @@ -1,44 +1,7 @@ ## Description -PM2 module to automatically rotate logs of processes managed by PM2. +I CREATED THIS BRANCH TO FIX ISSUE #160 (https://github.com/keymetrics/pm2-logrotate/issues/160). -## Install +See pull request #161 (https://github.com/keymetrics/pm2-logrotate/pull/161) for details. - pm2 install pm2-logrotate - -**NOTE:** the command is `pm2 install` NOT `npm install` - -## Configure - -- `max_size` (Defaults to `10M`): When a file size becomes higher than this value it will rotate it (its possible that the worker check the file after it actually pass the limit) . You can specify the unit at then end: `10G`, `10M`, `10K` -- `retain` (Defaults to `30` file logs): This number is the number of rotated logs that are keep at any one time, it means that if you have retain = 7 you will have at most 7 rotated logs and your current one. -- `compress` (Defaults to `false`): Enable compression via gzip for all rotated logs -- `dateFormat` (Defaults to `YYYY-MM-DD_HH-mm-ss`) : Format of the data used the name the file of log -- `rotateModule` (Defaults to `true`) : Rotate the log of pm2's module like other apps -- `workerInterval` (Defaults to `30` in secs) : You can control at which interval the worker is checking the log's size (minimum is `1`) -- `rotateInterval` (Defaults to `0 0 * * *` everyday at midnight): This cron is used to a force rotate when executed. -We are using [node-schedule](https://github.com/node-schedule/node-schedule) to schedule cron, so all valid cron for [node-schedule](https://github.com/node-schedule/node-schedule) is valid cron for this option. Cron style : -- `TZ` (Defaults to system time): This is the standard [tz database timezone](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones) used to offset the log file saved. For instance, a value of `Etc/GMT+1`, with an hourly log, will save a file at hour `14` GMT with hour `13` (GMT+1) in the log name. - -``` -* * * * * * -┬ ┬ ┬ ┬ ┬ ┬ -│ │ │ │ │ | -│ │ │ │ │ └ day of week (0 - 7) (0 or 7 is Sun) -│ │ │ │ └───── month (1 - 12) -│ │ │ └────────── day of month (1 - 31) -│ │ └─────────────── hour (0 - 23) -│ └──────────────────── minute (0 - 59) -└───────────────────────── second (0 - 59, OPTIONAL) -``` - -### How to set these values ? - - After having installed the module you have to type : -`pm2 set pm2-logrotate: ` - -e.g: -- `pm2 set pm2-logrotate:max_size 1K` (1KB) -- `pm2 set pm2-logrotate:compress true` (compress logs when rotated) -- `pm2 set pm2-logrotate:rotateInterval '*/1 * * * *'` (force rotate every minute) From 3cbdb9767e3f55902c892132036b0394c5ef3883 Mon Sep 17 00:00:00 2001 From: e-dot Date: Tue, 8 Sep 2020 16:16:29 +0200 Subject: [PATCH 3/3] Change package.json to enable module deploy in pm2 --- package.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 9af0f3e..9e5b9b1 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "pm2-logrotate", - "version": "2.7.0", - "description": "Module to rotate logs of every pm2 application", + "version": "1.0.0", + "description": "Module to rotate logs of every pm2 application - derived from pm2-logrotate 2.7.0", "main": "app.js", "dependencies": { "graceful-fs": "^4.2.2", @@ -13,15 +13,15 @@ "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, - "author": "Joni SHKURTI", + "author": "Joni SHKURTI and EDot", "repository": { "type": "git", - "url": "git+https://github.com/pm2-hive/pm2-logrotate.git" + "url": "git+https://github.com/e-dot/pm2-logrotate.git" }, "bugs": { - "url": "https://github.com/pm2-hive/pm2-logrotate/issues" + "url": "https://github.com/e-dot/pm2-logrotate/issues" }, - "homepage": "https://github.com/pm2-hive/pm2-logrotate", + "homepage": "https://github.com/e-dot/pm2-logrotate", "license": "MIT", "apps": [ {