Skip to content

Commit

Permalink
feat: product取值优化
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangqichao02 authored and meixg committed Oct 10, 2022
1 parent 69257d4 commit b857005
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
5 changes: 3 additions & 2 deletions packages/logger/__tests__/logger.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,16 @@ describe('@hoth/logger logger', function () {
headers: {
'user-agent': 'mock'
},
method: 'post'
method: 'post',
product: 'product_aa'
},
});
setTimeout(() => {
const log = readFileSync(join(rootPath, 'log/aa/aa.log.2021020100'), 'utf8');
expect(log).toContain('NOTICE: 2021-02-01 00:00:00');
expect(log).toContain('idc[all]');
expect(log).toContain('cluster[test]');
expect(log).toContain('product[aa]');
expect(log).toContain('product[product_aa]');
expect(log).toContain('module[foo_cc]');
expect(log).toContain('ua[mock]');
expect(log).toContain('status[201]');
Expand Down
6 changes: 3 additions & 3 deletions packages/logger/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ export const defaultLevels = {

const normalFormat = ':level: :time [:file::line]'
+ ' errno[:errno] logId[:logid] pid[:pid]'
+ ' uri[:uri] cluster[:cluster] idc[:idc] product[:app] module[:module]'
+ ' uri[:uri] cluster[:cluster] idc[:idc] product[:product] module[:module]'
+ ' clientIp[:ip] ua[:ua] refer[:referrer] :msg';

const noticeFormat = ':level: :time [:file::line]'
+ ' errno[:errno] status[:status] logId[:logid] pid[:pid]'
+ ' method[:method] uri[:uri] cluster[:cluster] idc[:idc] product[:app] module[:module]'
+ ' method[:method] uri[:uri] cluster[:cluster] idc[:idc] product[:product] module[:module]'
+ ' clientIp[:ip] ua[:ua] refer[:referrer] :notices tm[:performance] responseTime[:response-time]';

const errorFormat = ':level: :time [:file::line]'
+ ' errno[:errno] status[:status] logId[:logid] pid[:pid]'
+ ' uri[:uri] cluster[:cluster] idc[:idc] product[:app] module[:module]'
+ ' uri[:uri] cluster[:cluster] idc[:idc] product[:product] module[:module]'
+ ' clientIp[:ip] ua[:ua] refer[:referrer] :errmsg';

export const defaultFormats = {
Expand Down
3 changes: 3 additions & 0 deletions packages/logger/src/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ export default {
module(o) {
return o.req?.module || o.req?.url.split('?')[0].split('/').filter(a => a && a !== o.app).join('_');
},
product(o) {
return o.req?.product || o.app;
},
pid(o) {
return o.pid;
},
Expand Down

0 comments on commit b857005

Please sign in to comment.