Commit 88e24c2b by 蒋勇

d

parent 2eaa1def
...@@ -4,6 +4,7 @@ const settings = require("../../config/settings"); ...@@ -4,6 +4,7 @@ const settings = require("../../config/settings");
class APIBase{ class APIBase{
constructor() { constructor() {
this.cacheManager = system.getObject("db.common.cacheManager"); this.cacheManager = system.getObject("db.common.cacheManager");
this.logClient=system.getObject("util.logClient");
} }
getUUID() { getUUID() {
var uuid = uuidv4(); var uuid = uuidv4();
...@@ -51,39 +52,10 @@ class APIBase{ ...@@ -51,39 +52,10 @@ class APIBase{
} }
var rtn = await this[methodname](pobj, query, req); var rtn = await this[methodname](pobj, query, req);
rtn.requestId=this.getUUID() this.logClient.log(pobj,req,rtn)
req.params.param=pobj
let t=req.xctx.codetitle
if(t==''){
t="外部调用"
}
system.execLogs(t,req.params,pobj.company_id,rtn,null).then(res=>{
if(res && res.status==1){
console.log("log.....success")
}else{
console.log("log.....fail")
}
}).catch(e=>{
console.log("log.....fail")
})
return rtn; return rtn;
} catch (e) { } catch (e) {
let rtn={} this.logClient.log(pobj,req,{})
rtn.requestId=this.getUUID()
req.params.param=pobj
let t=req.xctx.codetitle
if(t==''){
t="外部调用"
}
system.execLogs(t,req.params,pobj.company_id,rtn,e.stack).then(res=>{
if(res && res.status==1){
console.log("log.....success")
}else{
console.log("log.....fail")
}
}).catch(e=>{
console.log("log.....fail")
})
console.log(e.stack, "api调用异常--error..................."); console.log(e.stack, "api调用异常--error...................");
var rtnerror = system.getResultFail(-200, "出现异常,请联系管理员"); var rtnerror = system.getResultFail(-200, "出现异常,请联系管理员");
return rtnerror; return rtnerror;
......
...@@ -6,6 +6,7 @@ class CtlBase { ...@@ -6,6 +6,7 @@ class CtlBase {
this.serviceName = sname; this.serviceName = sname;
this.service = system.getObject("service." + gname + "." + sname); this.service = system.getObject("service." + gname + "." + sname);
this.cacheManager = system.getObject("db.common.cacheManager"); this.cacheManager = system.getObject("db.common.cacheManager");
this.logClient=system.getObject("util.logClient");
} }
getUUID() { getUUID() {
var uuid = uuidv4(); var uuid = uuidv4();
...@@ -85,20 +86,7 @@ class CtlBase { ...@@ -85,20 +86,7 @@ class CtlBase {
} }
pobj.bizpath = req.xctx.bizpath; pobj.bizpath = req.xctx.bizpath;
} }
async log(pobj, req, rtn) {
rtn.requestId = this.getUUID()
req.params.param = pobj
//第三个字段应该存公司id
system.execLogs(req.xctx.codetitle, req.params, pobj.company_id, rtn, null).then(res => {
if (res && res.status == 1) {
console.log("log.....success")
} else {
console.log("log.....fail")
}
}).catch(e => {
console.log("log.....fail")
})
}
async doexec(methodname, pobj, query, req) { async doexec(methodname, pobj, query, req) {
try { try {
let xarg = await this.setContextParams(pobj, query, req); let xarg = await this.setContextParams(pobj, query, req);
...@@ -106,10 +94,10 @@ class CtlBase { ...@@ -106,10 +94,10 @@ class CtlBase {
return system.getResultFail(...xarg); return system.getResultFail(...xarg);
} }
var rtn = await this[methodname](pobj, query, req); var rtn = await this[methodname](pobj, query, req);
//this.log(pobj,req,rtn) this.logClient.log(pobj,req,rtn)
return rtn; return rtn;
} catch (e) { } catch (e) {
//this.log(pobj,req,rtn) this.logClient.log(pobj,req,{})
console.log(e.stack, "出现异常,请联系管理员......."); console.log(e.stack, "出现异常,请联系管理员.......");
return system.getResultFail(-200, "出现异常,请联系管理员"); return system.getResultFail(-200, "出现异常,请联系管理员");
} }
......
// var log4js = require('log4js'); // var log4js = require('log4js');
var settings=require("../../config/settings"); var settings = require("../../config/settings");
class LogClient{ const uuidv4 = require('uuid/v4');
constructor(){ const system = require("../system");
// log4js.configure(settings.basepath+"/app/config/log4js.json"); class LogClient {
// this.logerApp=log4js.getLogger("app"); constructor() {
// this.logerHttp=log4js.getLogger("http"); // log4js.configure(settings.basepath+"/app/config/log4js.json");
} // this.logerApp=log4js.getLogger("app");
// this.logerHttp=log4js.getLogger("http");
}
getUUID() {
var uuid = uuidv4();
var u = uuid.replace(/\-/g, "");
return u;
}
async log(pobj, req, rtn) {
rtn.requestId = this.getUUID()
req.params.param = pobj
//第三个字段应该存公司id
system.execLogs(req.xctx.codetitle, req.params, pobj.company_id, rtn, null).then(res => {
if (res && res.status == 1) {
console.log("log.....success")
} else {
console.log("log.....fail")
}
}).catch(e => {
console.log("log.....fail")
})
}
} }
module.exports=LogClient; module.exports = LogClient;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment