MCPcopy
hub / github.com/foreversd/forever / tailProcess

Function tailProcess

lib/forever.js:626–666  ·  view source on GitHub ↗
(procs, next)

Source from the content-addressed store, hash-verified

624 if (stream) { args.unshift('-f'); }
625
626 function tailProcess(procs, next) {
627 let count = 0;
628 const map = {};
629
630 procs.forEach(function (proc) {
631 args.push(proc.logFile);
632 map[proc.logFile] = { pid: proc.pid, file: proc.file };
633 count++;
634 });
635
636 const tail = spawn('tail', args, {
637 stdio: [null, 'pipe', 'pipe'],
638 });
639
640 tail.stdio[1].setEncoding('utf8');
641 tail.stdio[2].setEncoding('utf8');
642
643 tail.stdio[1].on('data', function (data) {
644 const chunk = data.split("\n\n");
645 chunk.forEach(function (logs) {
646 const filteredLogs = logs.split("\n").filter(blanks),
647 file = filteredLogs.filter(title);
648
649 const proc = file.length
650 ? map[file[0].split(' ')[1]]
651 : map[procs[0].logFile];
652
653 const lines = count !== 1
654 ? filteredLogs.slice(1)
655 : filteredLogs;
656
657 lines.forEach(function (line) {
658 callback(null, { file: proc.file, pid: proc.pid, line: line });
659 });
660 });
661 });
662
663 tail.stdio[2].on('data', function (err) {
664 return callback(err);
665 });
666 }
667
668 getAllProcesses(function (err, processes) {
669 if (err) {

Callers 1

forever.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected