Giter Club home page Giter Club logo

pm2-logrotate's Introduction

Description

PM2 module to automatically rotate logs of processes managed by PM2.

Install

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 to schedule cron, so all valid cron for node-schedule is valid cron for this option. Cron style :
  • TZ (Defaults to system time): This is the standard tz database timezone 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 view current configuration of the above values ?

After having installed the module, you have to type : pm2 conf

How to set these values ?

After having installed the module you have to type : pm2 set pm2-logrotate:<param> <value>

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)

pm2-logrotate's People

Contributors

danez avatar daraghking avatar hallucinogenizer avatar hemanthmalla avatar jshkurti avatar ma-zal avatar monkeydo avatar nitrocode avatar richardpringle avatar roytan883 avatar unitech avatar vmarchaud avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pm2-logrotate's Issues

pm2-logrotate is not working

RajRajen:lb4b-api rajrajen$ pm2 set pm2-logrotate:max_size 100K
== pm2-logrotate ==
┌──────────┬───────┐
│ key │ value │
├──────────┼───────┤
│ max_size │ 100K │
└──────────┴───────┘
RajRajen:lb4b-api rajrajen$ pm2 save
[PM2] Dumping processes
RajRajen:lb4b-api rajrajen$ ls -lhart /Volumes/DataPartition/MyData2/pm2/logs
total 2448
-rw-r--r-- 1 rajrajen staff 637K Dec 26 23:35 lb4b-api-out-old.log
drwxr-xr-x 12 rajrajen staff 408B Dec 27 09:54 ..
drwxr-xr-x 5 rajrajen staff 170B Dec 27 09:54 .
-rw-r--r-- 1 rajrajen staff 3.5K Dec 27 09:55 lb4b-api-error-0.log
-rw-r--r-- 1 rajrajen staff 576K Dec 27 10:07 lb4b-api-out-0.log
RajRajen:lb4b-api rajrajen$

Eventhough , I setup the pm2-logrotate at 100K , the process continues to dump log files in only one out log file. Is there anything else, I need to validate this one? Please let me know. Thanks

RangeError: Attempt to allocate Buffer larger than maximum size: 0x3fffffff bytes

RangeError: Attempt to allocate Buffer larger than maximum size: 0x3fffffff bytes
at new Buffer (buffer.js:72:11)
at Object.fs.readFileSync (fs.js:374:16)
at proceed (/home/ubuntu/.pm2/node_modules/pm2-logrotate/app.js:70:19)
at proceed_file (/home/ubuntu/.pm2/node_modules/pm2-logrotate/app.js:92:5)
at proceed_app (/home/ubuntu/.pm2/node_modules/pm2-logrotate/app.js:101:3)
at /home/ubuntu/.pm2/node_modules/pm2-logrotate/app.js:133:37
at Array.forEach (native)
at /home/ubuntu/.pm2/node_modules/pm2-logrotate/app.js:133:14
at /home/ubuntu/.pm2/node_modules/pm2-logrotate/node_modules/pm2/lib/CLI.js:1387:17
at /home/ubuntu/.pm2/node_modules/pm2-logrotate/node_modules/pm2/node_modules/pm2-axon-rpc/lib/client.js:45:10

High memory usage

First use-case, ubuntu14.04
pm2-logrotate 2.0.0
PMX version 0.6.8
Global logs size 20.87 GB (yeah, we should probably turn on cleanup)
Files count 8.4K
Memory Usage: 958.6 MB

Second use-case, amazon linux-ami
pm2-logrotate 2.0.0
PMX version 0.6.8
Global logs size 147.11 MB
Files count 836
Memory usage: 579.4 MB

How to read current settings?

Hi there,

I have an installed pm2 instance with the lograte plugin, but the initial admin didn't document the configuration.

Is there a command to list / view these settings?

logrotate fails after 15 restarts

logrotate fails after 15 restarts with this message:

0|logrotat | Error: <files> required
0|logrotat |     at Object.<anonymous> (/home/mosfilm/.pm2/node_modules/logrotate/bin/rotate:38:26)

version 2.1.5

RETAIN ignored on Windows platforms

The determination of the variable fileBaseName (line 65) depends on forward slash being the path separator. Tested using path.sep instead of '/'; yields expected results.

Bad "this" reference when notifying of file error. (this._interpretError is not a function)

logrotate encountered a file permissions issue when rotating a file to expected and normal file permissions issues. That one is expected.

