* Description * @method exec * @param {} script * @param {} stds * @return
(script, stds)
| 110 | * @return |
| 111 | */ |
| 112 | function exec(script, stds) { |
| 113 | if (p.extname(script) == '.ts' || p.extname(script) == '.tsx') { |
| 114 | try { |
| 115 | require('ts-node/register'); |
| 116 | } catch (e) { |
| 117 | console.error('Failed to load Typescript interpreter:', e.message || e); |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | process.on('message', function (msg) { |
| 122 | if (msg.type === 'log:reload') { |
| 123 | for (var k in stds){ |
| 124 | if (typeof stds[k] == 'object' && !isNaN(stds[k].fd)){ |
| 125 | if (stds[k].destroy) stds[k].destroy(); |
| 126 | else if (stds[k].end) stds[k].end(); |
| 127 | else if (stds[k].close) stds[k].close(); |
| 128 | stds[k] = stds[k]._file; |
| 129 | } |
| 130 | } |
| 131 | Utility.startLogging(stds, function (err) { |
| 132 | if (err) |
| 133 | return console.error('Failed to reload logs:', err.stack); |
| 134 | console.log('Reloading log...'); |
| 135 | }); |
| 136 | } |
| 137 | }); |
| 138 | |
| 139 | var dayjs = null; |
| 140 | |
| 141 | if (pm2_env.log_date_format) |
| 142 | dayjs = require('dayjs'); |
| 143 | |
| 144 | Utility.startLogging(stds, function (err) { |
| 145 | if (err) { |
| 146 | process.send({ |
| 147 | type : 'process:exception', |
| 148 | data : { |
| 149 | message: err.message, |
| 150 | syscall: 'ProcessContainer.startLogging' |
| 151 | } |
| 152 | }); |
| 153 | throw err; |
| 154 | return; |
| 155 | } |
| 156 | |
| 157 | process.stderr.write = (function(write) { |
| 158 | return function(string, encoding, cb) { |
| 159 | var log_data = null; |
| 160 | |
| 161 | // Disable logs if specified |
| 162 | if (pm2_env.disable_logs === true) { |
| 163 | return cb ? cb() : false; |
| 164 | } |
| 165 | |
| 166 | if (pm2_env.log_type && pm2_env.log_type === 'json') { |
| 167 | log_data = JSON.stringify({ |
| 168 | message : string.toString(), |
| 169 | timestamp : pm2_env.log_date_format && dayjs ? |
no test coverage detected
searching dependent graphs…