@athenna/logger 1.1.3 → 1.1.6

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/index.d.ts CHANGED
@@ -7,6 +7,7 @@
7
7
  * file that was distributed with this source code.
8
8
  */
9
9
  export * from './src/Logger';
10
+ export * from './src/Facades/Log';
10
11
  export * from './src/Utils/Color';
11
12
  export * from './src/Contracts/DriverContract';
12
13
  export * from './src/Contracts/FormatterContract';
package/index.js CHANGED
@@ -19,6 +19,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
19
19
  };
20
20
  Object.defineProperty(exports, "__esModule", { value: true });
21
21
  __exportStar(require("./src/Logger"), exports);
22
+ __exportStar(require("./src/Facades/Log"), exports);
22
23
  __exportStar(require("./src/Utils/Color"), exports);
23
24
  __exportStar(require("./src/Contracts/DriverContract"), exports);
24
25
  __exportStar(require("./src/Contracts/FormatterContract"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@athenna/logger",
3
- "version": "1.1.3",
3
+ "version": "1.1.6",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "author": "João Lenon <lenon@athenna.io>",
@@ -0,0 +1,10 @@
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 { Logger } from '../Logger';
10
+ export declare const Log: Logger;
@@ -0,0 +1,13 @@
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.Log = void 0;
12
+ const Handler_1 = require("../Utils/Handler");
13
+ exports.Log = new Proxy({}, new Handler_1.Handler('Athenna/Core/Logger'));
@@ -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;
@@ -18,7 +18,7 @@ class LoggerProvider extends ioc_1.ServiceProvider {
18
18
  * @return void
19
19
  */
20
20
  register() {
21
- this.container.bind('Athenna/Core/Logger', Logger_1.Logger);
21
+ this.container.instance('Athenna/Core/Logger', new Logger_1.Logger());
22
22
  }
23
23
  }
24
24
  exports.LoggerProvider = LoggerProvider;
@@ -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(
@@ -0,0 +1,13 @@
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
+ export declare class Handler {
10
+ private readonly alias;
11
+ constructor(alias: any);
12
+ get(_object: any, key: string): any;
13
+ }
@@ -0,0 +1,24 @@
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.Handler = void 0;
12
+ class Handler {
13
+ constructor(alias) {
14
+ this.alias = alias;
15
+ }
16
+ get(_object, key) {
17
+ const provider = ioc.use(this.alias);
18
+ if (!provider) {
19
+ return () => { };
20
+ }
21
+ return provider[key];
22
+ }
23
+ }
24
+ exports.Handler = Handler;