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
0214d765
Commit
0214d765
authored
Jul 16, 2020
by
sxy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: add log
parent
190d04f8
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
89 additions
and
13 deletions
+89
-13
icp-deliver/app/base/api/api.base.js
+3
-1
icp-deliver/app/base/controller/ctl.base.js
+5
-0
icp-deliver/app/base/system.js
+42
-2
icp-deliver/app/base/utils/logClient.js
+26
-8
icp-deliver/app/config/settings.js
+13
-2
No files found.
icp-deliver/app/base/api/api.base.js
View file @
0214d765
...
...
@@ -4,6 +4,7 @@ const settings = require("../../config/settings");
class
APIBase
{
constructor
()
{
this
.
cacheManager
=
system
.
getObject
(
"db.common.cacheManager"
);
this
.
logClient
=
system
.
getObject
(
"util.logClient"
);
}
async
setContextParams
(
pobj
,
qobj
,
req
)
{
let
custtags
=
req
.
headers
[
"x-consumetag"
]
?
req
.
headers
[
"x-consumetag"
].
split
(
"|"
)
:
null
;
...
...
@@ -39,10 +40,11 @@ class APIBase {
if
(
xarg
&&
xarg
[
0
]
<
0
)
{
return
system
.
getResultFail
(...
xarg
);
}
var
rtn
=
await
this
[
methodname
](
pobj
,
query
,
req
);
this
.
logClient
.
log
(
pobj
,
req
,
rtn
)
return
rtn
;
}
catch
(
e
)
{
this
.
logClient
.
log
(
pobj
,
req
,
null
,
e
.
stack
);
console
.
log
(
e
.
stack
,
"api调用异常--error..................."
);
var
rtnerror
=
system
.
getResultFail
(
-
200
,
"出现异常,请联系管理员"
);
return
rtnerror
;
...
...
icp-deliver/app/base/controller/ctl.base.js
View file @
0214d765
...
...
@@ -6,6 +6,7 @@ class CtlBase {
this
.
serviceName
=
sname
;
this
.
service
=
system
.
getObject
(
"service."
+
gname
+
"."
+
sname
);
this
.
cacheManager
=
system
.
getObject
(
"db.common.cacheManager"
);
this
.
logClient
=
system
.
getObject
(
"util.logClient"
);
}
static
getServiceName
(
ClassObj
)
{
...
...
@@ -53,6 +54,8 @@ class CtlBase {
bizpath
:
req
.
headers
[
"xbizpath"
],
opath
:
req
.
headers
[
'xopath'
],
ptags
:
req
.
headers
[
'xptags'
],
codename
:
req
.
headers
[
"xcodename"
],
codetitle
:
req
.
headers
[
"xcodetitle"
]
?
decodeURI
(
req
.
headers
[
"xcodetitle"
])
:
''
,
}
if
(
req
.
xctx
.
ptags
&&
req
.
xctx
.
ptags
!=
""
)
{
pobj
.
opath
=
req
.
xctx
.
ptags
...
...
@@ -107,8 +110,10 @@ class CtlBase {
// }
//req.session=redis缓存的上下文对象
var
rtn
=
await
this
[
methodname
](
pobj
,
query
,
req
);
this
.
logClient
.
log
(
pobj
,
req
,
rtn
)
return
rtn
;
}
catch
(
e
)
{
this
.
logClient
.
log
(
pobj
,
req
,
null
,
e
.
stack
);
console
.
log
(
e
.
stack
,
"出现异常,请联系管理员......."
);
return
system
.
getResultFail
(
-
200
,
"出现异常,请联系管理员"
);
}
...
...
icp-deliver/app/base/system.js
View file @
0214d765
...
...
@@ -70,11 +70,11 @@ class System {
method
:
md
,
json
:
true
,
headers
:
{
"content-type"
:
"application/json"
,
'Content-type'
:
'application/json'
,
// 'Authorization': 'Basic YWRtaW5lczphZG1pbkdTQmVzLg=='
},
body
:
data
},
function
(
error
,
response
,
body
)
{
console
.
log
(
error
)
rtn
.
statusCode
=
response
.
statusCode
if
(
!
error
)
{
if
(
body
)
{
...
...
@@ -258,6 +258,46 @@ 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
(
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
var
o
=
{
...
...
icp-deliver/app/base/utils/logClient.js
View file @
0214d765
// var log4js = require('log4js');
var
settings
=
require
(
"../../config/settings"
);
class
LogClient
{
constructor
(){
// log4js.configure(settings.basepath+"/app/config/log4js.json");
// this.logerApp=log4js.getLogger("app");
// this.logerHttp=log4js.getLogger("http");
}
var
settings
=
require
(
"../../config/settings"
);
const
uuidv4
=
require
(
'uuid/v4'
);
const
system
=
require
(
"../system"
);
class
LogClient
{
constructor
()
{
}
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
;
icp-deliver/app/config/settings.js
View file @
0214d765
...
...
@@ -17,9 +17,20 @@ var settings = {
defaultpwd
:
"gsb2020"
,
basepath
:
path
.
normalize
(
path
.
join
(
__dirname
,
'../..'
)),
port
:
process
.
env
.
NODE_PORT
||
8002
,
logindex
:
"center_manage"
,
appname
:
"icp_deliver"
,
kongurl
:
function
()
{
if
(
this
.
env
==
"dev"
)
{
var
localsettings
=
require
(
"./localsettings"
);
return
localsettings
.
kongurl
;
}
else
{
return
ENVINPUT
.
KONG_ADMIAN
;
}
},
txurl
:
function
()
{
if
(
this
.
env
==
"dev"
)
{
var
localsettings
=
require
(
"./localsettings"
);
return
localsettings
.
txurl
;
}
else
{
return
"http://brg-user-center-service"
;
}
},
txurl
:
function
()
{
if
(
this
.
env
==
"dev"
)
{
var
localsettings
=
require
(
"./localsettings"
);
return
localsettings
.
txurl
;
}
else
{
return
"http://brg-user-center-service"
;
}
},
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
,
pmcompanyid
:
1
,
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