1- /*eslint no-invalid-this: 0 no-console: 0 */
1+ /*eslint no-invalid-this: 0 */
22'use strict' ;
33const co = require ( 'co' ) ;
44const cosql = require ( 'co-mssql' ) ;
5+ const logger = require ( '@elastic.io/component-logger' ) ( ) ;
56
67let pstmt ;
78
@@ -26,18 +27,18 @@ function init(cfg) {
2627 + cfg . database
2728 + ( ( cfg . domain ) ? '?domain=' + cfg . domain + '&encrypt=' + cfg . encrypt
2829 : '?encrypt=' + cfg . encrypt ) ;
29- console . log ( conString ) ;
30+ logger . trace ( conString ) ;
3031 return co ( function * gen ( ) {
31- console . log ( 'Connecting to the database' ) ;
32+ logger . info ( 'Connecting to the database' ) ;
3233 const connection = new cosql . Connection ( conString ) ;
3334 // Always attach an error listener
3435 connection . on ( 'error' , ( err ) => this . emit ( 'error' , err ) ) ;
3536 let sql = cfg . query ;
3637 yield connection . connect ( ) ;
37- console . log ( 'Connection established' ) ;
38- console . log ( 'Preparing query=%s' , sql ) ;
38+ logger . info ( 'Connection established' ) ;
39+ logger . trace ( 'Preparing query=%s' , sql ) ;
3940 const vars = sql . match ( VARS_REGEXP ) ;
40- console . log ( 'Found following prepared variable:type pairs=%j' , vars ) ;
41+ logger . trace ( 'Found following prepared variable:type pairs=%j' , vars ) ;
4142 pstmt = new cosql . PreparedStatement ( connection ) ;
4243 for ( const tuple of vars ) {
4344 const [ placeholder , type ] = tuple . split ( ':' ) ;
@@ -69,14 +70,14 @@ function init(cfg) {
6970 pstmt . input ( name , cosql . BigInt ) ;
7071 break ;
7172 default :
72- console . log ( 'WARNING: Can figure out the type key=%s type=%s' , name , type ) ;
73+ logger . warn ( 'WARNING: Can figure out the type key=%s type=%s' , name , type ) ;
7374 }
7475 // Now let's remove all :string :boolean :date etc to the name only
7576 sql = sql . replace ( tuple , placeholder ) ;
7677 }
77- console . log ( 'Resulting SQL=%s' , sql ) ;
78+ logger . trace ( 'Resulting SQL=%s' , sql ) ;
7879 yield pstmt . prepare ( sql ) ;
79- console . log ( 'Preparing statement created' ) ;
80+ logger . info ( 'Preparing statement created' ) ;
8081 } . bind ( this ) ) ;
8182}
8283
@@ -132,10 +133,11 @@ function getMetaModel(cfg, cb) {
132133 * @param cfg configuration that is account information and configuration field values
133134 */
134135function processAction ( msg ) {
136+ const that = this ;
135137 return co ( function * gen ( ) {
136- console . log ( 'Executing statement' ) ;
138+ that . logger . info ( 'Executing statement' ) ;
137139 yield pstmt . execute ( msg . body ) ;
138- console . log ( 'Execution completed' ) ;
140+ that . logger . info ( 'Execution completed' ) ;
139141 return msg ;
140142 } . bind ( this ) ) ;
141143}
0 commit comments