Commit 6a6998f9c593e155e99121479d2f4da5610e99e2
1 parent
f8fc782a2e
Exists in
master
Add xid on some logs at http-listener
Showing 1 changed file with 21 additions and 4 deletions Side-by-side Diff
lib/http-listener.js
1 | +const MODULE_NAME = 'HTTP-LISTENER'; | |
2 | + | |
1 | 3 | const express = require('express'); |
2 | 4 | const ipfilter = require('express-ipfilter').IpFilter; |
3 | 5 | const removeAccents = require('remove-accents'); |
6 | +const uniqid = require('uniqid'); | |
4 | 7 | |
5 | 8 | const config = require('komodo-sdk/config'); |
6 | 9 | const logger = require('tektrans-logger'); |
... | ... | @@ -32,6 +35,14 @@ const port = (config && config.listener && config.listener.http |
32 | 35 | function mainHandler(req, res) { |
33 | 36 | if (!req.body) req.body = {}; |
34 | 37 | |
38 | + const xid = uniqid(); | |
39 | + | |
40 | + logger.verbose(`${MODULE_NAME} 72AFD326: Got a request`, { | |
41 | + xid, | |
42 | + query: req.query, | |
43 | + body: req.body, | |
44 | + }); | |
45 | + | |
35 | 46 | if ( |
36 | 47 | (!req.body.partner && !req.query.partner) |
37 | 48 | && ( |
... | ... | @@ -39,7 +50,8 @@ function mainHandler(req, res) { |
39 | 50 | || ((req.query.is_outgoing || req.body.is_outgoing) && !req.query.to && !req.body.to) |
40 | 51 | ) |
41 | 52 | ) { |
42 | - logger.warn('Undefined parameter partner or from or to. #D254B7B454DB', { | |
53 | + logger.warn(`${MODULE_NAME} D254B7B454DB: Undefined parameter partner or from or to`, { | |
54 | + xid, | |
43 | 55 | partner: req.body.partner || req.query.partner, |
44 | 56 | is_outgoing: req.body.is_outgoing || req.query.is_outgoing, |
45 | 57 | from: req.body.from || req.query.from, |
... | ... | @@ -51,17 +63,21 @@ function mainHandler(req, res) { |
51 | 63 | |
52 | 64 | // message cleansing |
53 | 65 | const msg = removeAccents(req.query.msg || req.body.msg || '') |
54 | - .replace(/[\u{0080}-\u{FFFF}]/gu, '').trim(); | |
66 | + .replace(/[\u{0080}-\u{FFFF}]/gu, '') | |
67 | + .trim(); | |
55 | 68 | |
56 | 69 | if (!msg) { |
57 | - logger.warn('Undefined parameter msg. #92996A497D12'); | |
58 | - res.end('ERROR. Undefined parameter: msg'); | |
70 | + logger.warn(`${MODULE_NAME} #92996A497D12: Undefined parameter msg`, { | |
71 | + xid, | |
72 | + }); | |
73 | + res.end(`ERROR. Undefined parameter: msg. XID: ${xid}`); | |
59 | 74 | return; |
60 | 75 | } |
61 | 76 | |
62 | 77 | logger.verbose( |
63 | 78 | `Saving ${req.body.is_outgoing || req.query.is_outgoing ? 'outgoing' : 'incoming'} message history`, |
64 | 79 | { |
80 | + xid, | |
65 | 81 | transport: req.body.origin_transport || req.query.origin_transport, |
66 | 82 | partner: req.body.partner || req.query.partner || req.body.from || req.query.from |
67 | 83 | || req.body.to || req.query.to, |
... | ... | @@ -89,6 +105,7 @@ function mainHandler(req, res) { |
89 | 105 | || req.body.is_outgoing || req.query.is_outgoing |
90 | 106 | ) { |
91 | 107 | logger.verbose('Ignoring message', { |
108 | + xid, | |
92 | 109 | from: req.body.from || req.query.from, |
93 | 110 | msg, |
94 | 111 | do_not_forward_to_core: req.body.do_not_forward_to_core |