However, after that error, a second error inside pm2-logrotate causes logrotate to fail. This is the stack trace:

TypeError: this._interpretError is not a function
    at WriteStream.Notify.notify (/home/pm2user/.pm2/node_modules/pmx/lib/notify.js:106:22)
    at emitOne (events.js:101:20)
    at WriteStream.emit (events.js:188:7)
    at WriteStream.<anonymous> (fs.js:2109:12)
    at FSReqWrap.oncomplete (fs.js:123:15)

This is when executing of this fragment of code:

Notify.notify = function(err) {

  var ret_err = this._interpretError(err);

When called, "this" is not a Notify object, so "this._interpretError" fails. I believe this is caused by these lines in logrotate app.js:

  // listen for error
        readStream.on('error', pmx.notify);
  writeStream.on('error', pmx.notify);
  if (COMPRESSION)
    GZIP.on('error', pmx.notify);

When these encounter errors, they call the right function, but the "this" reference is incorrect.

I believe you can fix it by doing something like this:

  // listen for error
        readStream.on('error', pmx.notify.bind(pmx));
  writeStream.on('error', pmx.notify.bind(pmx));
  if (COMPRESSION)
    GZIP.on('error', pmx.notify.bind(pmx));

The "bind" will cause these events to call the notify function with the pmx object as the "this" reference.

pm2-logrotate-out.log content contains `undefined`

Since about the early part of March, 2017 this package doesn't seem to be rotating at all now. January through early part of March, 2017 did.

Log file for this month after a manual fix (removal of March and April 2017) of all affected log files (also present from March 7th forward):

undefined

... what it normally has (edited for ~ for security reasons)...

"~/.pm2/logs/app-error__2017-03-07_00-00-00.log" has been created

Config since January 2017 (used http://www.cronmaker.com/ to make the rotateInterval... rotating once a month on the first at 00:00... reconfirmed same value as of today)...

$ pm2 get pm2-logrotate
== pm2-logrotate ==
┌────────────────┬─────────────────┐
│ key            │ value           │
├────────────────┼─────────────────┤
│ max_size       │ 5M              │
│ retain         │ all             │
│ rotateInterval │ 0 0 0 1 1/1 ? * │
└────────────────┴─────────────────┘

Installation method since ~2013:

$ sudo npm install pm2 -g
$ sudo npm install pm2-logrotate -g

Latest nodejs LTS and all sub-deps updated often.

Reupdated pm2@2.4.6 today from pm2@2.4.5... same issue as last month. Rechecked manually pm2-logrotate@2.2.0 is present.

Thanks for the look.

pm2 install on Windows

As you know, module installation has been broken on Windows. Here's a simple fix:

In file Modularizer.js,

  • add a require for 'os'
  • at 'ugly hack', change the shelljs.exe line to:

    var no_errs = os.platform()==='win32'? ' 2> nul:' : ' 2> /dev/null';

    shelljs.exec('npm install ' + module_name + ' --prefix ' + cst.PM2_ROOT_PATH + no_errs, function(code) {

Support log retention

pm2-logrotate does not have any configure to remove old log file after retention period. To prevent disk full, we need to use another log logrotate tool like logrotate to do retention. It would be great if it can be done in pm2-logrotate.

module doesn't start

Hello,
I copied the whole folder (../.pm2/node_modules/pm2-logrotate) to the same directory on a machine without internet access but the module doesn't start, even after a reboot.
How can I activate it or install it on an offline machine?
thanks in advance

Rotated files date

I'm not sure what's the rational behind the rotated file names. Actual logic is to take the current date and subtract 1 of the specified time unit. As an example, if today is 2015-12-01 and interval_unit is 'MM', the file will be named 2015-11-01.
This may make some sense if the logrotate module is running continuously and rotation is time based only, but files can also be rotated on size. Suppose I have a max_size of 1K, interval_unit is 'MM' and my apps produce 1K of logs per minute. The logs generated today will be rotated due to size, but the file name will be 2015-11-01 while the content is that of the last minute of today.
There is also a problem with the file deletion system if the unit is changed. Suppose you have an interval_unit of 'DD' and a retention of 2, then suppose 2 files are created today, with the names:

somelog-out__2015-11-30-15-00.log
somelog-out__2015-11-30-15-05.log

(notice the date of yesterday, which is today minus 1 day)

Now, suppose I change the interval_unit to 'MM'. If a new file is created, the file will have a name like:

somelog-out__2015-11-01-15-10.log

(notice the date of 1 month ago, which is today minus 1 month)

The log rotation system will sort the files in this way:

somelog-out__2015-11-30-15-00.log
somelog-out__2015-11-30-15-05.log
somelog-out__2015-11-01-15-10.log <<< NEWEST FILE&CONTENT, OLDEST NAME

And then will delete what thinks is the OLDEST file, i.e. "somelog-out__2015-11-01-15-10.log". But this file contains the latest log lines instead...

My suggestions are:

  1. allow to name the file with the actual date (the date when the file is rotated).
  2. sort files for deletion using file date, not their names

pm2 set pm2-logrotate:max_size

Just started using pm2-logrotate and immediately ran into an issue. I'm not sure whether this is expected behaviour but at least its a warning to anybody trying to do the same.

I had a 27GB logfile on a server that was running for a long time.
I ran pm2 set pm2-logrotate:max_size 1G

What I expected was that on the default time (midnight) the huge logfile would be moved and from then on logrotate would check for files > 1GB at the time specified.

What actually happened was that a number of logfiles were generated in parallel immediately and I almost ran out of disk since the orginal logfile didn't get smaller.

pm2 list showed pm2-logrotate as an activated module, but pm2 stop pm2-logrotate only resulted in "Process pm2-logrotate not found".

In the end i went on a killing spree and deleted the pm2 god as well as the node processes and deleted the huge log file.

logs rotated more often then configured

I'm using:

pm2: v2.4.0
pm2-logrotate: v2.2.0
OS: Ubuntu 14.04 64bit
node: v4.8.0

with following settings:

pm2 get pm2-logrotate:rotateInterval
Value for module pm2-logrotate key rotateInterval: 0 0 * * *
pm2 get pm2-logrotate:max_size
Value for module pm2-logrotate key max_size: 10MB
pm2 get pm2-logrotate:retain
Value for module pm2-logrotate key retain: 7
pm2 get pm2-logrotate:workerInterval
{ err: 'Unknown key' }
pm2 get pm2-logrotate:compress
{ err: 'Unknown key' }
pm2 get pm2-logrotate:dateFormat
{ err: 'Unknown key' }
pm2 get pm2-logrotate:rotateModule
{ err: 'Unknown key' }

Expected:
logs are rotated every midnight when they're larger than 10MB.

Actual:
Logs are rotated every 2 - 5 minutes.

-rw-rw-r--  1 nodejs nodejs    210 Mar  2 18:02 api-dev_error__2017-03-02_18-02-44.log
-rw-rw-r--  1 nodejs nodejs    210 Mar  3 13:13 api-dev_error__2017-03-03_13-13-16.log
-rw-rw-r--  1 nodejs nodejs    210 Mar  3 13:16 api-dev_error__2017-03-03_13-16-16.log
-rw-rw-r--  1 nodejs nodejs    562 Mar  3 20:41 api-dev_error__2017-03-03_20-41-05.log
-rw-rw-r--  1 nodejs nodejs    281 Mar  3 20:42 api-dev_error__2017-03-03_20-42-05.log
-rw-rw-r--  1 nodejs nodejs    281 Mar  3 20:42 api-dev_error__2017-03-03_20-42-35.log
-rw-rw-r--  1 nodejs nodejs    281 Mar  3 20:44 api-dev_error__2017-03-03_20-44-34.log
-rw-r--r--  1 nodejs nodejs      0 Mar  3 20:44 api-dev_error.log
-rw-rw-r--  1 nodejs nodejs     89 Mar  3 20:57 api-dev_out__2017-03-03_20-57-18.log
-rw-rw-r--  1 nodejs nodejs     89 Mar  3 20:58 api-dev_out__2017-03-03_20-58-18.log
-rw-rw-r--  1 nodejs nodejs    327 Mar  3 20:59 api-dev_out__2017-03-03_20-59-18.log
-rw-rw-r--  1 nodejs nodejs     89 Mar  3 21:00 api-dev_out__2017-03-03_21-00-18.log
-rw-rw-r--  1 nodejs nodejs     89 Mar  3 21:01 api-dev_out__2017-03-03_21-01-18.log
-rw-rw-r--  1 nodejs nodejs     89 Mar  3 21:02 api-dev_out__2017-03-03_21-02-18.log
-rw-rw-r--  1 nodejs nodejs     89 Mar  3 21:03 api-dev_out__2017-03-03_21-03-18.log
-rw-r--r--  1 nodejs nodejs     89 Mar  3 21:04 api-dev_out.log
-rw-rw-r--  1 nodejs nodejs   1416 Mar  3 19:35 notify-dev__2017-03-03_19-35-06.log
-rw-rw-r--  1 nodejs nodejs   1029 Mar  3 19:36 notify-dev__2017-03-03_19-36-36.log
-rw-rw-r--  1 nodejs nodejs    390 Mar  3 19:37 notify-dev__2017-03-03_19-37-06.log
-rw-rw-r--  1 nodejs nodejs   4237 Mar  3 19:39 notify-dev__2017-03-03_19-39-06.log
-rw-rw-r--  1 nodejs nodejs    396 Mar  3 19:59 notify-dev__2017-03-03_19-59-36.log
-rw-rw-r--  1 nodejs nodejs    852 Mar  3 20:03 notify-dev__2017-03-03_20-03-36.log
-rw-rw-r--  1 nodejs nodejs   4060 Mar  3 20:12 notify-dev__2017-03-03_20-12-05.log
-rw-rw-r--  1 nodejs nodejs   2326 Mar  3 19:29 notify-dev_error__2017-03-03_19-29-36.log
-rw-rw-r--  1 nodejs nodejs     91 Mar  3 19:30 notify-dev_error__2017-03-03_19-30-36.log
-rw-rw-r--  1 nodejs nodejs  10925 Mar  3 19:31 notify-dev_error__2017-03-03_19-31-06.log
-rw-rw-r--  1 nodejs nodejs    141 Mar  3 19:32 notify-dev_error__2017-03-03_19-32-06.log
-rw-rw-r--  1 nodejs nodejs   2118 Mar  3 19:36 notify-dev_error__2017-03-03_19-36-36.log
-rw-rw-r--  1 nodejs nodejs     91 Mar  3 19:59 notify-dev_error__2017-03-03_19-59-36.log
-rw-rw-r--  1 nodejs nodejs   6555 Mar  3 20:12 notify-dev_error__2017-03-03_20-12-05.log
-rw-rw-r--  1 nodejs nodejs      0 Mar  3 20:12 notify-dev_error.log
-rw-rw-r--  1 nodejs nodejs      0 Mar  3 20:12 notify-dev.log
-rw-r--r--  1 nodejs nodejs      0 Feb 21 22:38 ws-dev_error.log
-rw-rw-r--  1 nodejs nodejs   1072 Mar  3 19:35 ws-dev_out__2017-03-03_19-35-06.log
-rw-rw-r--  1 nodejs nodejs    587 Mar  3 19:36 ws-dev_out__2017-03-03_19-36-36.log
-rw-rw-r--  1 nodejs nodejs    202 Mar  3 19:37 ws-dev_out__2017-03-03_19-37-06.log
-rw-rw-r--  1 nodejs nodejs   3829 Mar  3 19:39 ws-dev_out__2017-03-03_19-39-06.log
-rw-rw-r--  1 nodejs nodejs    415 Mar  3 19:59 ws-dev_out__2017-03-03_19-59-36.log
-rw-rw-r--  1 nodejs nodejs    626 Mar  3 20:03 ws-dev_out__2017-03-03_20-03-36.log
-rw-rw-r--  1 nodejs nodejs   1878 Mar  3 20:12 ws-dev_out__2017-03-03_20-12-05.log
-rw-rw-r--  1 nodejs nodejs      0 Mar  3 20:12 ws-dev_out.log

Please warnning user if free disk space is low

My server is low free disk space because of pm2 log files, so i install pm2-logrotate, it start running, split log files, but it occupy more space quickly. Finally i manually remove all log files and do "pm2 kill" to makesure all log files closed to really free disk space. This is my story, hopes there is a warnning before i do it:(

High memory usage

Hello

I have a simple setup with only one active app, but pm2-logrotate uses 108MB.
image

(also note the double % sign??)

Is there a way to set timezone?

Hi alls,
I would like to rotate log file per date every midnight in my local timezone and avoid changing the system timezone.

logrotate errors out on startup

When I restart pm2, I get the following error from pm2-logrotate. This prevents the apps from starting.

TypeError: Cannot read property 'toString' of undefined
    at get_limit_size (/home/jenkins/.pm2/node_modules/pm2-logrotate/app.js:49:36)
    at Object.<anonymous> (/home/jenkins/.pm2/node_modules/pm2-logrotate/app.js:30:18)
    at Module._compile (module.js:541:32)
    at Object.Module._extensions..js (module.js:550:10)
    at Module.load (module.js:458:32)
    at tryModuleLoad (module.js:417:12)
    at Function.Module._load (module.js:409:3)
    at Function._load (/home/jenkins/.pm2/node_modules/pmx/lib/transaction.js:62:21)
    at Object.<anonymous> (/home/jenkins/.pm2/node_modules/pm2/lib/ProcessContainerFork.js:46:21)
    at Module._compile (module.js:541:32)

I was able to install pm2-logrotate and successfully run it for a while, but I am prevented from using it after restarting.

I added the following to my module_conf.json and it looks like by explicitly adding the variables, I am able to use pm2-logrotate again:

    "pm2-logrotate": {
        "interval": "1",
        "max_size": "10M",
        "interval_unit": "DD",
        "retain": "4"
    }

However, this is of couse less than ideal. Any ideas on why this is happening?

Rotating empty logs?

-rw-rw-r-- 1 ubuntu ubuntu 2,6K août  12 10:00 AXM-REVERSE-INTERACTION-out.log
-rw-rw-r-- 1 ubuntu ubuntu    0 août  11 00:00 AXM-WEB-API-error__2015-08-10.log
-rw-rw-r-- 1 ubuntu ubuntu    0 août  12 00:00 AXM-WEB-API-error__2015-08-11.log
-rw-rw-r-- 1 ubuntu ubuntu 2,2K août  12 11:19 AXM-WEB-API-error.log
-rw-rw-r-- 1 ubuntu ubuntu    0 août  11 00:00 AXM-WEB-API-out__2015-08-10.log
-rw-rw-r-- 1 ubuntu ubuntu    0 août  12 00:00 AXM-WEB-API-out__2015-08-11.log
-rw-rw-r-- 1 ubuntu ubuntu  31K août  12 11:48 AXM-WEB-API-out.log
-rw-rw-r-- 1 ubuntu ubuntu 9,3K août  12 11:51 pm2-elasticsearch-error-22.log

pm2 log --lines show truncated output

I have the following setup:

Process file

{
  "apps": [{
    "name"            : "dash-preview",
    "script"          : "./preview/bin/www",
    "error_file"      : "./preview/log/err.log",
    "out_file"        : "./preview/log/out.log",
    "log_type"        : "json",
    "merge_logs"      : true,
    "log_date_format" : "YYYY-MM-DD HH:mm Z",
    "env": {
      "NODE_ENV": "development",
      "PORT"    : "1485"
    }
  }]
}

Logrotate config config

┌──────────┬───────┐
│ key      │ value │
├──────────┼───────┤
│ max_size │ 128MB │
│ retain   │ all   │
└──────────┴───────┘

Output

$ sudo pm2 logs --lines 100
[TAILING] Tailing last 100 lines for [all] processes (change the value with --lines option)
/home/user/.pm2/pm2.log last 100 lines:
/home/user/.pm2/logs/pm2-logrotate-error-0.log last 100 lines:
/home/deploy/client/preview/log/err.log last 100 lines:
/home/deploy/client/preview/log/out.log last 100 lines:
/home/user/.pm2/logs/pm2-logrotate-out-0.log last 100 lines:
0|pm2-logr | "/home/user/.pm2/logs/pm2-logrotate-out-0__2017-03-04_00-35-02.log" has been created

[STREAMING] Now streaming realtime logs for [all] processes```

Is there a reason why I can not see older logs? The service has been running for a while now but the logs turn out to be empty

pm2-config example

What is the correct way to add options to my project's pm2 configuration file? I'm looking for an example.

Is this correct for an existing config?

	apps: [
		{
			name: 'example'
			,script: 'the.js'
			// for pm2-logrotate
			,max_size: "3M"
			,retain: "all"
			,compress: true
			,dateFormat: "YYYY-MM-DD_HH-mm-ss"
			,workerInterval: 10
			,rotateInterval: "*/5 * * * *"
			,rotateModule: true
		}
	]

Log File Size exceeding Max Size config value

I'm currently running into an issue where the log files are exceeding the max size limit for a log file. Configuration is the following:

{ "max_size": "50M", "retain": "20" }

Here is an example of file when I do "ls -lh":

564M Dec  7 07:01 App__2015-12-06-07-01.log

Twenty files are being created with various sizes from 259 MB up to 614 MB. The current log is the only one that seems to be less than what I specified; currently it's 43 MB.

My understanding based off the config I set is I should have 21 files and all of them 50 MB each.

Off topic but wondering why file rotation names aren't .log.1 and so forth. I come from a Java background and usually you can configure it to be time-based or size based which would have the .log.1 extension.

License missing

There's no license for this module. I recommend the MIT license.

Rotating non-root user logs?

When I attempt to install pm2-logrotate with a non-root user, I receive the following error:

$ pm2 install pm2-logrotate
[PM2][Module] Installing module pm2-logrotate
[PM2][Module] Processing...
[PM2][Module][ERROR] Unknown module

If I do the same as the root user, the module installs fine:

$ sudo pm2 install pm2-logrotate
[PM2][Module] Installing module pm2-logrotate
[PM2][Module] Processing...
....
[PM2][Module] Module downloaded
[PM2][WARN] Applications pm2-logrotate not running, starting...
[PM2] App [pm2-logrotate] launched (1 instances)
[PM2][Module] Module successfully installed and launched
[PM2][Module] : To configure module do
[PM2][Module] : $ pm2 conf

But when I execute pm2 status for the non-root user, I do not see the module. Does this rotate the logs for all users? It doesn't seem to be doing anything at all. My log files continue to get larger. I've set the interval to 1 minute, restarted PM2, re-created PM2 service jobs, and still nothing.

Cannot remove empty config

Hello there,
I accidentally write pm2 set pm2-logrotate: interval 1 (notice the space between : and interval)
Then I remove the empty key by typing pm2 set pm2-logrotate: '' but there will be empty row left:

key value
interval_unit DD
(empty) (empty)
retain 7

How can I remove the empty key-value from the config?

setting a custom pm2-logrotate path

Hello,

Currently, pm2-logrotate seems to rotate its own logs under wherever PM2_HOME is set. Even though the logs produced by the application managed by pm2 can be set to go to a custom location, the pm2-logrotate's own logs(pm2-logrotate-error-0.log, pm2-logrotate-out-0.log
) just go under PM2_HOME. How can we define a custom path to make these logs go to a certain place? How can we override this default path?

Thank you so much,
KB

TypeError: Cannot read property 'length' of undefined

I get the following error on Windows, which causes pm2-logrotate to restart

TypeError: Cannot read property 'length' of undefined
    at C:\Users\panu\.pm2\node_modules\pm2-logrotate\app.js:28:32
    at FSReqWrap.oncomplete (fs.js:95:15)

Creating compressed log file each minute

Seems to be creating a new compressed .gz file every minute.

┌────────────────┬───────┐
│ key            │ value │
├────────────────┼───────┤
│ max_size       │ 25MB  │
│ compress       │ true  │
│ workerInterval │ 60    │
│ retain         │ 10    │
└────────────────┴───────┘

That's not what I expect. I'd expect pm2-logrotate to check files every minute, but only create and compress when it reaches 25MB keeping 10 versions.

-rw-r--r-- 1 node node    0 Mar 26 01:19 blog.mydomain.net-error.log
-rw-r--r-- 1 node node 5.1K Mar 26 07:28 blog.mydomain.net-out__2017-03-26_07-28-11.log.gz
-rw-r--r-- 1 node node  346 Mar 26 07:29 blog.mydomain.net-out__2017-03-26_07-29-17.log.gz
-rw-r--r-- 1 node node  350 Mar 26 07:30 blog.mydomain.net-out__2017-03-26_07-30-17.log.gz
-rw-r--r-- 1 node node  136 Mar 26 07:31 blog.mydomain.net-out__2017-03-26_07-31-17.log.gz
-rw-r--r-- 1 node node  133 Mar 26 07:32 blog.mydomain.net-out__2017-03-26_07-32-17.log.gz
-rw-r--r-- 1 node node  134 Mar 26 07:33 blog.mydomain.net-out__2017-03-26_07-33-17.log.gz
-rw-r--r-- 1 node node  136 Mar 26 07:34 blog.mydomain.net-out__2017-03-26_07-34-17.log.gz
-rw-r--r-- 1 node node  137 Mar 26 07:35 blog.mydomain.net-out__2017-03-26_07-35-17.log.gz
-rw-r--r-- 1 node node  136 Mar 26 07:36 blog.mydomain.net-out__2017-03-26_07-36-17.log.gz
-rw-r--r-- 1 node node  135 Mar 26 07:37 blog.mydomain.net-out__2017-03-26_07-37-17.log.gz
-rw-r--r-- 1 node node  135 Mar 26 07:38 blog.mydomain.net-out__2017-03-26_07-38-17.log.gz
-rw-r--r-- 1 node node    0 Mar 26 07:38 blog.mydomain.net-out.log
-rw-r--r-- 1 node node    0 Mar 26 07:25 pm2-logrotate-error-1.log
-rw-r--r-- 1 node node   33 Mar 26 07:28 pm2-logrotate-out-1__2017-03-26_07-28-11.log.gz
-rw-r--r-- 1 node node  136 Mar 26 07:29 pm2-logrotate-out-1__2017-03-26_07-29-17.log.gz
-rw-r--r-- 1 node node  131 Mar 26 07:30 pm2-logrotate-out-1__2017-03-26_07-30-17.log.gz
-rw-r--r-- 1 node node  124 Mar 26 07:31 pm2-logrotate-out-1__2017-03-26_07-31-17.log.gz
-rw-r--r-- 1 node node  124 Mar 26 07:32 pm2-logrotate-out-1__2017-03-26_07-32-17.log.gz
-rw-r--r-- 1 node node  124 Mar 26 07:33 pm2-logrotate-out-1__2017-03-26_07-33-17.log.gz
-rw-r--r-- 1 node node  123 Mar 26 07:34 pm2-logrotate-out-1__2017-03-26_07-34-17.log.gz
-rw-r--r-- 1 node node  123 Mar 26 07:35 pm2-logrotate-out-1__2017-03-26_07-35-17.log.gz
-rw-r--r-- 1 node node  123 Mar 26 07:36 pm2-logrotate-out-1__2017-03-26_07-36-17.log.gz
-rw-r--r-- 1 node node  123 Mar 26 07:37 pm2-logrotate-out-1__2017-03-26_07-37-17.log.gz
-rw-r--r-- 1 node node  124 Mar 26 07:38 pm2-logrotate-out-1__2017-03-26_07-38-17.log.gz
-rw-r--r-- 1 node node  181 Mar 26 07:38 pm2-logrotate-out-1.log

Windows - system restart

Hi,

I have installed the pm2-logrotate and configured it in the windows environment. Everything works fine until I restart the system. After the reboot, I don't see the pm2-logrotate is running any more.
Please suggest what is the workaround.

Thanks

install globally

does it work if i install globally?

does it work with the log path listed in ecosystem.json?

Fast growing log files may be overwritten

The worker job is executed every 50 seconds and the rotated file name has a format of year-month-day-hour-minutes. This may lead to overwrite files is the worker starts in the first 10 seconds of the minute and the log file grows fast enough to exceed 'max_size'. As an example, if the worker is started at 10:00:05 and truncates a file, the worker will execute again at 10:00:55. If the file needs to be rotated again, it will get the same name and be overwritten.

Feature request: UTC option

We require all our log filename dates to be in utc. It's easy to patch the call to moment().format(..) as moment().utc().format(...) but it would be useful to have an option for this.

max_size on README

max_size... KB or MB?

e.g: pm2 set pm2-logrotate:max_size 1024 (1KB) pm2 set pm2-logrotate:interval_unit 'MM' (Months)

To:
e.g: pm2 set pm2-logrotate:max_size 1024 (1MB) pm2 set pm2-logrotate:interval_unit 'MM' (Months)

TypeError: "listener" argument must be a function

5|pm2-logr | at Socket.once (events.js:307:11)
5|pm2-logr | at Socket.connect (net.js:943:10)
5|pm2-logr | at Socket.connect (/usr/lib/node_modules/pm2/node_modules/async-listener/index.js:76:27)5|pm2-logr | at ReqSocket.Socket.connect (/home/ubuntu/.pm2/node_modules/pm2-axon/lib/sockets/sock.js
:295:8)
5|pm2-logr | at Object.InteractorDaemonizer.ping (/home/ubuntu/.pm2/node_modules/pm2/lib/Interactor/I
nteractorDaemonizer.js:52:7)
5|pm2-logr | at Object.InteractorDaemonizer.getInteractInfo (/home/ubuntu/.pm2/node_modules/pm2/lib/I
nteractor/InteractorDaemonizer.js:474:24)
5|pm2-logr | at new module.exports (/home/ubuntu/.pm2/node_modules/pm2/lib/API.js:124:12)
5|pm2-logr | at Object. (/home/ubuntu/.pm2/node_modules/pm2/index.js:11:18)
5|pm2-logr | at Module._compile (module.js:571:32)
5|pm2-logr | at Object.Module._extensions..js (module.js:580:10)
5|pm2-logr | TypeError: "listener" argument must be a function
5|pm2-logr | at Socket.once (events.js:307:11)
5|pm2-logr | at Socket.connect (net.js:943:10)
5|pm2-logr | at Socket.connect (/usr/lib/node_modules/pm2/node_modules/async-listener/index.js:76:27)
5|pm2-logr | at ReqSocket.Socket.connect (/home/ubuntu/.pm2/node_modules/pm2-axon/lib/sockets/sock.js
:295:8)
5|pm2-logr | at Object.InteractorDaemonizer.ping (/home/ubuntu/.pm2/node_modules/pm2/lib/Interactor/I
nteractorDaemonizer.js:52:7)
5|pm2-logr | at Object.InteractorDaemonizer.getInteractInfo (/home/ubuntu/.pm2/node_modules/pm2/lib/I
nteractor/InteractorDaemonizer.js:474:24)
5|pm2-logr | at new module.exports (/home/ubuntu/.pm2/node_modules/pm2/lib/API.js:124:12)
5|pm2-logr | at Object. (/home/ubuntu/.pm2/node_modules/pm2/index.js:11:18)
5|pm2-logr | at Module._compile (module.js:571:32)
5|pm2-logr | at Object.Module._extensions..js (module.js:580:10)

is_it_time_yet logic

Hi,
I fail to understand the logic in the code of "is_it_time_yet()" function. I'm reporting it here:

119 function is_it_time_yet() { 
120   var max_value = INTERVAL_UNIT == 'MM' ? 12 : 60; 
121 
122   if (NOW + INTERVAL == parseInt(moment().format(INTERVAL_UNIT)) 
123       || NOW + INTERVAL == parseInt(moment().format(INTERVAL_UNIT)) - max_value) { 
124     NOW = parseInt(moment().format(INTERVAL_UNIT)); 
125     return true; 
126   } 
127   else { 
128     return false; 
129   } 
130 } 

Line 120: if the unit is 'dd' (i.e. days) max value should not be 60.
Line 123: I fail to understand what's happening there. I suppose it is a try to handle overflows in the sum of now and interval, but it seems to me it is not working at all..
Let's suppose INTERVAL_UNIT is 'MM' (i.e. months) and INTERVAL is 1. In this case, NOW will be in range [1,12] so NOW + INTERVAL will be in range [2,13]. parseInt(moment().format(INTERVAL_UNIT)) is in range [1,12] and subtracting 12 will move it to range [-11, 0]. I don't think that the equal operator will ever be true.

Since you are using moment.js, my suggestion is to use ".diff" or durations.

Delete compressed logs

Hi,

I would like to know if it is possible to delete the compressed files with post rotate script or something similar to that.
My problem is that I have small disk space and it's getting full quickly.

Thanks

Continuously written log files corrupted using compression option

Having tried the compression option, we have had to disable it and implement separate gzipping logic.

Our log files are continuously written to, which meant the gzipped file was continuously written to as pm2-logrotate compression is implemented using pipes.

The current implementation seems broken, since when log files were renamed the resulting gzip files were truncated mid-gzip-stream. gunzipping them resulted in errors, and log files with truncated final lines.

A better implementation could be to write uncompressed logs, and gzip completed log files after their rotation.

pm2 show logrotate errored on Windows Server 2012 x64, Node v4.1.1

Environment:
Windows Server 2012 x64, Node 4.1.1
pm2 is fresh installed
logrotate is fresh installed
No other app running

When run "pm2 show logrotate" will see the status "errored". In the log file of logrotate has the following error around 15 times.


Error:  required
    at Object. (C:\Users\mick\.pm2\node_modules\logrotate\bin\rotate:38:26)
    at Module._compile (module.js:434:26)
    at Object.Module._extensions..js (module.js:452:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Function._load (C:\Users\mick\AppData\Roaming\npm\node_modules\pm2\node_modules\pmx\lib\transaction.js:62:21)
    at Object. (C:\Users\mick\AppData\Roaming\npm\node_modules\pm2\lib\ProcessContainerFork.js:28:21)
    at Module._compile (module.js:434:26)
    at Object.Module._extensions..js (module.js:452:10)
    at Module.load (module.js:355:32)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.