Commit 05183f065165a00db66b36db2ee03aaa4caf0434
1 parent
449b0a7c
Exists in
master
and in
1 other branch
update log
Showing
2 changed files
with
123 additions
and
0 deletions
Show diff stats
ais-structure/src/config/express.js
| ... | ... | @@ -209,6 +209,10 @@ module.exports = function () { |
| 209 | 209 | return res.resBody?res.resBody:'' ; |
| 210 | 210 | }) |
| 211 | 211 | |
| 212 | + app.use( function( req, res, next ) { | |
| 213 | + log.startEC(req); | |
| 214 | + next(); | |
| 215 | +} ); | |
| 212 | 216 | |
| 213 | 217 | // app.use(morgan('IP|:remote-ip|USER|:user-id|REQUESTID|:id|METHOD|:method|URI|:uri|REQUESTBODY|:json|RESPSTATUS|:status|RESPBODY|:resp-body|RESPTIME|:response-time', { |
| 214 | 218 | // "stream": logger.stream |
| ... | ... | @@ -279,6 +283,8 @@ module.exports = function () { |
| 279 | 283 | { |
| 280 | 284 | res.status(200).json(responseMsg.unknow(req)); |
| 281 | 285 | } |
| 286 | + | |
| 287 | + log.endEC(res); | |
| 282 | 288 | next(); |
| 283 | 289 | } ); |
| 284 | 290 | ... | ... |
ais-structure/src/modules/helper/log.js
| ... | ... | @@ -14,6 +14,7 @@ var logger = []; |
| 14 | 14 | var summaryList = []; |
| 15 | 15 | var start = {}; |
| 16 | 16 | var detail = {}; |
| 17 | +var startTime; | |
| 17 | 18 | |
| 18 | 19 | logger.stat = function (msg){ |
| 19 | 20 | logg.stat(msg); |
| ... | ... | @@ -170,7 +171,123 @@ var undefinedToNull = function(data){ |
| 170 | 171 | return data; |
| 171 | 172 | } |
| 172 | 173 | |
| 174 | +logger.startEC = function(req) | |
| 175 | +{ | |
| 176 | + var newLine = "\r\n"; | |
| 177 | + var messageRes = ''; | |
| 178 | + startTime = new Date(); | |
| 179 | + | |
| 180 | + // if(!mapTime[req.headers.host]) | |
| 181 | + // { | |
| 182 | + // mapTime[req.headers.host] | |
| 183 | + // } | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + // console.log(Object.keys(req)); | |
| 188 | + // console.log(req.headers); | |
| 189 | + // console.log(req.body); | |
| 190 | + | |
| 191 | + if(req.body) | |
| 192 | + { | |
| 193 | + if(typeof req.body === 'string') | |
| 194 | + body = req.bod; | |
| 195 | + else | |
| 196 | + body = JSON.stringify(req.body); | |
| 197 | + } | |
| 198 | + | |
| 199 | + var header = ""; | |
| 200 | + if(req.headers) | |
| 201 | + { | |
| 202 | + if(typeof req.headers === 'string') | |
| 203 | + header = req.headers; | |
| 204 | + else | |
| 205 | + header = JSON.stringify(req.headers); | |
| 206 | + } | |
| 207 | + | |
| 208 | + messageRes += newLine+newLine+"#====> Incoming Message <====# "; | |
| 209 | + messageRes += newLine+"Header : "+header; | |
| 210 | + messageRes += newLine+"Body : "+body; | |
| 211 | + messageRes += newLine+"Time in : "+startTime.toISOString(); | |
| 212 | + messageRes += newLine | |
| 173 | 213 | |
| 214 | + logger.log(messageRes); | |
| 215 | +}; | |
| 216 | + | |
| 217 | +logger.endEC = function(res) | |
| 218 | +{ | |
| 219 | + | |
| 220 | + var newLine = "\r\n"; | |
| 221 | + var messageRes = ''; | |
| 222 | + var endTime = new Date(); | |
| 223 | + | |
| 224 | + | |
| 225 | + var body = ""; | |
| 226 | + if(res.resBody) | |
| 227 | + { | |
| 228 | + if(typeof res.resBody === 'string') | |
| 229 | + body = res.resBody; | |
| 230 | + else | |
| 231 | + body = JSON.stringify(res.resBody); | |
| 232 | + } | |
| 233 | + | |
| 234 | + var header = ""; | |
| 235 | + if(res.req.headers) | |
| 236 | + { | |
| 237 | + if(typeof res.req.headers === 'string') | |
| 238 | + header = res.req.headers; | |
| 239 | + else | |
| 240 | + header = JSON.stringify(res.req.headers); | |
| 241 | + } | |
| 242 | + | |
| 243 | + messageRes += newLine+newLine+"#====> Outgoing Message <====# "; | |
| 244 | + messageRes += newLine+"Header : "+header; | |
| 245 | + messageRes += newLine+"Body : "+body; | |
| 246 | + messageRes += newLine+"Time out : "+endTime.toISOString(); | |
| 247 | + messageRes += newLine+"Use times : "+Math.abs(endTime - startTime)+" ms"; | |
| 248 | + | |
| 249 | + | |
| 250 | + messageRes += ` | |
| 251 | + ________________________________________________________________________________________________________________________ | |
| 252 | + __________#####___________________________________#####___________________________________#####_________________________ | |
| 253 | + _________##____#_________________________________##____#_________________________________##____#________________________ | |
| 254 | + ________##______#_______________________________##______#_______________________________##______#_______________________ | |
| 255 | + ________#________#______________________________#________#______________________________#________#______________________ | |
| 256 | + _________________#######_________________________________#######_________________________________#######________________ | |
| 257 | + _________________#########_______________________________#########_______________________________#########______________ | |
| 258 | + __________##_____###########______________________##_____###########______________________##_____###########____________ | |
| 259 | + ___________#_____#############_____________________#_____#############_____________________#_____#############__________ | |
| 260 | + _________________##############___###____________________##############___###____________________##############___###___ | |
| 261 | + _______##________###############_##_##_________##________###############_##_##_________##________###############_##_##__ | |
| 262 | + ______###_______#################____#________###_______#################____#________###_______#################____#__ | |
| 263 | + ____#######___##________#########____#______#######___##________#########____#______#######___##________#########____#__ | |
| 264 | + ___#___####___#______________###_____#_____#___####___#______________###_____#_____#___####___#______________###_____#__ | |
| 265 | + ___#___##______#__#__________________#_____#___##______#__#__________________#_____#___##______#__#__________________#__ | |
| 266 | + ___#_________________________________#_____#_________________________________#_____#_________________________________#__ | |
| 267 | + ___#______________##_________________#_____#______________##_________________#_____#______________##_________________#__ | |
| 268 | + __#___________#_________________#___#_____#___________#_________________#___#_____#___________#_________________#___#___ | |
| 269 | + ___#__________#________________###__#______#__________#________________###__#______#__________#________________###__#___ | |
| 270 | + ____##_______#_________________#_###________##_______#_________________#_###________##_______#_________________#_###____ | |
| 271 | + _____#________________________##_____________#________________________##_____________#________________________##________ | |
| 272 | + _____#________________________#______________#________________________#______________#________________________#_________ | |
| 273 | + _____#_______________________#_______________#_______________________#_______________#_______________________#__________ | |
| 274 | + _____#______________________##_______________#______________________##_______________#______________________##__________ | |
| 275 | + _____##_____________________#________________##_____________________#________________##_____________________#___________ | |
| 276 | + ______#____________________#__________________#____________________#__________________#____________________#____________ | |
| 277 | + ______#___________________#___________________#___________________#___________________#___________________#_____________ | |
| 278 | + _______#_________________#_____________________#_________________#_____________________#_________________#______________ | |
| 279 | + _______##_______________#______________________##_______________#______________________##_______________#_______________ | |
| 280 | + ________##____________##________________________##____________##________________________##____________##________________ | |
| 281 | + __________##________###___________________________##________###___________________________##________###_________________ | |
| 282 | + ____________#########_______________________________#########_______________________________#########___________________ | |
| 283 | + ________________________________________________________________________________________________________________________ | |
| 284 | + | |
| 285 | + ________________________________________________________________________________________________________________________ | |
| 286 | + `; | |
| 287 | + | |
| 288 | + logger.log(messageRes); | |
| 289 | + messageRes += newLine | |
| 290 | +}; | |
| 174 | 291 | |
| 175 | 292 | |
| 176 | 293 | module.exports = logger; | ... | ... |