Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Z
zhichan
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
蒋勇
zhichan
Commits
255ab956
Commit
255ab956
authored
Jul 17, 2020
by
sxy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: add log
parent
bd16f91e
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
91 additions
and
15 deletions
+91
-15
ic-deliver/app/base/api/api.base.js
+5
-2
ic-deliver/app/base/controller/ctl.base.js
+10
-5
ic-deliver/app/base/system.js
+41
-0
ic-deliver/app/base/utils/logClient.js
+26
-8
ic-deliver/app/config/settings.js
+9
-0
No files found.
ic-deliver/app/base/api/api.base.js
View file @
255ab956
...
@@ -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"
);
}
}
async
setContextParams
(
pobj
,
qobj
,
req
)
{
async
setContextParams
(
pobj
,
qobj
,
req
)
{
let
custtags
=
req
.
headers
[
"x-consumetag"
]
?
req
.
headers
[
"x-consumetag"
].
split
(
"|"
)
:
null
;
let
custtags
=
req
.
headers
[
"x-consumetag"
]
?
req
.
headers
[
"x-consumetag"
].
split
(
"|"
)
:
null
;
...
@@ -27,7 +28,7 @@ class APIBase {
...
@@ -27,7 +28,7 @@ class APIBase {
}
}
if
(
req
.
xctx
.
userid
)
{
//在请求传递数据对象注入公司id
if
(
req
.
xctx
.
userid
)
{
//在请求传递数据对象注入公司id
pobj
.
userid
=
req
.
xctx
.
userid
;
pobj
.
userid
=
req
.
xctx
.
userid
;
pobj
.
username
=
req
.
xctx
.
username
pobj
.
username
=
req
.
xctx
.
username
}
}
if
(
!
req
.
xctx
.
appkey
)
{
if
(
!
req
.
xctx
.
appkey
)
{
return
[
-
200
,
"请求头缺少应用x-app-key"
]
return
[
-
200
,
"请求头缺少应用x-app-key"
]
...
@@ -41,7 +42,7 @@ class APIBase {
...
@@ -41,7 +42,7 @@ class APIBase {
// if(!req.xctx.companyid && !req.xctx.companykey){
// if(!req.xctx.companyid && !req.xctx.companykey){
// return [-200,"请求头缺少应用x-app-key"]
// return [-200,"请求头缺少应用x-app-key"]
// }
// }
if
(
!
req
.
xctx
.
companyid
&&
req
.
xctx
.
companykey
&&
req
.
xctx
.
companykey
!=
'null'
&&
req
.
xctx
.
companykey
!=
'undefined'
)
{
if
(
!
req
.
xctx
.
companyid
&&
req
.
xctx
.
companykey
&&
req
.
xctx
.
companykey
!=
'null'
&&
req
.
xctx
.
companykey
!=
'undefined'
)
{
let
comptmp
=
await
this
.
cacheManager
[
"CompanyCache"
].
cache
(
req
.
xctx
.
companykey
);
let
comptmp
=
await
this
.
cacheManager
[
"CompanyCache"
].
cache
(
req
.
xctx
.
companykey
);
req
.
xctx
.
companyid
=
comptmp
.
id
;
req
.
xctx
.
companyid
=
comptmp
.
id
;
}
}
...
@@ -57,8 +58,10 @@ class APIBase {
...
@@ -57,8 +58,10 @@ class APIBase {
}
}
var
rtn
=
await
this
[
methodname
](
pobj
,
query
,
req
);
var
rtn
=
await
this
[
methodname
](
pobj
,
query
,
req
);
this
.
logClient
.
log
(
pobj
,
req
,
rtn
)
return
rtn
;
return
rtn
;
}
catch
(
e
)
{
}
catch
(
e
)
{
this
.
logClient
.
log
(
pobj
,
req
,
null
,
e
.
stack
);
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
;
...
...
ic-deliver/app/base/controller/ctl.base.js
View file @
255ab956
...
@@ -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"
);
}
}
static
getServiceName
(
ClassObj
)
{
static
getServiceName
(
ClassObj
)
{
...
@@ -52,12 +53,14 @@ class CtlBase {
...
@@ -52,12 +53,14 @@ class CtlBase {
bizpath
:
req
.
headers
[
"xbizpath"
],
bizpath
:
req
.
headers
[
"xbizpath"
],
opath
:
req
.
headers
[
'xopath'
],
opath
:
req
.
headers
[
'xopath'
],
ptags
:
req
.
headers
[
'xptags'
],
ptags
:
req
.
headers
[
'xptags'
],
codename
:
req
.
headers
[
"xcodename"
],
codetitle
:
req
.
headers
[
"xcodetitle"
]
?
decodeURI
(
req
.
headers
[
"xcodetitle"
])
:
''
,
}
}
//添加组织结构路径,如果是上级,取上级
//添加组织结构路径,如果是上级,取上级
if
(
req
.
xctx
.
ptags
&&
req
.
xctx
.
ptags
!=
""
)
{
if
(
req
.
xctx
.
ptags
&&
req
.
xctx
.
ptags
!=
""
)
{
pobj
.
opath
=
req
.
xctx
.
ptags
pobj
.
opath
=
req
.
xctx
.
ptags
}
else
{
}
else
{
pobj
.
opath
=
req
.
xctx
.
opath
pobj
.
opath
=
req
.
xctx
.
opath
}
}
if
(
!
req
.
xctx
.
appkey
)
{
if
(
!
req
.
xctx
.
appkey
)
{
return
[
-
200
,
"请求头缺少应用x-app-key"
]
return
[
-
200
,
"请求头缺少应用x-app-key"
]
...
@@ -82,7 +85,7 @@ class CtlBase {
...
@@ -82,7 +85,7 @@ class CtlBase {
}
}
if
(
req
.
xctx
.
userid
)
{
//在请求传递数据对象注入公司id
if
(
req
.
xctx
.
userid
)
{
//在请求传递数据对象注入公司id
pobj
.
userid
=
req
.
xctx
.
userid
;
pobj
.
userid
=
req
.
xctx
.
userid
;
pobj
.
username
=
req
.
xctx
.
username
pobj
.
username
=
req
.
xctx
.
username
}
}
pobj
.
bizpath
=
req
.
xctx
.
bizpath
;
pobj
.
bizpath
=
req
.
xctx
.
bizpath
;
}
}
...
@@ -104,8 +107,10 @@ class CtlBase {
...
@@ -104,8 +107,10 @@ class CtlBase {
// }
// }
//req.session=redis缓存的上下文对象
//req.session=redis缓存的上下文对象
var
rtn
=
await
this
[
methodname
](
pobj
,
query
,
req
);
var
rtn
=
await
this
[
methodname
](
pobj
,
query
,
req
);
this
.
logClient
.
log
(
pobj
,
req
,
rtn
)
return
rtn
;
return
rtn
;
}
catch
(
e
)
{
}
catch
(
e
)
{
this
.
logClient
.
log
(
pobj
,
req
,
null
,
e
.
stack
);
console
.
log
(
e
.
stack
,
"出现异常,请联系管理员......."
);
console
.
log
(
e
.
stack
,
"出现异常,请联系管理员......."
);
return
system
.
getResultFail
(
-
200
,
"出现异常,请联系管理员"
);
return
system
.
getResultFail
(
-
200
,
"出现异常,请联系管理员"
);
}
}
...
...
ic-deliver/app/base/system.js
View file @
255ab956
...
@@ -257,6 +257,47 @@ class System {
...
@@ -257,6 +257,47 @@ class System {
};
};
/**
* 记录日志信息
* @param {*} opTitle 操作的标题
* @param {*} params 参数
* @param {*} identifyCode 业务标识
* @param {*} resultInfo 返回结果
* @param {*} errorInfo 错误信息
*/
static
execLogs
(
opTitle
,
params
,
identifyCode
,
resultInfo
,
errorInfo
)
{
var
reqUrl
=
settings
.
logUrl
();
let
isLogData
=
true
if
(
params
.
method
&&
(
params
.
method
.
indexOf
(
"find"
)
>=
0
||
params
.
method
.
indexOf
(
"get"
)
>=
0
))
{
isLogData
=
false
}
var
param
=
{
actionType
:
"produceLogsData"
,
// Y 功能名称
actionBody
:
{
opTitle
:
opTitle
||
""
,
// N 操作的业务标题
identifyCode
:
identifyCode
||
"brg-center-manage"
,
// Y 操作的业务标识
indexName
:
settings
.
logindex
,
// Y es索引值,同一个项目用一个值
messageBody
:
params
,
//日志的描述信息
resultInfo
:
isLogData
?
resultInfo
:
{
status
:
resultInfo
.
status
},
//返回信息
errorInfo
:
errorInfo
,
//错误信息
requestId
:
resultInfo
.
requestId
||
""
}
};
console
.
log
(
"写入日志内容:"
)
console
.
log
(
JSON
.
stringify
(
param
))
let
P
=
new
Promise
((
resv
,
rej
)
=>
{
this
.
postJsonTypeReq
(
reqUrl
,
param
).
then
(
res
=>
{
if
(
res
.
statusCode
==
200
)
{
resv
(
res
.
data
)
}
else
{
rej
(
null
)
}
});
})
return
P
}
}
}
Date
.
prototype
.
Format
=
function
(
fmt
)
{
//author: meizz
Date
.
prototype
.
Format
=
function
(
fmt
)
{
//author: meizz
var
o
=
{
var
o
=
{
...
...
ic-deliver/app/base/utils/logClient.js
View file @
255ab956
// 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");
}
}
getUUID
()
{
var
uuid
=
uuidv4
();
var
u
=
uuid
.
replace
(
/
\-
/g
,
""
);
return
u
;
}
async
log
(
pobj
,
req
,
rtninfo
,
errinfo
)
{
rtninfo
.
requestId
=
this
.
getUUID
()
req
.
params
.
param
=
pobj
//第三个字段应该存公司id
system
.
execLogs
(
settings
.
appname
+
"_"
+
req
.
xctx
.
codetitle
,
req
.
params
,
"_"
+
pobj
.
company_id
+
"_"
,
rtninfo
,
errinfo
).
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
;
ic-deliver/app/config/settings.js
View file @
255ab956
...
@@ -17,6 +17,8 @@ var settings = {
...
@@ -17,6 +17,8 @@ var settings = {
defaultpwd
:
"gsb2020"
,
defaultpwd
:
"gsb2020"
,
basepath
:
path
.
normalize
(
path
.
join
(
__dirname
,
'../..'
)),
basepath
:
path
.
normalize
(
path
.
join
(
__dirname
,
'../..'
)),
port
:
process
.
env
.
NODE_PORT
||
8888
,
port
:
process
.
env
.
NODE_PORT
||
8888
,
logindex
:
"center_manage"
,
appname
:
"ic_deliver"
,
kongurl
:
function
()
{
kongurl
:
function
()
{
if
(
this
.
env
==
"dev"
)
{
if
(
this
.
env
==
"dev"
)
{
var
localsettings
=
require
(
"./localsettings"
);
var
localsettings
=
require
(
"./localsettings"
);
...
@@ -46,6 +48,13 @@ var settings = {
...
@@ -46,6 +48,13 @@ var settings = {
return
"http://brg-user-center-service/api/action/order/springBoard"
;
return
"http://brg-user-center-service/api/action/order/springBoard"
;
}
}
},
},
logUrl
:
function
()
{
if
(
this
.
env
==
"dev"
)
{
return
"http://43.247.184.94:7200/api/queueAction/producer/springBoard"
;
}
else
{
return
"http://logs-sytxpublic-msgq-service/api/queueAction/producer/springBoard"
;
}
},
pmappid
:
1
,
pmappid
:
1
,
pmcompanyid
:
1
,
pmcompanyid
:
1
,
pmroleid
:
{
"ta"
:
1
,
"pr"
:
2
},
pmroleid
:
{
"ta"
:
1
,
"pr"
:
2
},
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment