Commit 18ee66245d5320e60fb96d42abd07849291e3eaa
1 parent
bdcea0edf1
Exists in
master
logging
Showing 3 changed files with 37 additions and 13 deletions Side-by-side Diff
index.js
1 | 1 | var iniparser = require('iniparser'); |
2 | 2 | var config = iniparser.parseSync('./config.ini'); |
3 | 3 | |
4 | +var logger = require('sate24/logger.js').start(); | |
5 | + | |
4 | 6 | var aaaHost = config.globals.aaa_host; |
5 | 7 | |
6 | 8 | HttpServer = require('sate24/httpserver.js'); |
7 | -var httpServer = HttpServer.start(config); | |
9 | +var httpServer = HttpServer.start(config, {logger: logger}); | |
8 | 10 | |
9 | 11 | var aaa = require('sate24/aaa.js'); |
12 | +HttpServer.setAaa(aaa); | |
13 | + | |
10 | 14 | var partner = require('./partner-scrappingkisel.js'); |
11 | 15 | |
12 | -partner.start(config, aaa.callbackReport); | |
13 | -aaa.start(config, partner); | |
16 | +var partner_options = { | |
17 | + 'aaa': aaa, | |
18 | + 'logger': logger | |
19 | +} | |
20 | + | |
21 | +partner.start(config, aaa.callbackReport, partner_options); | |
22 | +aaa.start(config, partner, {logger: logger}); |
package.json
... | ... | @@ -29,6 +29,7 @@ |
29 | 29 | "xmlrpc": "~1.3.1", |
30 | 30 | "xml2js": "~0.4.9", |
31 | 31 | "node-simple-router": "~0.9.4-2", |
32 | - "sate24": "git+http://git@gitlab.kodesumber.com/reload97/node-sate24.git" | |
32 | + "sate24": "git+http://git@gitlab.kodesumber.com/reload97/node-sate24.git", | |
33 | + "winston": "~1.0.2" | |
33 | 34 | } |
34 | 35 | } |
partner-scrappingkisel.js
... | ... | @@ -6,9 +6,10 @@ var request = require('request'); |
6 | 6 | var xml2js = require('xml2js').parseString; |
7 | 7 | var strftime = require('strftime'); |
8 | 8 | var math = require('mathjs'); |
9 | +var winston = require('winston'); | |
9 | 10 | |
10 | 11 | var config; |
11 | -var httpServer; | |
12 | +var logger; | |
12 | 13 | |
13 | 14 | process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'; |
14 | 15 | |
... | ... | @@ -41,7 +42,7 @@ function topupRequest(task) { |
41 | 42 | product: task['remoteProduct'] |
42 | 43 | } |
43 | 44 | }; |
44 | - console.log(options); | |
45 | + logger.info('HTTP request to partner', {request_options: options}); | |
45 | 46 | |
46 | 47 | request(options, function (error, response, body) { |
47 | 48 | if (config.globals.active_requests_count == undefined) { |
... | ... | @@ -51,13 +52,12 @@ function topupRequest(task) { |
51 | 52 | } |
52 | 53 | |
53 | 54 | if (error || response.statusCode != 200) { |
54 | - console.log(logTag + ': Gateway Error'); | |
55 | + logger.warn(logTag + ': Gateway Error'); | |
55 | 56 | callbackReport(task['requestId'], '40', 'Gateway Error'); |
56 | 57 | return; |
57 | 58 | } |
58 | 59 | |
59 | - console.log(logTag + ': Supplier response:'); | |
60 | - console.log(body); | |
60 | + logger.info('Got supplier response', {response_body: body}); | |
61 | 61 | |
62 | 62 | xml2js(body, function (err, result) { |
63 | 63 | if (err) { |
... | ... | @@ -65,7 +65,7 @@ function topupRequest(task) { |
65 | 65 | return; |
66 | 66 | } |
67 | 67 | |
68 | - console.log(result); | |
68 | + logger.info('Got result from partner', {result: result}); | |
69 | 69 | |
70 | 70 | var response_code = '68'; |
71 | 71 | var message = result.trx_response.info[0].trim(); |
... | ... | @@ -113,7 +113,7 @@ function topupRequest(task) { |
113 | 113 | var stock = parseStock(stocks, product); |
114 | 114 | |
115 | 115 | if (stock == 0) { |
116 | - console.log('OUT OF STOCK: ' + task['product']); | |
116 | + logger.info('OUT OF STOCK: ' + task['product']); | |
117 | 117 | config.globals.products = productsWithout(task['product']); |
118 | 118 | } |
119 | 119 | |
... | ... | @@ -122,7 +122,7 @@ function topupRequest(task) { |
122 | 122 | message = 'SN=' + kode_voucher + '; ' + product + ' ' + destination + ' ' + harga + ' ref_num: ' + ref_num + ' kode_voucher: ' + kode_voucher + ' sisa stock: ' + stock + ' unit'; |
123 | 123 | } |
124 | 124 | |
125 | - console.log('Message to AAA: ' + message); | |
125 | + logger.info('Message to AAA: ' + message); | |
126 | 126 | callbackReport(task['requestId'], response_code, message); |
127 | 127 | }); |
128 | 128 | }); |
... | ... | @@ -130,7 +130,21 @@ function topupRequest(task) { |
130 | 130 | |
131 | 131 | function start(_config, _callbackReport) { |
132 | 132 | config = _config; |
133 | - callbackReport = _callbackReport | |
133 | + callbackReport = _callbackReport; | |
134 | + | |
135 | + if (options && options.aaa) { | |
136 | + aaa = options.aaa; | |
137 | + } | |
138 | + | |
139 | + if (options && options.logger) { | |
140 | + logger = options.logger; | |
141 | + } else { | |
142 | + logger = new winston.Logger({ | |
143 | + transports: [ | |
144 | + new (winston.transports.Console)() | |
145 | + ] | |
146 | + }); | |
147 | + } | |
134 | 148 | } |
135 | 149 | |
136 | 150 | function stockKeyword(product_desc) { |