* Description * @method exec * @param {} script * @param {} stds * @return
(script, stds)
| 105 | * @return |
| 106 | */ |
| 107 | function exec(script, stds) { |
| 108 | process.on('message', function (msg) { |
| 109 | if (msg.type === 'log:reload') { |
| 110 | for (var k in stds){ |
| 111 | if (typeof stds[k] == 'object' && !isNaN(stds[k].fd)){ |
| 112 | if (stds[k].destroy) stds[k].destroy(); |
| 113 | else if (stds[k].end) stds[k].end(); |
| 114 | else if (stds[k].close) stds[k].close(); |
| 115 | stds[k] = stds[k]._file; |
| 116 | } |
| 117 | } |
| 118 | Utility.startLogging(stds, function (err) { |
| 119 | if (err) |
| 120 | return console.error('Failed to reload logs:', err.stack); |
| 121 | console.log('Reloading log...'); |
| 122 | }); |
| 123 | } |
| 124 | }); |
| 125 | |
| 126 | var dayjs = null; |
| 127 | |
| 128 | if (pm2_env.log_date_format) |
| 129 | dayjs = require('dayjs'); |
| 130 | |
| 131 | Utility.startLogging(stds, function (err) { |
| 132 | if (err) { |
| 133 | process.send({ |
| 134 | type : 'process:exception', |
| 135 | data : { |
| 136 | message: err.message, |
| 137 | syscall: 'ProcessContainer.startLogging' |
| 138 | } |
| 139 | }); |
| 140 | throw err; |
| 141 | return; |
| 142 | } |
| 143 | |
| 144 | ['warn', 'error'].forEach((method) => { |
| 145 | console[method] = (...args) => { |
| 146 | let log_data = null; |
| 147 | |
| 148 | const msg = util.format(...args); |
| 149 | |
| 150 | if (pm2_env.disable_logs === true) { |
| 151 | return false; |
| 152 | } |
| 153 | |
| 154 | if (pm2_env.log_type && pm2_env.log_type === 'json') { |
| 155 | log_data = JSON.stringify({ |
| 156 | message : msg, |
| 157 | timestamp : pm2_env.log_date_format && dayjs ? |
| 158 | dayjs().format(pm2_env.log_date_format) : new Date().toISOString(), |
| 159 | type : 'err', |
| 160 | process_id : pm2_env.pm_id, |
| 161 | app_name : pm2_env.name |
| 162 | }) + '\n'; |
| 163 | } |
| 164 | else if (pm2_env.log_date_format && dayjs) |
no test coverage detected
searching dependent graphs…