Commit 23001dfb6944d41fd8465672f797da9768074a4a

Authored by sumatek
1 parent d934f74e
Exists in master and in 1 other branch dev

update log

ais-structure/index.js
... ... @@ -2,6 +2,7 @@ const crypto = require('crypto');
2 2 const fs = require("fs");
3 3 const http = require("http");
4 4 const https = require("https");
  5 +// const log = require('./src/modules/helper/log.js');;
5 6  
6 7  
7 8 /* ------------- [START STORE CONFIG] ------------ */
... ...
ais-structure/src/config/config.js
... ... @@ -19,7 +19,7 @@ var config = {
19 19 },
20 20 SPW:{
21 21 Name : "SPW API",
22   - POST_SearchCustomer_URL : "http://10.1.3.172:8080",
  22 + POST_SearchCustomer_URL : "http://10.1.3.74:8080",
23 23 POST_SearchCustomer_Timeout : 10
24 24  
25 25 },
... ... @@ -32,11 +32,26 @@ var config = {
32 32  
33 33 }
34 34 },
  35 + log:{
  36 + logTime : 15,
  37 + statTime : 2,
  38 + detailTime : 15,
  39 + summaryTime : 15,
  40 + statInterval : 1,
  41 + appLogPath : './logTest/',
  42 + summaryPath : './logTest/',
  43 + statPath : './logTest/',
  44 + detailPath : './logTest/',
  45 + level : 'debug'
  46 + },
35 47 http_req_timeout: 120,
36 48 session: 30, //minutes
37 49 Default_Timeout: 10
38 50 }
39 51 };
  52 +
  53 +
  54 +
40 55 /* ------------- [END SERVER CONFIG VARIABLES] ------------ */
41 56  
42 57 /* ------------- [START SERVER GET FUNTION] ------------ */
... ...
ais-structure/src/modules/helper/log.js 0 → 100644
... ... @@ -0,0 +1,102 @@
  1 +var env = process.env.NODE_ENV || 'development';
  2 +var cfg = require('../../config/config.js').get(env);
  3 +
  4 +var conf = {};
  5 +conf.log = cfg.log;
  6 +conf.log.projectName = cfg.app_name;
  7 +
  8 +var logg = require('commonlog-kb').init(conf);
  9 +
  10 +// wait log stats
  11 +// logg.stat('stat_name');
  12 +
  13 +var logger = [];
  14 +var summaryList = [];
  15 +
  16 +logger.log(msg,type)
  17 +{
  18 +
  19 + if(!type)
  20 + type = 'debug';
  21 +
  22 + type = type.toLowerCase();
  23 +
  24 + switch(type) {
  25 + case 'debug':
  26 + logg.debug(msg);
  27 + break;
  28 + case 'info':
  29 + logg.info(msg);
  30 + break;
  31 + case 'warn':
  32 + logg.warn(msg);
  33 + break;
  34 + case 'error':
  35 + logg.error(msg);
  36 + break;
  37 + default:
  38 + logg.debug(msg);
  39 + }
  40 +}
  41 +
  42 +logger.start(sessionData,cmdData,identityData)
  43 +{
  44 + summary = {
  45 + session : sessionData,
  46 + cmd : cmdData,
  47 + identity : identityData
  48 + };
  49 + summaryList.push();
  50 +}
  51 +logger.addSummary(nodeData,cmdData,resultData)
  52 +{
  53 + summary = {
  54 + node : nodeData,
  55 + cmd : cmdData,
  56 + resultCode : resultData.resultCode,
  57 + resultDesc : resultData.developerMessage
  58 + };
  59 + summaryList.push();
  60 +}
  61 +
  62 +logger.logSummary()
  63 +{
  64 + var log;
  65 + var row;
  66 + for (let index = 0; index < summaryList.length; index++) {
  67 + row = array[index];
  68 +
  69 + if(index == 0)
  70 + {
  71 + log = logg.summary(row.session1, row.cmd, row.identity);
  72 + }else
  73 + {
  74 + log.addSuccessBlock(row.node,row.cmd,row.resultCode,row.resultDesc);
  75 + }
  76 +
  77 + }
  78 + log.end(row.resultCode,row.resultDesc)
  79 +}
  80 +
  81 +module.exports = logger;
  82 +
  83 +
  84 +
  85 +// var s1 = logg.summary('session1', 'cmd', 'identity');
  86 +// s1.addSuccessBlock('node', 'a', '20000', 'resultDesc');
  87 +// s1.addSuccessBlock('node', 'b', 'resultCode', 'resultDesc');
  88 +// s1.addSuccessBlock('node1', 'c', 'resultCode', 'resultDesc');
  89 +// s1.addSuccessBlock('node1', 'cmd', 'resultCode', 'resultDesc');
  90 +
  91 +// s1.addSuccessBlock('node1', 'cmd', 'resultCode', 'resultDesc 1');
  92 +// s1.addSuccessBlock('node1', 'cmd', 'resultCode', 'resultDesc 1');
  93 +// var s2 = logg.summary('session2', 'cmd', 'identity');
  94 +
  95 +// s1.end('20000','sucesss');
  96 +// s2.end();
  97 +
  98 +//type// - REQ, RES, RES_TIMEOUT, REQ_RETRY_1/1
  99 +var ddd = logg.detail('session1', 'cmd', 'identity');
  100 +ddd.addInput( 'node', 'cmd', 'type', 'rawData', 'data' );
  101 +ddd.addOutput( 'node', 'cmd', 'type', 'rawData', 'data');
  102 +ddd.end();
0 103 \ No newline at end of file
... ...