zova-module-a-logger 5.0.0 → 5.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/index.js +114 -0
- package/dist/index.js.map +1 -0
- package/package.json +31 -23
- package/src/.metadata/index.ts +61 -0
- package/src/.metadata/this.ts +2 -0
- package/src/bean/aopMethod.log.ts +114 -0
- package/src/index.ts +2 -0
- package/src/lib/index.ts +1 -0
- package/src/lib/log.ts +7 -0
- package/README.md +0 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2016-present Zova
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { BeanAopMethodBase, BeanInfo, BeanScopeBase, SymbolBeanFullName, cast } from "zova";
|
|
2
|
+
import { evaluateExpressions } from "@cabloy/utils";
|
|
3
|
+
import { AopMethod, Scope, UseAopMethod } from "zova-module-a-bean";
|
|
4
|
+
//#region src/bean/aopMethod.log.ts
|
|
5
|
+
var _dec$1, _dec2$1, _class$1;
|
|
6
|
+
var AopMethodLog = (_dec$1 = AopMethod({ level: "info" }), _dec2$1 = BeanInfo({ module: "a-logger" }), _dec$1(_class$1 = _dec2$1(_class$1 = class AopMethodLog extends BeanAopMethodBase {
|
|
7
|
+
get(options, next, receiver, prop) {
|
|
8
|
+
const context = this._getContext(options, receiver);
|
|
9
|
+
const message = `${receiver[SymbolBeanFullName]}#${prop}(get)`;
|
|
10
|
+
const profiler = this.sys.meta.logger.child(options.childName, options.clientName).startTimer();
|
|
11
|
+
try {
|
|
12
|
+
const res = next();
|
|
13
|
+
this._logResult(profiler, context, res, options, message);
|
|
14
|
+
return res;
|
|
15
|
+
} catch (err) {
|
|
16
|
+
this._logError(profiler, context, err, options, message);
|
|
17
|
+
throw err;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
set(options, value, next, receiver, prop) {
|
|
21
|
+
const context = this._getContext(options, receiver);
|
|
22
|
+
const message = `${receiver[SymbolBeanFullName]}#${prop}(set)`;
|
|
23
|
+
const profiler = this.sys.meta.logger.child(options.childName, options.clientName).startTimer();
|
|
24
|
+
try {
|
|
25
|
+
const res = next();
|
|
26
|
+
this._logValue(profiler, context, value, options, message);
|
|
27
|
+
return res;
|
|
28
|
+
} catch (err) {
|
|
29
|
+
this._logError(profiler, context, err, options, message);
|
|
30
|
+
throw err;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
execute(options, _args, next, receiver, prop) {
|
|
34
|
+
const context = this._getContext(options, receiver);
|
|
35
|
+
const message = `${receiver[SymbolBeanFullName]}#${prop}`;
|
|
36
|
+
const logger = this.sys.meta.logger.child(options.childName, options.clientName);
|
|
37
|
+
if (options.args !== false) {
|
|
38
|
+
const info = {
|
|
39
|
+
level: options.level,
|
|
40
|
+
message
|
|
41
|
+
};
|
|
42
|
+
if (context) info.context = context;
|
|
43
|
+
if (_args.length > 0) info.args = _args;
|
|
44
|
+
logger.log(info);
|
|
45
|
+
}
|
|
46
|
+
const profiler = logger.startTimer();
|
|
47
|
+
try {
|
|
48
|
+
const res = next();
|
|
49
|
+
if (res?.then) return res.then((res) => {
|
|
50
|
+
options.result !== false && this._logResult(profiler, context, res, options, message);
|
|
51
|
+
return res;
|
|
52
|
+
}).catch((err) => {
|
|
53
|
+
this._logError(profiler, context, err, options, message);
|
|
54
|
+
throw err;
|
|
55
|
+
});
|
|
56
|
+
options.result !== false && this._logResult(profiler, context, res, options, message);
|
|
57
|
+
return res;
|
|
58
|
+
} catch (err) {
|
|
59
|
+
this._logError(profiler, context, err, options, message);
|
|
60
|
+
throw err;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
_getContext(options, receiver) {
|
|
64
|
+
return evaluateExpressions(options.context, {
|
|
65
|
+
self: receiver,
|
|
66
|
+
sys: cast(receiver).sys,
|
|
67
|
+
app: cast(receiver).app,
|
|
68
|
+
ctx: cast(receiver).ctx
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
_logValue(profiler, context, value, options, message) {
|
|
72
|
+
const info = {
|
|
73
|
+
level: options.level,
|
|
74
|
+
message
|
|
75
|
+
};
|
|
76
|
+
if (context) info.context = context;
|
|
77
|
+
info.value = value;
|
|
78
|
+
profiler.done(info);
|
|
79
|
+
}
|
|
80
|
+
_logResult(profiler, context, res, options, message) {
|
|
81
|
+
const info = {
|
|
82
|
+
level: options.level,
|
|
83
|
+
message
|
|
84
|
+
};
|
|
85
|
+
if (context) info.context = context;
|
|
86
|
+
if (res !== void 0) info.result = res;
|
|
87
|
+
profiler.done(info);
|
|
88
|
+
}
|
|
89
|
+
_logError(profiler, context, err, _options, message) {
|
|
90
|
+
const info = {
|
|
91
|
+
level: "error",
|
|
92
|
+
message
|
|
93
|
+
};
|
|
94
|
+
if (context) info.context = context;
|
|
95
|
+
if (err) info.error = err;
|
|
96
|
+
profiler.done(info);
|
|
97
|
+
}
|
|
98
|
+
}) || _class$1) || _class$1);
|
|
99
|
+
//#endregion
|
|
100
|
+
//#region src/.metadata/index.ts
|
|
101
|
+
/** aopMethod: end */
|
|
102
|
+
/** scope: begin */
|
|
103
|
+
var _dec, _dec2, _class;
|
|
104
|
+
var ScopeModuleALogger = (_dec = Scope(), _dec2 = BeanInfo({ module: "a-logger" }), _dec(_class = _dec2(_class = class ScopeModuleALogger extends BeanScopeBase {}) || _class) || _class);
|
|
105
|
+
/** scope: end */
|
|
106
|
+
//#endregion
|
|
107
|
+
//#region src/lib/log.ts
|
|
108
|
+
function Log(options) {
|
|
109
|
+
return UseAopMethod("a-logger:log", options);
|
|
110
|
+
}
|
|
111
|
+
//#endregion
|
|
112
|
+
export { AopMethodLog, Log, ScopeModuleALogger };
|
|
113
|
+
|
|
114
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/bean/aopMethod.log.ts","../src/.metadata/index.ts","../src/lib/log.ts"],"sourcesContent":["import type { ILoggerChildRecord, ILoggerClientRecord, Next, NextSync } from 'zova';\nimport type { IAopMethodExecute, IAopMethodGet, IAopMethodSet, IDecoratorAopMethodOptions } from 'zova-module-a-bean';\n\nimport { LoggerLevel, Profiler } from '@cabloy/logger';\nimport { evaluateExpressions } from '@cabloy/utils';\nimport { BeanAopMethodBase, cast, SymbolBeanFullName } from 'zova';\nimport { AopMethod } from 'zova-module-a-bean';\n\nexport interface IAopMethodOptionsLog extends IDecoratorAopMethodOptions {\n level: LoggerLevel;\n childName?: keyof ILoggerChildRecord;\n clientName?: keyof ILoggerClientRecord;\n args?: boolean;\n result?: boolean;\n context?: Record<string, any>;\n}\n\n@AopMethod<IAopMethodOptionsLog>({\n level: 'info',\n})\nexport class AopMethodLog extends BeanAopMethodBase implements IAopMethodGet, IAopMethodSet, IAopMethodExecute {\n get(options: IAopMethodOptionsLog, next: NextSync, receiver: any, prop: string): any {\n const context = this._getContext(options, receiver);\n const message = `${receiver[SymbolBeanFullName]}#${prop}(get)`;\n const logger = this.sys.meta.logger.child(options.childName, options.clientName);\n // begin\n const profiler = logger.startTimer();\n // next\n try {\n const res = next();\n this._logResult(profiler, context, res, options, message);\n return res;\n } catch (err: any) {\n this._logError(profiler, context, err, options, message);\n throw err;\n }\n }\n\n set(options: IAopMethodOptionsLog, value: any, next: NextSync, receiver: any, prop: string): boolean {\n const context = this._getContext(options, receiver);\n const message = `${receiver[SymbolBeanFullName]}#${prop}(set)`;\n const logger = this.sys.meta.logger.child(options.childName, options.clientName);\n // begin\n const profiler = logger.startTimer();\n // next\n try {\n const res = next();\n this._logValue(profiler, context, value, options, message);\n return res;\n } catch (err: any) {\n this._logError(profiler, context, err, options, message);\n throw err;\n }\n }\n\n execute(options: IAopMethodOptionsLog, _args: [], next: Next | NextSync, receiver: any, prop: string): Promise<any> | any {\n const context = this._getContext(options, receiver);\n const message = `${receiver[SymbolBeanFullName]}#${prop}`;\n const logger = this.sys.meta.logger.child(options.childName, options.clientName);\n // begin\n if (options.args !== false) {\n const info: any = { level: options.level, message };\n if (context) info.context = context;\n if (_args.length > 0) info.args = _args;\n logger.log(info);\n }\n const profiler = logger.startTimer();\n // next\n try {\n const res = next();\n if (res?.then) {\n return res\n .then((res: any) => {\n options.result !== false && this._logResult(profiler, context, res, options, message);\n return res;\n })\n .catch((err: Error) => {\n this._logError(profiler, context, err, options, message);\n throw err;\n });\n }\n options.result !== false && this._logResult(profiler, context, res, options, message);\n return res;\n } catch (err: any) {\n this._logError(profiler, context, err, options, message);\n throw err;\n }\n }\n\n _getContext(options: IAopMethodOptionsLog, receiver: any) {\n return evaluateExpressions(options.context, { self: receiver, sys: cast(receiver).sys, app: cast(receiver).app, ctx: cast(receiver).ctx });\n }\n\n _logValue(profiler: Profiler, context: any, value: any, options: IAopMethodOptionsLog, message: string) {\n const info: any = { level: options.level, message };\n if (context) info.context = context;\n info.value = value;\n profiler.done(info);\n }\n\n _logResult(profiler: Profiler, context: any, res: any, options: IAopMethodOptionsLog, message: string) {\n const info: any = { level: options.level, message };\n if (context) info.context = context;\n if (res !== undefined) info.result = res;\n profiler.done(info);\n }\n\n _logError(profiler: Profiler, context: any, err: Error, _options: IAopMethodOptionsLog, message: string) {\n const info: any = { level: 'error', message };\n if (context) info.context = context;\n if (err) info.error = err;\n profiler.done(info);\n }\n}\n","// eslint-disable\n/** aopMethod: begin */\nexport * from '../bean/aopMethod.log.js';\nimport { IAopMethodOptionsLog } from '../bean/aopMethod.log.js';\nimport 'zova-module-a-bean';\ndeclare module 'zova-module-a-bean' {\n \n export interface IAopMethodRecord {\n 'a-logger:log': IAopMethodOptionsLog;\n }\n\n \n}\ndeclare module 'zova-module-a-logger' {\n \n export interface AopMethodLog {\n /** @internal */\n get scope(): ScopeModuleALogger;\n }\n\n export interface AopMethodLog {\n get $beanFullName(): 'a-logger.aopMethod.log';\n get $onionName(): 'a-logger:log';\n get $onionOptions(): IAopMethodOptionsLog;\n } \n}\n/** aopMethod: end */\n/** aopMethod: begin */\nimport { AopMethodLog } from '../bean/aopMethod.log.js';\nimport 'zova';\ndeclare module 'zova' {\n export interface IBeanRecordLocal {\n 'a-logger.aopMethod.log': AopMethodLog;\n }\n}\n/** aopMethod: end */\n/** scope: begin */\nimport { BeanScopeBase, type BeanScopeUtil } from 'zova';\nimport { Scope } from 'zova-module-a-bean';\n\n@Scope()\nexport class ScopeModuleALogger extends BeanScopeBase {}\n\nexport interface ScopeModuleALogger {\n util: BeanScopeUtil;\n}\n\nimport 'zova';\ndeclare module 'zova' {\n export interface IBeanScopeRecord {\n 'a-logger': ScopeModuleALogger;\n }\n \n \n\n \n\n \n}\n \n/** scope: end */\n","import { UseAopMethod } from 'zova-module-a-bean';\n\nimport type { IAopMethodOptionsLog } from '../bean/aopMethod.log.js';\n\nexport function Log(options?: Partial<IAopMethodOptionsLog>): MethodDecorator {\n return UseAopMethod('a-logger:log', options);\n}\n"],"mappings":"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"}
|
package/package.json
CHANGED
|
@@ -1,37 +1,45 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zova-module-a-logger",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.1.1",
|
|
4
|
+
"description": "",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"Zova Module"
|
|
7
|
+
],
|
|
8
|
+
"author": "",
|
|
9
|
+
"files": [
|
|
10
|
+
"dist",
|
|
11
|
+
"mock",
|
|
12
|
+
"src",
|
|
13
|
+
"icons",
|
|
14
|
+
"assets",
|
|
15
|
+
"rest"
|
|
16
|
+
],
|
|
4
17
|
"type": "module",
|
|
5
|
-
"publishConfig": {
|
|
6
|
-
"access": "public"
|
|
7
|
-
},
|
|
8
18
|
"exports": {
|
|
9
19
|
".": {
|
|
10
20
|
"types": [
|
|
11
21
|
"./src/index.ts",
|
|
12
22
|
"./dist/index.d.ts"
|
|
13
23
|
],
|
|
14
|
-
"
|
|
15
|
-
"import": "./dist/index.js",
|
|
16
|
-
"default": "./src/index.ts"
|
|
24
|
+
"default": "./dist/index.js"
|
|
17
25
|
},
|
|
18
|
-
"
|
|
26
|
+
"./*": "./*"
|
|
19
27
|
},
|
|
20
|
-
"description": "",
|
|
21
|
-
"files": [
|
|
22
|
-
"dist",
|
|
23
|
-
"static",
|
|
24
|
-
"typings"
|
|
25
|
-
],
|
|
26
28
|
"scripts": {
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"
|
|
29
|
+
"clean": "rimraf dist tsconfig.build.tsbuildinfo",
|
|
30
|
+
"tsc:publish": "npm run clean && zova :bin:buildModule --sourcemap",
|
|
31
|
+
"prepublishOnly": "npm run tsc:publish",
|
|
32
|
+
"prepack": "clean-package",
|
|
33
|
+
"postpack": "clean-package restore && npm run clean"
|
|
31
34
|
},
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
|
|
35
|
-
"
|
|
36
|
-
"
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"@cabloy/logger": "^1.1.1"
|
|
37
|
+
},
|
|
38
|
+
"title": "a-logger",
|
|
39
|
+
"zovaModule": {
|
|
40
|
+
"globalDependencies": {
|
|
41
|
+
"@cabloy/logger": true
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
"gitHead": "a1b13b06e259e4447ab2f361ec76941810bc4ad7"
|
|
37
45
|
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// eslint-disable
|
|
2
|
+
/** aopMethod: begin */
|
|
3
|
+
export * from '../bean/aopMethod.log.js';
|
|
4
|
+
import { IAopMethodOptionsLog } from '../bean/aopMethod.log.js';
|
|
5
|
+
import 'zova-module-a-bean';
|
|
6
|
+
declare module 'zova-module-a-bean' {
|
|
7
|
+
|
|
8
|
+
export interface IAopMethodRecord {
|
|
9
|
+
'a-logger:log': IAopMethodOptionsLog;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
}
|
|
14
|
+
declare module 'zova-module-a-logger' {
|
|
15
|
+
|
|
16
|
+
export interface AopMethodLog {
|
|
17
|
+
/** @internal */
|
|
18
|
+
get scope(): ScopeModuleALogger;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface AopMethodLog {
|
|
22
|
+
get $beanFullName(): 'a-logger.aopMethod.log';
|
|
23
|
+
get $onionName(): 'a-logger:log';
|
|
24
|
+
get $onionOptions(): IAopMethodOptionsLog;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/** aopMethod: end */
|
|
28
|
+
/** aopMethod: begin */
|
|
29
|
+
import { AopMethodLog } from '../bean/aopMethod.log.js';
|
|
30
|
+
import 'zova';
|
|
31
|
+
declare module 'zova' {
|
|
32
|
+
export interface IBeanRecordLocal {
|
|
33
|
+
'a-logger.aopMethod.log': AopMethodLog;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/** aopMethod: end */
|
|
37
|
+
/** scope: begin */
|
|
38
|
+
import { BeanScopeBase, type BeanScopeUtil } from 'zova';
|
|
39
|
+
import { Scope } from 'zova-module-a-bean';
|
|
40
|
+
|
|
41
|
+
@Scope()
|
|
42
|
+
export class ScopeModuleALogger extends BeanScopeBase {}
|
|
43
|
+
|
|
44
|
+
export interface ScopeModuleALogger {
|
|
45
|
+
util: BeanScopeUtil;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
import 'zova';
|
|
49
|
+
declare module 'zova' {
|
|
50
|
+
export interface IBeanScopeRecord {
|
|
51
|
+
'a-logger': ScopeModuleALogger;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** scope: end */
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import type { ILoggerChildRecord, ILoggerClientRecord, Next, NextSync } from 'zova';
|
|
2
|
+
import type { IAopMethodExecute, IAopMethodGet, IAopMethodSet, IDecoratorAopMethodOptions } from 'zova-module-a-bean';
|
|
3
|
+
|
|
4
|
+
import { LoggerLevel, Profiler } from '@cabloy/logger';
|
|
5
|
+
import { evaluateExpressions } from '@cabloy/utils';
|
|
6
|
+
import { BeanAopMethodBase, cast, SymbolBeanFullName } from 'zova';
|
|
7
|
+
import { AopMethod } from 'zova-module-a-bean';
|
|
8
|
+
|
|
9
|
+
export interface IAopMethodOptionsLog extends IDecoratorAopMethodOptions {
|
|
10
|
+
level: LoggerLevel;
|
|
11
|
+
childName?: keyof ILoggerChildRecord;
|
|
12
|
+
clientName?: keyof ILoggerClientRecord;
|
|
13
|
+
args?: boolean;
|
|
14
|
+
result?: boolean;
|
|
15
|
+
context?: Record<string, any>;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
@AopMethod<IAopMethodOptionsLog>({
|
|
19
|
+
level: 'info',
|
|
20
|
+
})
|
|
21
|
+
export class AopMethodLog extends BeanAopMethodBase implements IAopMethodGet, IAopMethodSet, IAopMethodExecute {
|
|
22
|
+
get(options: IAopMethodOptionsLog, next: NextSync, receiver: any, prop: string): any {
|
|
23
|
+
const context = this._getContext(options, receiver);
|
|
24
|
+
const message = `${receiver[SymbolBeanFullName]}#${prop}(get)`;
|
|
25
|
+
const logger = this.sys.meta.logger.child(options.childName, options.clientName);
|
|
26
|
+
// begin
|
|
27
|
+
const profiler = logger.startTimer();
|
|
28
|
+
// next
|
|
29
|
+
try {
|
|
30
|
+
const res = next();
|
|
31
|
+
this._logResult(profiler, context, res, options, message);
|
|
32
|
+
return res;
|
|
33
|
+
} catch (err: any) {
|
|
34
|
+
this._logError(profiler, context, err, options, message);
|
|
35
|
+
throw err;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
set(options: IAopMethodOptionsLog, value: any, next: NextSync, receiver: any, prop: string): boolean {
|
|
40
|
+
const context = this._getContext(options, receiver);
|
|
41
|
+
const message = `${receiver[SymbolBeanFullName]}#${prop}(set)`;
|
|
42
|
+
const logger = this.sys.meta.logger.child(options.childName, options.clientName);
|
|
43
|
+
// begin
|
|
44
|
+
const profiler = logger.startTimer();
|
|
45
|
+
// next
|
|
46
|
+
try {
|
|
47
|
+
const res = next();
|
|
48
|
+
this._logValue(profiler, context, value, options, message);
|
|
49
|
+
return res;
|
|
50
|
+
} catch (err: any) {
|
|
51
|
+
this._logError(profiler, context, err, options, message);
|
|
52
|
+
throw err;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
execute(options: IAopMethodOptionsLog, _args: [], next: Next | NextSync, receiver: any, prop: string): Promise<any> | any {
|
|
57
|
+
const context = this._getContext(options, receiver);
|
|
58
|
+
const message = `${receiver[SymbolBeanFullName]}#${prop}`;
|
|
59
|
+
const logger = this.sys.meta.logger.child(options.childName, options.clientName);
|
|
60
|
+
// begin
|
|
61
|
+
if (options.args !== false) {
|
|
62
|
+
const info: any = { level: options.level, message };
|
|
63
|
+
if (context) info.context = context;
|
|
64
|
+
if (_args.length > 0) info.args = _args;
|
|
65
|
+
logger.log(info);
|
|
66
|
+
}
|
|
67
|
+
const profiler = logger.startTimer();
|
|
68
|
+
// next
|
|
69
|
+
try {
|
|
70
|
+
const res = next();
|
|
71
|
+
if (res?.then) {
|
|
72
|
+
return res
|
|
73
|
+
.then((res: any) => {
|
|
74
|
+
options.result !== false && this._logResult(profiler, context, res, options, message);
|
|
75
|
+
return res;
|
|
76
|
+
})
|
|
77
|
+
.catch((err: Error) => {
|
|
78
|
+
this._logError(profiler, context, err, options, message);
|
|
79
|
+
throw err;
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
options.result !== false && this._logResult(profiler, context, res, options, message);
|
|
83
|
+
return res;
|
|
84
|
+
} catch (err: any) {
|
|
85
|
+
this._logError(profiler, context, err, options, message);
|
|
86
|
+
throw err;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
_getContext(options: IAopMethodOptionsLog, receiver: any) {
|
|
91
|
+
return evaluateExpressions(options.context, { self: receiver, sys: cast(receiver).sys, app: cast(receiver).app, ctx: cast(receiver).ctx });
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
_logValue(profiler: Profiler, context: any, value: any, options: IAopMethodOptionsLog, message: string) {
|
|
95
|
+
const info: any = { level: options.level, message };
|
|
96
|
+
if (context) info.context = context;
|
|
97
|
+
info.value = value;
|
|
98
|
+
profiler.done(info);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
_logResult(profiler: Profiler, context: any, res: any, options: IAopMethodOptionsLog, message: string) {
|
|
102
|
+
const info: any = { level: options.level, message };
|
|
103
|
+
if (context) info.context = context;
|
|
104
|
+
if (res !== undefined) info.result = res;
|
|
105
|
+
profiler.done(info);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
_logError(profiler: Profiler, context: any, err: Error, _options: IAopMethodOptionsLog, message: string) {
|
|
109
|
+
const info: any = { level: 'error', message };
|
|
110
|
+
if (context) info.context = context;
|
|
111
|
+
if (err) info.error = err;
|
|
112
|
+
profiler.done(info);
|
|
113
|
+
}
|
|
114
|
+
}
|
package/src/index.ts
ADDED
package/src/lib/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './log.js';
|
package/src/lib/log.ts
ADDED
package/README.md
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
# @cabloy/set
|