@@ -7,6 +7,7 @@ const http = require('http');
77const ps = require ( 'ps-node' ) ;
88const globalManager = require ( './globalManager' ) ;
99const { encryptTextSimple } = require ( './filescript/helpers' ) ;
10+ const logger = require ( './logger' ) ;
1011
1112const ALICE_PROJECT_NAME = 'criptext-encryption-service' ;
1213
@@ -127,13 +128,13 @@ const handShake = ({ alicePath, dbpath, myPort, logspath, onAppOpened }) => {
127128 'Service Error' ,
128129 `Unable to initialize encryption service. ${ data } `
129130 ) ;
130- console . log ( `-----alice-----\nError:\n${ data } \n -----end-----` ) ;
131+ logger . error ( `-----alice-----\nError:\n${ data } \n -----end-----` ) ;
131132 if ( onAppOpened ) app . quit ( ) ;
132133 } ) ;
133134 alice . stdout . setEncoding ( 'utf8' ) ;
134135 alice . stdout . on ( 'data' , async data => {
135136 if ( ! passwordRegex . test ( data ) ) {
136- console . log ( `-----alice-----\n${ data } \n -----end-----` ) ;
137+ logger . debug ( `-----alice-----\n${ data } \n -----end-----` ) ;
137138 return ;
138139 }
139140 token = data . replace ( passwordRegex , '' ) . replace ( / \r ? \n | \r / g, '' ) ;
@@ -145,17 +146,17 @@ const handShake = ({ alicePath, dbpath, myPort, logspath, onAppOpened }) => {
145146 }
146147 } ) ;
147148 alice . on ( 'exit' , ( code , signal ) => {
148- console . log ( `alice exited with code ${ code } and signal ${ signal } ` ) ;
149+ logger . error ( `alice exited with code ${ code } and signal ${ signal } ` ) ;
150+ closeAlice ( ) ;
149151 if ( signal !== 'SIGTERM' && signal !== 'SIGABRT' ) {
150- closeAlice ( ) ;
151152 reject ( ) ;
152153 return ;
153154 }
154155 reject ( { retry : true } ) ;
155156 } ) ;
156157
157158 alice . on ( 'close' , code => {
158- console . log ( `alice closed with code ${ code } ` ) ;
159+ logger . info ( `alice closed with code ${ code } ` ) ;
159160 closeAlice ( ) ;
160161 reject ( ) ;
161162 } ) ;
@@ -208,20 +209,20 @@ const isReachable = () => {
208209 return ;
209210 }
210211 const req = http . request ( options , res => {
211- console . log ( `statusCode: ${ res . statusCode } ` ) ;
212+ logger . info ( `statusCode: ${ res . statusCode } ` ) ;
212213 resolve ( res . statusCode === 200 ) ;
213214 } ) ;
214215
215216 req . on ( 'error' , error => {
216- console . log ( error ) ;
217+ logger . error ( error ) ;
217218 resolve ( false ) ;
218219 } ) ;
219220 try {
220221 const data = await encryptTextSimple ( getPassword ( ) , token ) ;
221222 req . write ( JSON . stringify ( data ) ) ;
222223 req . end ( ) ;
223224 } catch ( ex ) {
224- console . log ( ex ) ;
225+ logger . error ( ex ) ;
225226 resolve ( false ) ;
226227 }
227228 } ) ;
@@ -252,11 +253,10 @@ const cleanAliceRemenants = () => {
252253 return new Promise ( resolve => {
253254 ps . lookup ( { command : ALICE_PROJECT_NAME } , async ( err , list ) => {
254255 if ( err ) {
255- console . log ( err ) ;
256+ logger . error ( err ) ;
256257 resolve ( ) ;
257258 return ;
258259 }
259- console . log ( list ) ;
260260 await Promise . all (
261261 list . map ( p => {
262262 return killPs ( p . pid ) ;
0 commit comments