@athenna/logger 1.1.3 → 1.1.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@athenna/logger",
3
- "version": "1.1.3",
3
+ "version": "1.1.4",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "author": "João Lenon <lenon@athenna.io>",
@@ -9,12 +9,13 @@
9
9
  */
10
10
  Object.defineProperty(exports, "__esModule", { value: true });
11
11
  exports.FormatterFactory = void 0;
12
+ const CliFormatter_1 = require("../Formatters/CliFormatter");
12
13
  const JsonFormatter_1 = require("../Formatters/JsonFormatter");
13
14
  const NestFormatter_1 = require("../Formatters/NestFormatter");
14
15
  const SimpleFormatter_1 = require("../Formatters/SimpleFormatter");
16
+ const RequestFormatter_1 = require("../Formatters/RequestFormatter");
15
17
  const NotFoundFormatterException_1 = require("../Exceptions/NotFoundFormatterException");
16
18
  const FormatterAlreadyExistException_1 = require("../Exceptions/FormatterAlreadyExistException");
17
- const CliFormatter_1 = require("../Formatters/CliFormatter");
18
19
  class FormatterFactory {
19
20
  static availableFormatters() {
20
21
  const availableFormatters = [];
@@ -42,4 +43,5 @@ FormatterFactory.formatters = new Map()
42
43
  .set('cli', { Formatter: CliFormatter_1.CliFormatter })
43
44
  .set('nest', { Formatter: NestFormatter_1.NestFormatter })
44
45
  .set('json', { Formatter: JsonFormatter_1.JsonFormatter })
45
- .set('simple', { Formatter: SimpleFormatter_1.SimpleFormatter });
46
+ .set('simple', { Formatter: SimpleFormatter_1.SimpleFormatter })
47
+ .set('request', { Formatter: RequestFormatter_1.RequestFormatter });
@@ -14,11 +14,10 @@ class RequestFormatter {
14
14
  format(ctx, options) {
15
15
  const ip = ctx.request.ip;
16
16
  const status = ctx.status;
17
- const baseUrl = ctx.request.baseUrl;
18
- const method = Color_1.Color[ctx.request.method];
19
- const responseTimeMs = `${ctx.responseTime}ms`;
17
+ const responseTimeMs = `${Math.round(ctx.responseTime)}ms`;
18
+ const methodAndUrl = Color_1.Color[ctx.request.method](`${ctx.request.method}::${ctx.request.baseUrl}`);
20
19
  if (!options.asJson) {
21
- return `(${ip}) - [${status}] ${method}::${baseUrl} ${responseTimeMs}`;
20
+ return `(${ip}) - [${status}] ${methodAndUrl} ${responseTimeMs}`;
22
21
  }
23
22
  const metadata = {
24
23
  method: ctx.request.method,
@@ -28,12 +27,21 @@ class RequestFormatter {
28
27
  url: ctx.request.hostUrl,
29
28
  path: ctx.request.baseUrl,
30
29
  createdAt: Date.now(),
30
+ data: ctx.data,
31
31
  };
32
- return JSON.stringify({
33
- request: JSON.stringify(ctx.request),
34
- response: JSON.stringify(ctx.response),
35
- metadata,
36
- });
32
+ const request = {
33
+ url: ctx.request.hostUrl,
34
+ method: ctx.request.method,
35
+ body: ctx.request.body,
36
+ params: ctx.request.params,
37
+ queries: ctx.request.queries,
38
+ headers: ctx.request.headers,
39
+ };
40
+ const response = {
41
+ body: ctx.body,
42
+ headers: ctx.headers,
43
+ };
44
+ return JSON.stringify({ request, response, metadata });
37
45
  }
38
46
  }
39
47
  exports.RequestFormatter = RequestFormatter;
@@ -60,25 +60,25 @@ class Color {
60
60
  return this.orange.bold;
61
61
  }
62
62
  static get GET() {
63
- return this.purple.bold('GET');
63
+ return this.purple.bold;
64
64
  }
65
65
  static get HEAD() {
66
- return this.cyan.bold('HEAD');
66
+ return this.cyan.bold;
67
67
  }
68
68
  static get PUT() {
69
- return this.orange.bold('PUT');
69
+ return this.orange.bold;
70
70
  }
71
71
  static get PATCH() {
72
- return this.yellow.bold('PATCH');
72
+ return this.yellow.bold;
73
73
  }
74
74
  static get POST() {
75
- return this.green.bold('POST');
75
+ return this.green.bold;
76
76
  }
77
77
  static get DELETE() {
78
- return this.red.bold('DELETE');
78
+ return this.red.bold;
79
79
  }
80
80
  static get OPTIONS() {
81
- return this.cyan.bold('OPTIONS');
81
+ return this.cyan.bold;
82
82
  }
83
83
  static removeColors(string) {
84
84
  return Color.chalk.reset(string).replace(