@athenna/logger 1.1.2 → 1.1.3

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.2",
3
+ "version": "1.1.3",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "author": "João Lenon <lenon@athenna.io>",
@@ -153,8 +153,8 @@
153
153
  }
154
154
  },
155
155
  "dependencies": {
156
- "@athenna/ioc": "1.1.1",
157
- "@secjs/utils": "1.8.2",
156
+ "@athenna/ioc": "1.1.2",
157
+ "@secjs/utils": "1.8.3",
158
158
  "chalk": "4.1.1",
159
159
  "reflect-metadata": "0.1.13",
160
160
  "tscpaths": "0.0.9"
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @athenna/logger
3
+ *
4
+ * (c) João Lenon <lenon@athenna.io>
5
+ *
6
+ * For the full copyright and license information, please view the LICENSE
7
+ * file that was distributed with this source code.
8
+ */
9
+ import { Chalk } from 'chalk';
10
+ import { FormatterContract } from '../Contracts/FormatterContract';
11
+ export interface RequestFormatterOptions {
12
+ chalk: Chalk;
13
+ asJson: boolean;
14
+ }
15
+ export declare class RequestFormatter implements FormatterContract {
16
+ format(ctx: any, options: RequestFormatterOptions): string;
17
+ }
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ /**
3
+ * @athenna/logger
4
+ *
5
+ * (c) João Lenon <lenon@athenna.io>
6
+ *
7
+ * For the full copyright and license information, please view the LICENSE
8
+ * file that was distributed with this source code.
9
+ */
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.RequestFormatter = void 0;
12
+ const Color_1 = require("../Utils/Color");
13
+ class RequestFormatter {
14
+ format(ctx, options) {
15
+ const ip = ctx.request.ip;
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`;
20
+ if (!options.asJson) {
21
+ return `(${ip}) - [${status}] ${method}::${baseUrl} ${responseTimeMs}`;
22
+ }
23
+ const metadata = {
24
+ method: ctx.request.method,
25
+ duration: responseTimeMs,
26
+ status: status <= 399 ? 'SUCCESS' : 'ERROR',
27
+ statusCode: status,
28
+ url: ctx.request.hostUrl,
29
+ path: ctx.request.baseUrl,
30
+ createdAt: Date.now(),
31
+ };
32
+ return JSON.stringify({
33
+ request: JSON.stringify(ctx.request),
34
+ response: JSON.stringify(ctx.response),
35
+ metadata,
36
+ });
37
+ }
38
+ }
39
+ exports.RequestFormatter = RequestFormatter;
@@ -30,16 +30,19 @@ export declare class Color {
30
30
  static get green(): Chalk;
31
31
  static get darkGreen(): Chalk;
32
32
  static get red(): Chalk;
33
- static removeColors(string: string): any;
34
33
  static get info(): any;
35
34
  static get log(): any;
36
35
  static get debug(): any;
37
36
  static get error(): any;
38
37
  static get warning(): any;
39
- static httpMethod(method: Methods): any;
40
38
  static get GET(): any;
39
+ static get HEAD(): any;
41
40
  static get PUT(): any;
41
+ static get PATCH(): any;
42
42
  static get POST(): any;
43
43
  static get DELETE(): any;
44
+ static get OPTIONS(): any;
45
+ static removeColors(string: string): any;
46
+ static httpMethod(method: Methods): any;
44
47
  }
45
48
  export {};
@@ -44,11 +44,6 @@ class Color {
44
44
  static get red() {
45
45
  return Color.chalk.hex('#f10e0e');
46
46
  }
47
- static removeColors(string) {
48
- return Color.chalk.reset(string).replace(
49
- // eslint-disable-next-line no-control-regex
50
- /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, '');
51
- }
52
47
  static get info() {
53
48
  return this.cyan.bold;
54
49
  }
@@ -64,20 +59,34 @@ class Color {
64
59
  static get warning() {
65
60
  return this.orange.bold;
66
61
  }
67
- static httpMethod(method) {
68
- return this[method];
69
- }
70
62
  static get GET() {
71
- return this.purple.bold('GET 🔍');
63
+ return this.purple.bold('GET');
64
+ }
65
+ static get HEAD() {
66
+ return this.cyan.bold('HEAD');
72
67
  }
73
68
  static get PUT() {
74
- return this.yellow.bold('PUT 🛠');
69
+ return this.orange.bold('PUT');
70
+ }
71
+ static get PATCH() {
72
+ return this.yellow.bold('PATCH');
75
73
  }
76
74
  static get POST() {
77
- return this.green.bold('POST 🧱');
75
+ return this.green.bold('POST');
78
76
  }
79
77
  static get DELETE() {
80
- return this.red.bold('DELETE');
78
+ return this.red.bold('DELETE');
79
+ }
80
+ static get OPTIONS() {
81
+ return this.cyan.bold('OPTIONS');
82
+ }
83
+ static removeColors(string) {
84
+ return Color.chalk.reset(string).replace(
85
+ // eslint-disable-next-line no-control-regex
86
+ /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, '');
87
+ }
88
+ static httpMethod(method) {
89
+ return this[method];
81
90
  }
82
91
  }
83
92
  exports.Color = Color;