@onivoro/server-pino 22.0.0 → 22.0.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.
@@ -1,2 +1,3 @@
1
1
  export * from './lib/classes/server-pino-config.class';
2
+ export * from './lib/functions/patch-console.function';
2
3
  export * from './lib/server-pino.module';
package/dist/cjs/index.js CHANGED
@@ -15,4 +15,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./lib/classes/server-pino-config.class"), exports);
18
+ __exportStar(require("./lib/functions/patch-console.function"), exports);
18
19
  __exportStar(require("./lib/server-pino.module"), exports);
@@ -0,0 +1,5 @@
1
+ import { PinoLogger } from 'nestjs-pino';
2
+ export declare function patchConsole(logger: PinoLogger): {
3
+ _console: PinoLogger;
4
+ restore: () => void;
5
+ };
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.patchConsole = patchConsole;
4
+ function patchConsole(logger) {
5
+ const _console = logger;
6
+ const original = {
7
+ debug: console.debug,
8
+ error: console.error,
9
+ info: console.info,
10
+ log: console.log,
11
+ trace: console.trace,
12
+ warn: console.warn,
13
+ };
14
+ console.debug = (...args) => {
15
+ _console.debug(...args);
16
+ };
17
+ console.error = (...args) => {
18
+ _console.error(...args);
19
+ };
20
+ console.info = (...args) => {
21
+ _console.debug(...args);
22
+ };
23
+ console.log = (...args) => {
24
+ _console.debug(...args); // what should this be? which is higher level?
25
+ };
26
+ console.trace = (...args) => {
27
+ _console.trace(...args);
28
+ };
29
+ console.warn = (...args) => {
30
+ _console.warn(...args);
31
+ };
32
+ return {
33
+ _console,
34
+ restore: () => {
35
+ Object.entries(original).forEach(([method, implementation]) => {
36
+ console[method] = implementation;
37
+ });
38
+ }
39
+ };
40
+ }
@@ -1,4 +1,4 @@
1
1
  import { ServerPinoConfig } from './classes/server-pino-config.class';
2
2
  export declare class ServerPinoModule {
3
- static configure(config: ServerPinoConfig): any;
3
+ static configure(config: ServerPinoConfig, patchConsoleInstance?: boolean): any;
4
4
  }
@@ -9,14 +9,21 @@ var ServerPinoModule_1;
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
10
  exports.ServerPinoModule = void 0;
11
11
  const common_1 = require("@nestjs/common");
12
+ const nestjs_pino_1 = require("nestjs-pino");
12
13
  const server_pino_config_class_1 = require("./classes/server-pino-config.class");
13
14
  const server_common_1 = require("@onivoro/server-common");
