pm2-logrotate 2.6.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/README.md +6 -4
- package/app.js +21 -3
- package/package.json +3 -3
- package/test/echo.js +4 -0
- package/pres/logo.png +0 -0
- /package/{test.js → test/test.js} +0 -0
package/CHANGELOG.md
ADDED
package/README.md
CHANGED
|
@@ -7,9 +7,7 @@ PM2 module to automatically rotate logs of processes managed by PM2.
|
|
|
7
7
|
|
|
8
8
|
pm2 install pm2-logrotate
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
pm2 install pm2-logrotate@2.2.0
|
|
10
|
+
**NOTE:** the command is `pm2 install` NOT `npm install`
|
|
13
11
|
|
|
14
12
|
## Configure
|
|
15
13
|
|
|
@@ -21,7 +19,7 @@ To install a specific version use the `@<version>` suffix
|
|
|
21
19
|
- `workerInterval` (Defaults to `30` in secs) : You can control at which interval the worker is checking the log's size (minimum is `1`)
|
|
22
20
|
- `rotateInterval` (Defaults to `0 0 * * *` everyday at midnight): This cron is used to a force rotate when executed.
|
|
23
21
|
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 :
|
|
24
|
-
- `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
|
|
22
|
+
- `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.
|
|
25
23
|
|
|
26
24
|
```
|
|
27
25
|
* * * * * *
|
|
@@ -35,6 +33,10 @@ We are using [node-schedule](https://github.com/node-schedule/node-schedule) to
|
|
|
35
33
|
└───────────────────────── second (0 - 59, OPTIONAL)
|
|
36
34
|
```
|
|
37
35
|
|
|
36
|
+
### How to view current configuration of the above values ?
|
|
37
|
+
After having installed the module, you have to type :
|
|
38
|
+
`pm2 conf`
|
|
39
|
+
|
|
38
40
|
### How to set these values ?
|
|
39
41
|
|
|
40
42
|
After having installed the module you have to type :
|
package/app.js
CHANGED
|
@@ -35,15 +35,21 @@ else if (process.env.HOME && !process.env.HOMEPATH)
|
|
|
35
35
|
else if (process.env.HOME || process.env.HOMEPATH)
|
|
36
36
|
PM2_ROOT_PATH = path.resolve(process.env.HOMEDRIVE, process.env.HOME || process.env.HOMEPATH, '.pm2');
|
|
37
37
|
|
|
38
|
+
const parseBool = (str, defaultVal = false) => {
|
|
39
|
+
if (str === 'true') return true;
|
|
40
|
+
if (str === 'false') return false;
|
|
41
|
+
return defaultVal;
|
|
42
|
+
};
|
|
43
|
+
|
|
38
44
|
var WORKER_INTERVAL = isNaN(parseInt(conf.workerInterval)) ? 30 * 1000 :
|
|
39
45
|
parseInt(conf.workerInterval) * 1000; // default: 30 secs
|
|
40
46
|
var SIZE_LIMIT = get_limit_size(); // default : 10MB
|
|
41
47
|
var ROTATE_CRON = conf.rotateInterval || "0 0 * * *"; // default : every day at midnight
|
|
42
48
|
var RETAIN = isNaN(parseInt(conf.retain)) ? undefined : parseInt(conf.retain); // All
|
|
43
|
-
var COMPRESSION =
|
|
49
|
+
var COMPRESSION = parseBool(conf.compress, false); // Do not compress by default
|
|
44
50
|
var DATE_FORMAT = conf.dateFormat || 'YYYY-MM-DD_HH-mm-ss';
|
|
45
51
|
var TZ = conf.TZ;
|
|
46
|
-
var ROTATE_MODULE =
|
|
52
|
+
var ROTATE_MODULE = parseBool(conf.rotateModule, true);
|
|
47
53
|
var WATCHED_FILES = [];
|
|
48
54
|
|
|
49
55
|
function get_limit_size() {
|
|
@@ -62,7 +68,7 @@ function get_limit_size() {
|
|
|
62
68
|
|
|
63
69
|
function delete_old(file) {
|
|
64
70
|
if (file === "/dev/null") return;
|
|
65
|
-
var fileBaseName =
|
|
71
|
+
var fileBaseName = path.basename(file, '.log') + "__";
|
|
66
72
|
var dirName = path.dirname(file);
|
|
67
73
|
|
|
68
74
|
fs.readdir(dirName, function(err, files) {
|
|
@@ -199,10 +205,16 @@ pm2.connect(function(err) {
|
|
|
199
205
|
pm2.list(function(err, apps) {
|
|
200
206
|
if (err) return console.error(err.stack || err);
|
|
201
207
|
|
|
208
|
+
var appMap = {};
|
|
202
209
|
// rotate log that are bigger than the limit
|
|
203
210
|
apps.forEach(function(app) {
|
|
204
211
|
// if its a module and the rotate of module is disabled, ignore
|
|
205
212
|
if (typeof(app.pm2_env.axm_options.isModule) !== 'undefined' && !ROTATE_MODULE) return ;
|
|
213
|
+
|
|
214
|
+
// if apps instances are multi and one of the instances has rotated, ignore
|
|
215
|
+
if(app.pm2_env.instances > 1 && appMap[app.name]) return;
|
|
216
|
+
|
|
217
|
+
appMap[app.name] = app;
|
|
206
218
|
|
|
207
219
|
proceed_app(app, false);
|
|
208
220
|
});
|
|
@@ -219,11 +231,17 @@ pm2.connect(function(err) {
|
|
|
219
231
|
pm2.list(function(err, apps) {
|
|
220
232
|
if (err) return console.error(err.stack || err);
|
|
221
233
|
|
|
234
|
+
var appMap = {};
|
|
222
235
|
// force rotate for each app
|
|
223
236
|
apps.forEach(function(app) {
|
|
224
237
|
// if its a module and the rotate of module is disabled, ignore
|
|
225
238
|
if (typeof(app.pm2_env.axm_options.isModule) !== 'undefined' && !ROTATE_MODULE) return ;
|
|
226
239
|
|
|
240
|
+
// if apps instances are multi and one of the instances has rotated, ignore
|
|
241
|
+
if(app.pm2_env.instances > 1 && appMap[app.name]) return;
|
|
242
|
+
|
|
243
|
+
appMap[app.name] = app;
|
|
244
|
+
|
|
227
245
|
proceed_app(app, true);
|
|
228
246
|
});
|
|
229
247
|
});
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pm2-logrotate",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "Module to rotate logs of every pm2 application",
|
|
5
5
|
"main": "app.js",
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"graceful-fs": "^4.
|
|
7
|
+
"graceful-fs": "^4.2.2",
|
|
8
8
|
"moment-timezone": "^0.5.11",
|
|
9
|
-
"node-schedule": "^1.
|
|
9
|
+
"node-schedule": "^1.3.1",
|
|
10
10
|
"pm2": "latest",
|
|
11
11
|
"pmx": "latest"
|
|
12
12
|
},
|
package/test/echo.js
ADDED
package/pres/logo.png
DELETED
|
Binary file
|
|
File without changes
|