vona-module-a-logger 5.0.16 → 5.0.17

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.
@@ -6,7 +6,6 @@ export interface IAopMethodOptionsLog extends IDecoratorAopMethodOptions {
6
6
  level: LoggerLevel;
7
7
  childName?: keyof ILoggerClientChildRecord;
8
8
  clientName?: keyof ILoggerClientRecord;
9
- auto?: boolean;
10
9
  args?: boolean;
11
10
  result?: boolean;
12
11
  context?: Record<string, any>;
@@ -16,6 +15,7 @@ export declare class AopMethodLog extends BeanAopMethodBase implements IAopMetho
16
15
  set(options: IAopMethodOptionsLog, value: any, next: NextSync, receiver: any, prop: string): boolean;
17
16
  execute(options: IAopMethodOptionsLog, _args: [], next: Next | NextSync, receiver: any, prop: string): Promise<any> | any;
18
17
  _getContext(options: IAopMethodOptionsLog, receiver: any): any;
18
+ _logValue(profiler: winston.Profiler, context: any, value: any, options: IAopMethodOptionsLog, message: string): void;
19
19
  _logResult(profiler: winston.Profiler, context: any, res: any, options: IAopMethodOptionsLog, message: string): void;
20
20
  _logError(profiler: winston.Profiler, context: any, err: Error, _options: IAopMethodOptionsLog, message: string): void;
21
21
  }
package/dist/index.js CHANGED
@@ -13,7 +13,7 @@ let MiddlewareSystemHttpLog = (_dec$4 = MiddlewareSystem(), _dec2$4 = BeanInfo({
13
13
  const ctx = this.ctx;
14
14
  // start
15
15
  const req = StdSerializers.req(ctx.req);
16
- this.$loggerChild('req').http(JSON.stringify(req));
16
+ this.$loggerChild('req').http(() => JSON.stringify(req));
17
17
  const profiler = this.$loggerChild('res').startTimer();
18
18
  // next
19
19
  await next();
@@ -41,9 +41,6 @@ let AopMethodLog = (_dec$3 = AopMethod({
41
41
  const message = `${receiver[SymbolBeanFullName]}#${prop}(get)`;
42
42
  const logger = this.app.meta.logger.child(options.childName, options.clientName);
43
43
  // begin
44
- !options.auto && logger.log(options.level, message, context ? {
45
- context
46
- } : undefined);
47
44
  const profiler = logger.startTimer();
48
45
  // next
49
46
  try {
@@ -60,14 +57,11 @@ let AopMethodLog = (_dec$3 = AopMethod({
60
57
  const message = `${receiver[SymbolBeanFullName]}#${prop}(set)`;
61
58
  const logger = this.app.meta.logger.child(options.childName, options.clientName);
62
59
  // begin
63
- logger.log(options.level, `${message} value: ${JSON.stringify(value)}`, context ? {
64
- context
65
- } : undefined);
66
60
  const profiler = logger.startTimer();
67
61
  // next
68
62
  try {
69
63
  const res = next();
70
- !options.auto && this._logResult(profiler, context, undefined, options, message);
64
+ this._logValue(profiler, context, value, options, message);
71
65
  return res;
72
66
  } catch (err) {
73
67
  this._logError(profiler, context, err, options, message);
@@ -79,7 +73,7 @@ let AopMethodLog = (_dec$3 = AopMethod({
79
73
  const message = `${receiver[SymbolBeanFullName]}#${prop}`;
80
74
  const logger = this.app.meta.logger.child(options.childName, options.clientName);
81
75
  // begin
82
- options.args !== false && logger.log(options.level, `${message} args: ${JSON.stringify(_args)}`, context ? {
76
+ options.args !== false && logger.log(options.level, () => `${message} args: ${JSON.stringify(_args)}`, context ? {
83
77
  context
84
78
  } : undefined);
85
79
  const profiler = logger.startTimer();
@@ -109,20 +103,35 @@ let AopMethodLog = (_dec$3 = AopMethod({
109
103
  ctx: cast(receiver).ctx
110
104
  });
111
105
  }
106
+ _logValue(profiler, context, value, options, message) {
107
+ const info = {
108
+ level: options.level,
109
+ message: () => {
110
+ const textValue = ` value: ${JSON.stringify(value)}`;
111
+ return `${message}${textValue}`;
112
+ }
113
+ };
114
+ if (context) info.context = context;
115
+ profiler.done(info);
116
+ }
112
117
  _logResult(profiler, context, res, options, message) {
113
- const textResult = res !== undefined ? ` result: ${JSON.stringify(res)}` : '';
114
118
  const info = {
115
119
  level: options.level,
116
- message: `${message}${textResult}`
120
+ message: () => {
121
+ const textResult = res !== undefined ? ` result: ${JSON.stringify(res)}` : '';
122
+ return `${message}${textResult}`;
123
+ }
117
124
  };
118
125
  if (context) info.context = context;
119
126
  profiler.done(info);
120
127
  }
121
128
  _logError(profiler, context, err, _options, message) {
122
- const textError = ` error: ${err.message}`;
123
129
  const info = {
124
130
  level: 'error',
125
- message: `${message}${textError}`
131
+ message: () => {
132
+ const textError = ` error: ${err.message}`;
133
+ return `${message}${textError}`;
134
+ }
126
135
  };
127
136
  if (context) info.context = context;
128
137
  profiler.done(info);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vona-module-a-logger",
3
3
  "type": "module",
4
- "version": "5.0.16",
4
+ "version": "5.0.17",
5
5
  "title": "a-logger",
6
6
  "vonaModule": {
7
7
  "dependencies": {}