@@ -482,13 +482,10 @@ class ServerlessWSGI {
482
482
// remotely, we get a string back and we want it to appear in the console as it would have
483
483
// if it was invoked locally.
484
484
//
485
- // Thus, console.log is temporarily hijacked to capture the output and parse it as JSON. This
486
- // hack is needed to avoid having to call the provider-specific invoke plugins .
485
+ // We capture stdout output in order to parse the array returned from the lambda invocation,
486
+ // then restore stdout .
487
487
let output = "" ;
488
488
489
- /* eslint-disable no-console */
490
- const native_log = console . log ;
491
- console . log = ( msg ) => ( output += msg + "\n" ) ;
492
489
/* eslint-disable no-unused-vars */
493
490
const {
494
491
originalStdoutWrite, // Original `write` bound to `process.stdout`#noqa
@@ -500,9 +497,7 @@ class ServerlessWSGI {
500
497
orig , // data input
501
498
originalStdoutWrite // // Original `write` bound to `process.stdout`
502
499
) => {
503
- // Example of filtering ANSI codes for original stdout.write
504
- originalStdoutWrite ( orig . replace ( / [ " ] + / g, "" ) . replace ( / \\ n / g, "\n" ) ) ;
505
- // originalStdoutWrite(orig.substring(orig.indexOf(",") + 7).replace(/\\n/g,"\n") + "\n");
500
+ output += orig ;
506
501
}
507
502
) ;
508
503
/* eslint-enable no-unused-vars */
@@ -525,18 +520,18 @@ class ServerlessWSGI {
525
520
? _ . trimEnd ( output [ 1 ] , "\n" )
526
521
: output [ 1 ] ;
527
522
if ( return_code == 0 ) {
528
- native_log ( output_data ) ;
523
+ this . serverless . cli . log ( output_data ) ;
529
524
} else {
530
- return reject ( output_data ) ;
525
+ return reject ( new this . serverless . classes . Error ( output_data ) ) ;
531
526
}
532
527
} else {
533
- native_log ( output ) ;
528
+ this . serverless . cli . log ( output ) ;
534
529
}
535
530
return resolve ( ) ;
536
531
} )
537
532
)
538
533
. finally ( ( ) => {
539
- console . log = native_log ;
534
+ restoreStdoutWrite ( ) ;
540
535
} ) ;
541
536
/* eslint-enable no-console */
542
537
}
0 commit comments