@@ -35,6 +35,53 @@ class Engine {
3535 this . servicesMonitor . addCheck ( 'embarkVersion' , function ( cb ) {
3636 return cb ( { name : 'Embark ' + self . version , status : 'on' } ) ;
3737 } , 0 ) ;
38+
39+ if ( this . interceptLogs || this . interceptLogs === undefined ) {
40+ this . doInterceptLogs ( ) ;
41+ }
42+ }
43+
44+ doInterceptLogs ( ) {
45+ var self = this ;
46+ let context = { } ;
47+ context . console = console ;
48+
49+ let normalizeInput = function ( input ) {
50+ let args = Object . values ( input ) ;
51+ if ( args . length === 0 ) {
52+ return "" ;
53+ }
54+ if ( args . length === 1 ) {
55+ if ( Array . isArray ( args [ 0 ] ) ) { return args [ 0 ] . join ( ',' ) ; }
56+ return args [ 0 ] || "" ;
57+ }
58+ return ( '[' + args . map ( ( x ) => {
59+ if ( x === null ) { return "null" ; }
60+ if ( x === undefined ) { return "undefined" ; }
61+ if ( Array . isArray ( x ) ) { return x . join ( ',' ) ; }
62+ return x ;
63+ } ) . toString ( ) + ']' ) ;
64+ } ;
65+
66+ context . console . log = function ( ) {
67+ self . logger . info ( normalizeInput ( arguments ) ) ;
68+ } ;
69+ context . console . warn = function ( ) {
70+ self . logger . warn ( normalizeInput ( arguments ) ) ;
71+ } ;
72+ context . console . info = function ( ) {
73+ self . logger . info ( normalizeInput ( arguments ) ) ;
74+ } ;
75+ context . console . debug = function ( ) {
76+ // TODO: ue JSON.stringify
77+ self . logger . debug ( normalizeInput ( arguments ) ) ;
78+ } ;
79+ context . console . trace = function ( ) {
80+ self . logger . trace ( normalizeInput ( arguments ) ) ;
81+ } ;
82+ context . console . dir = function ( ) {
83+ self . logger . dir ( normalizeInput ( arguments ) ) ;
84+ } ;
3885 }
3986
4087 startMonitor ( ) {
0 commit comments