15
+ const patch_console_function_1 = require("./functions/patch-console.function");
14
16
  let ServerPinoModule = ServerPinoModule_1 = class ServerPinoModule {
15
- static configure(config) {
17
+ static configure(config, patchConsoleInstance = false) {
18
+ if (patchConsoleInstance) {
19
+ (0, patch_console_function_1.patchConsole)(new nestjs_pino_1.PinoLogger(config));
20
+ }
16
21
  return (0, server_common_1.moduleFactory)({
17
22
  module: ServerPinoModule_1,
23
+ imports: [nestjs_pino_1.LoggerModule.forRoot(config)],
18
24
  providers: [
19
25
  { provide: server_pino_config_class_1.ServerPinoConfig, useValue: config },
26
+ // { provide: Logger, useFactory: (logger: PinoLogger) => logger, inject: [PinoLogger] }
20
27
  ]
21
28
  });
22
29
  }
@@ -1,2 +1,3 @@
1
1
  export * from './lib/classes/server-pino-config.class';
2
+ export * from './lib/functions/patch-console.function';
2
3
  export * from './lib/server-pino.module';
package/dist/esm/index.js CHANGED
@@ -15,4 +15,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./lib/classes/server-pino-config.class"), exports);
18
+ __exportStar(require("./lib/functions/patch-console.function"), exports);
18
19
  __exportStar(require("./lib/server-pino.module"), exports);
@@ -0,0 +1,5 @@
1
+ import { PinoLogger } from 'nestjs-pino';
2
+ export declare function patchConsole(logger: PinoLogger): {
3
+ _console: PinoLogger;
4
+ restore: () => void;
5
+ };
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.patchConsole = patchConsole;
4
+ function patchConsole(logger) {
5
+ const _console = logger;
6
+ const original = {
7
+ debug: console.debug,
8
+ error: console.error,
9
+ info: console.info,
10
+ log: console.log,
11
+ trace: console.trace,
12
+ warn: console.warn,
13
+ };
14
+ console.debug = (...args) => {
15
+ _console.debug(...args);
16
+ };
17
+ console.error = (...args) => {
18
+ _console.error(...args);
19
+ };
20
+ console.info = (...args) => {
21
+ _console.debug(...args);
22
+ };
23
+ console.log = (...args) => {
24
+ _console.debug(...args); // what should this be? which is higher level?
25
+ };
26
+ console.trace = (...args) => {
27
+ _console.trace(...args);
28
+ };
29
+ console.warn = (...args) => {
30
+ _console.warn(...args);
31
+ };
32
+ return {
33
+ _console,
34
+ restore: () => {
35
+ Object.entries(original).forEach(([method, implementation]) => {
36
+ console[method] = implementation;
37
+ });
38
+ }
39
+ };
40
+ }
@@ -1,4 +1,4 @@
1
1
  import { ServerPinoConfig } from './classes/server-pino-config.class';
2
2
  export declare class ServerPinoModule {
3
- static configure(config: ServerPinoConfig): any;
3
+ static configure(config: ServerPinoConfig, patchConsoleInstance?: boolean): any;
4
4
  }
@@ -9,14 +9,21 @@ var ServerPinoModule_1;
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
10
  exports.ServerPinoModule = void 0;
11
11
  const common_1 = require("@nestjs/common");
12
+ const nestjs_pino_1 = require("nestjs-pino");
12
13
  const server_pino_config_class_1 = require("./classes/server-pino-config.class");
13
14
  const server_common_1 = require("@onivoro/server-common");
15
+ const patch_console_function_1 = require("./functions/patch-console.function");
14
16
  let ServerPinoModule = ServerPinoModule_1 = class ServerPinoModule {
15
- static configure(config) {
17
+ static configure(config, patchConsoleInstance = false) {
18
+ if (patchConsoleInstance) {
19
+ (0, patch_console_function_1.patchConsole)(new nestjs_pino_1.PinoLogger(config));
20
+ }
16
21
  return (0, server_common_1.moduleFactory)({
17
22
  module: ServerPinoModule_1,
23
+ imports: [nestjs_pino_1.LoggerModule.forRoot(config)],
18
24
  providers: [
19
25
  { provide: server_pino_config_class_1.ServerPinoConfig, useValue: config },
26
+ // { provide: Logger, useFactory: (logger: PinoLogger) => logger, inject: [PinoLogger] }
20
27
  ]
21
28
  });
22
29
  }
@@ -1,2 +1,3 @@
1
1
  export * from './lib/classes/server-pino-config.class';
2
+ export * from './lib/functions/patch-console.function';
2
3
  export * from './lib/server-pino.module';
@@ -0,0 +1,5 @@
1
+ import { PinoLogger } from 'nestjs-pino';
2
+ export declare function patchConsole(logger: PinoLogger): {
3
+ _console: PinoLogger;
4
+ restore: () => void;
5
+ };
@@ -1,4 +1,4 @@
1
1
  import { ServerPinoConfig } from './classes/server-pino-config.class';
2
2
  export declare class ServerPinoModule {
3
- static configure(config: ServerPinoConfig): any;
3
+ static configure(config: ServerPinoConfig, patchConsoleInstance?: boolean): any;
4
4
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onivoro/server-pino",
3
- "version": "22.0.0",
3
+ "version": "22.0.1",
4
4
  "repository": {
5
5
  "url": "git+https://github.com/onivoro/server-pino.git"
6
6
  },
@@ -44,4 +44,4 @@
44
44
  "@onivoro/server-common": "^22.0.3",
45
45
  "nestjs-pino": "^4.1.0"
46
46
  }
47
- }
47
+ }