nestjs-fox-logger 0.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.
package/README.md ADDED
@@ -0,0 +1,85 @@
1
+ <div align="center">
2
+ <a href="http://nestjs.com/" target="_blank">
3
+ <img src="https://nestjs.com/img/logo_text.svg" width="150" alt="Nest Logo" />
4
+ </a>
5
+ </div>
6
+
7
+ <h3 align="center">NestJS Logger Module with Cls</h3>
8
+
9
+ <div align="center">
10
+ <a href="https://nestjs.com" target="_blank">
11
+ <img src="https://img.shields.io/badge/built%20with-NestJs-red.svg" alt="Built with NestJS">
12
+ </a>
13
+ </div>
14
+
15
+ ### Введение
16
+
17
+ Модуль логгера с поддержкой CLS
18
+
19
+ ### Установка
20
+
21
+ ```bash
22
+ npm install --save nestjs-fox-logger
23
+ ```
24
+
25
+ ### Использование
26
+
27
+ #### Импорт
28
+
29
+ ```ts
30
+ // В корневом модуле
31
+ import { ClsModule } from 'nestjs-cls';
32
+
33
+ @Module({
34
+ imports: [
35
+ ClsModule.forRoot({
36
+ middleware: {
37
+ mount: true,
38
+ generateId: true,
39
+ idGenerator: (req: Request) => req.headers['X-Request-Id'] ?? nanoid(),
40
+ },
41
+ global: true,
42
+ }),
43
+ ],
44
+ })
45
+ export class AppModule {}
46
+
47
+ ///... в конкретном модуле
48
+ import { FoxLoggerModule } from 'nestjs-fox-logger';
49
+
50
+ @Module({
51
+ imports: [
52
+ LoggerModule.forFeature({
53
+ name: UsersModule.name,
54
+ }),
55
+ ],
56
+ controllers: [],
57
+ providers: [],
58
+ exports: [],
59
+ })
60
+ export class UsersModule {}
61
+ ```
62
+
63
+ #### Вызовы
64
+
65
+ ```typescript
66
+ import { LoopService } from 'nestjs-fox-logger';
67
+
68
+ @Injectable()
69
+ export class YourService {
70
+ constructor(private readonly logger: FoxLoggerService) {}
71
+
72
+ async foo() {
73
+ const eventId = nanoid();
74
+ await this.logger.log('someMessage', eventId);
75
+ }
76
+ }
77
+ ```
78
+
79
+ ## Author
80
+
81
+ **Semen Kononets ([GitHub](https://github.com/triple-sun))**
82
+
83
+ ## LICENSE
84
+
85
+ MIT
@@ -0,0 +1,8 @@
1
+ import { DynamicModule, Provider } from '@nestjs/common';
2
+ import { FoxLoggerServiceAsyncOptions, FoxLoggerServiceOptions } from './fox-logger.interfaces';
3
+ export declare class FoxLoggerCoreModule {
4
+ static forRoot(options: FoxLoggerServiceOptions): DynamicModule;
5
+ static forRootAsync(options: FoxLoggerServiceAsyncOptions): DynamicModule;
6
+ static createAsyncProviders(options: FoxLoggerServiceAsyncOptions): Provider[];
7
+ private static createAsyncOptionsProvider;
8
+ }
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var FoxLoggerCoreModule_1;
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.FoxLoggerCoreModule = void 0;
11
+ const common_1 = require("@nestjs/common");
12
+ const fox_logger_const_1 = require("./fox-logger.const");
13
+ const fox_logger_service_1 = require("./fox-logger.service");
14
+ let FoxLoggerCoreModule = FoxLoggerCoreModule_1 = class FoxLoggerCoreModule {
15
+ static forRoot(options) {
16
+ const LoopModuleOptionsProvider = {
17
+ provide: fox_logger_const_1.FOXLOGGER_SERVICE_OPTIONS,
18
+ useValue: options,
19
+ };
20
+ return {
21
+ module: FoxLoggerCoreModule_1,
22
+ providers: [LoopModuleOptionsProvider, fox_logger_service_1.FoxLoggerService],
23
+ exports: [fox_logger_service_1.FoxLoggerService],
24
+ };
25
+ }
26
+ static forRootAsync(options) {
27
+ const providers = this.createAsyncProviders(options);
28
+ return {
29
+ module: FoxLoggerCoreModule_1,
30
+ providers: [
31
+ ...providers,
32
+ fox_logger_service_1.FoxLoggerService,
33
+ ...(options.extraProviders || []),
34
+ ],
35
+ imports: options.imports,
36
+ exports: [
37
+ fox_logger_service_1.FoxLoggerService,
38
+ ],
39
+ };
40
+ }
41
+ static createAsyncProviders(options) {
42
+ const providers = [this.createAsyncOptionsProvider(options)];
43
+ if (options.useClass) {
44
+ providers.push({
45
+ provide: options.useClass,
46
+ useClass: options.useClass,
47
+ });
48
+ }
49
+ return providers;
50
+ }
51
+ static createAsyncOptionsProvider(options) {
52
+ if (options.useFactory) {
53
+ return {
54
+ name: fox_logger_const_1.FOXLOGGER_SERVICE_OPTIONS,
55
+ provide: fox_logger_const_1.FOXLOGGER_SERVICE_OPTIONS,
56
+ useFactory: options.useFactory,
57
+ inject: options.inject || [],
58
+ };
59
+ }
60
+ return {
61
+ name: fox_logger_const_1.FOXLOGGER_SERVICE_OPTIONS,
62
+ provide: fox_logger_const_1.FOXLOGGER_SERVICE_OPTIONS,
63
+ useFactory: async (optionsFactory) => {
64
+ return optionsFactory.createLoopOptions();
65
+ },
66
+ inject: [options.useExisting || options.useClass],
67
+ };
68
+ }
69
+ };
70
+ exports.FoxLoggerCoreModule = FoxLoggerCoreModule;
71
+ exports.FoxLoggerCoreModule = FoxLoggerCoreModule = FoxLoggerCoreModule_1 = __decorate([
72
+ (0, common_1.Global)(),
73
+ (0, common_1.Module)({})
74
+ ], FoxLoggerCoreModule);
75
+ //# sourceMappingURL=fox-logger-core.module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fox-logger-core.module.js","sourceRoot":"","sources":["../src/fox-logger-core.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAMwB;AAExB,yDAA+D;AAM/D,6DAAwD;AAIjD,IAAM,mBAAmB,2BAAzB,MAAM,mBAAmB;IAEv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CAAC;QAED,OAAO;YACL,IAAI,EAAE,4CAAyB;YAC/B,OAAO,EAAE,4CAAyB;YAClC,UAAU,EAAE,KAAK,EAAE,cAA8C,EAAE,EAAE;gBACnE,OAAO,cAAc,CAAC,iBAAiB,EAAE,CAAC;YAC5C,CAAC;YACD,MAAM,EAAE,CAAC,OAAO,CAAC,WAAY,IAAI,OAAO,CAAC,QAAS,CAAC;SACpD,CAAC;IACJ,CAAC;CACF,CAAA;AA1EY,kDAAmB;8BAAnB,mBAAmB;IAF/B,IAAA,eAAM,GAAE;IACR,IAAA,eAAM,EAAC,EAAE,CAAC;GACE,mBAAmB,CA0E/B"}
@@ -0,0 +1 @@
1
+ export declare const FOXLOGGER_SERVICE_OPTIONS = "FOXLOGGER_SERVICE_OPTIONS";
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FOXLOGGER_SERVICE_OPTIONS = void 0;
4
+ exports.FOXLOGGER_SERVICE_OPTIONS = 'FOXLOGGER_SERVICE_OPTIONS';
5
+ //# sourceMappingURL=fox-logger.const.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fox-logger.const.js","sourceRoot":"","sources":["../src/fox-logger.const.ts"],"names":[],"mappings":";;;AAAa,QAAA,yBAAyB,GAAG,2BAA2B,CAAC"}
@@ -0,0 +1,18 @@
1
+ import { ModuleMetadata, Provider, Type } from '@nestjs/common';
2
+ export interface FoxLoggerServiceOptions {
3
+ name?: string;
4
+ timestamp?: boolean;
5
+ }
6
+ export interface FoxLoggerServiceFeatureOptions extends FoxLoggerServiceOptions {
7
+ name: Required<string>;
8
+ }
9
+ export interface FoxLoggerServiceOptionsFactory {
10
+ createLoopOptions(): Promise<FoxLoggerServiceOptions> | FoxLoggerServiceOptions;
11
+ }
12
+ export interface FoxLoggerServiceAsyncOptions extends Pick<ModuleMetadata, 'imports'> {
13
+ inject?: any[];
14
+ useClass?: Type<FoxLoggerServiceOptionsFactory>;
15
+ useExisting?: Type<FoxLoggerServiceOptionsFactory>;
16
+ useFactory?: (...args: any[]) => Promise<FoxLoggerServiceOptions> | FoxLoggerServiceOptions;
17
+ extraProviders?: Provider[];
18
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=fox-logger.interfaces.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fox-logger.interfaces.js","sourceRoot":"","sources":["../src/fox-logger.interfaces.ts"],"names":[],"mappings":""}
@@ -0,0 +1,8 @@
1
+ import { DynamicModule } from '@nestjs/common';
2
+ import { FoxLoggerServiceAsyncOptions, FoxLoggerServiceOptions } from './fox-logger.interfaces';
3
+ export declare class FoxLoggerModule {
4
+ static forRoot(options: FoxLoggerServiceOptions): DynamicModule;
5
+ static forRootAsync(options: FoxLoggerServiceAsyncOptions): DynamicModule;
6
+ static forFeature(options: FoxLoggerServiceOptions): DynamicModule;
7
+ static forFeatureAsync(options: FoxLoggerServiceAsyncOptions): DynamicModule;
8
+ }
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var FoxLoggerModule_1;
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.FoxLoggerModule = void 0;
11
+ const common_1 = require("@nestjs/common");
12
+ const fox_logger_const_1 = require("./fox-logger.const");
13
+ const fox_logger_service_1 = require("./fox-logger.service");
14
+ const fox_logger_core_module_1 = require("./fox-logger-core.module");
15
+ let FoxLoggerModule = FoxLoggerModule_1 = class FoxLoggerModule {
16
+ static forRoot(options) {
17
+ return {
18
+ module: FoxLoggerModule_1,
19
+ imports: [
20
+ fox_logger_core_module_1.FoxLoggerCoreModule.forRoot(options),
21
+ ],
22
+ };
23
+ }
24
+ static forRootAsync(options) {
25
+ return {
26
+ module: FoxLoggerModule_1,
27
+ imports: [
28
+ fox_logger_core_module_1.FoxLoggerCoreModule.forRootAsync(options),
29
+ ],
30
+ };
31
+ }
32
+ static forFeature(options) {
33
+ const FoxLoggerOptionsProvider = {
34
+ provide: fox_logger_const_1.FOXLOGGER_SERVICE_OPTIONS,
35
+ useValue: options,
36
+ };
37
+ return {
38
+ module: FoxLoggerModule_1,
39
+ imports: [],
40
+ providers: [FoxLoggerOptionsProvider, fox_logger_service_1.FoxLoggerService],
41
+ exports: [FoxLoggerOptionsProvider, fox_logger_service_1.FoxLoggerService],
42
+ };
43
+ }
44
+ static forFeatureAsync(options) {
45
+ const providers = fox_logger_core_module_1.FoxLoggerCoreModule.createAsyncProviders(options);
46
+ return {
47
+ module: FoxLoggerModule_1,
48
+ providers: [
49
+ ...providers,
50
+ fox_logger_service_1.FoxLoggerService,
51
+ ...(options.extraProviders || []),
52
+ ],
53
+ imports: options.imports,
54
+ exports: [
55
+ ...providers,
56
+ fox_logger_service_1.FoxLoggerService,
57
+ ],
58
+ };
59
+ }
60
+ };
61
+ exports.FoxLoggerModule = FoxLoggerModule;
62
+ exports.FoxLoggerModule = FoxLoggerModule = FoxLoggerModule_1 = __decorate([
63
+ (0, common_1.Module)({})
64
+ ], FoxLoggerModule);
65
+ //# sourceMappingURL=fox-logger.module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fox-logger.module.js","sourceRoot":"","sources":["../src/fox-logger.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAAgF;AAEhF,yDAA+D;AAK/D,6DAAwD;AACxD,qEAA+D;AAGxD,IAAM,eAAe,uBAArB,MAAM,eAAe;IACnB,MAAM,CAAC,OAAO,CAAC,OAAgC;QACpD,OAAO;YACL,MAAM,EAAE,iBAAe;YACvB,OAAO,EAAE;gBAEP,4CAAmB,CAAC,OAAO,CAAC,OAAQ,CAAC;aACtC;SACF,CAAC;IACJ,CAAC;IAEM,MAAM,CAAC,YAAY,CACxB,OAAqC;QAErC,OAAO;YACL,MAAM,EAAE,iBAAe;YACvB,OAAO,EAAE;gBAEP,4CAAmB,CAAC,YAAY,CAAC,OAAO,CAAC;aAC1C;SACF,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,UAAU,CAAC,OAAgC;QAChD,MAAM,wBAAwB,GAA2C;YACvE,OAAO,EAAE,4CAAyB;YAClC,QAAQ,EAAE,OAAO;SAClB,CAAC;QAEF,OAAO;YACL,MAAM,EAAE,iBAAe;YACvB,OAAO,EAAE,EAAE;YACX,SAAS,EAAE,CAAC,wBAAwB,EAAE,qCAAgB,CAAC;YACvD,OAAO,EAAE,CAAC,wBAAwB,EAAE,qCAAgB,CAAC;SACtD,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,eAAe,CAAC,OAAqC;QAC1D,MAAM,SAAS,GACb,4CAAmB,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC;QAEpD,OAAO;YACL,MAAM,EAAE,iBAAe;YACvB,SAAS,EAAE;gBAET,GAAG,SAAS;gBAEZ,qCAAgB;gBAEhB,GAAG,CAAC,OAAO,CAAC,cAAc,IAAI,EAAE,CAAC;aAClC;YACD,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,OAAO,EAAE;gBACP,GAAG,SAAS;gBAEZ,qCAAgB;aACjB;SACF,CAAC;IACJ,CAAC;CACF,CAAA;AA3DY,0CAAe;0BAAf,eAAe;IAD3B,IAAA,eAAM,EAAC,EAAE,CAAC;GACE,eAAe,CA2D3B"}
@@ -0,0 +1,17 @@
1
+ import { Logger } from '@nestjs/common';
2
+ import { ClsService } from 'nestjs-cls';
3
+ import { FoxLoggerServiceOptions } from './fox-logger.interfaces';
4
+ export declare class FoxLoggerService extends Logger {
5
+ readonly options: FoxLoggerServiceOptions;
6
+ private readonly cls?;
7
+ private readonly name?;
8
+ constructor(options: FoxLoggerServiceOptions, cls?: ClsService);
9
+ private formatMsg;
10
+ private getPrefix;
11
+ log(msg: any, eventId?: string): void;
12
+ warn(msg: any, eventId?: string): void;
13
+ debug(msg: any, eventId?: string): void;
14
+ error(msg: any, eventId?: string): void;
15
+ verbose(msg: any, eventId?: string): void;
16
+ fatal(msg: any, eventId?: string): void;
17
+ }
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.FoxLoggerService = void 0;
16
+ const common_1 = require("@nestjs/common");
17
+ const nestjs_cls_1 = require("nestjs-cls");
18
+ const fox_logger_const_1 = require("./fox-logger.const");
19
+ let FoxLoggerService = class FoxLoggerService extends common_1.Logger {
20
+ constructor(options, cls) {
21
+ super();
22
+ this.options = options;
23
+ this.cls = cls;
24
+ this.name = options.name;
25
+ }
26
+ formatMsg(msg) {
27
+ switch (typeof msg) {
28
+ case 'string':
29
+ return msg;
30
+ case 'number':
31
+ case 'bigint':
32
+ case 'boolean':
33
+ case 'symbol':
34
+ case 'undefined':
35
+ case 'function':
36
+ return String(msg);
37
+ case 'object':
38
+ const prefix = [
39
+ 'statusCode' in msg && `[${msg.statusCode}]`,
40
+ 'status' in msg && `[${msg.status}]`,
41
+ 'error' in msg && `[${msg.error}]`,
42
+ ].filter(Boolean);
43
+ if (prefix.length > 0)
44
+ prefix.push(': ');
45
+ const message = [
46
+ msg['response']?.['data']?.['message'] &&
47
+ `: ${msg['data']['message']}`,
48
+ msg['data']?.['message'] && `: ${msg['data']['message']}`,
49
+ msg['message'] && `${msg['message']}`,
50
+ msg['msg'] && `${msg['msg']}`,
51
+ ].filter(Boolean);
52
+ if (prefix.length + message.length > 0) {
53
+ return prefix.join(``) + message.join(' ');
54
+ }
55
+ default:
56
+ JSON.stringify(msg);
57
+ }
58
+ }
59
+ getPrefix(eventId) {
60
+ return (`${this.name ? `[${this.name}]` : ``}` +
61
+ `${this.cls.getId() ? `[${this.cls.getId()}]` : ''}` +
62
+ `${eventId ? `[${eventId}]` : ``}`);
63
+ }
64
+ log(msg, eventId) {
65
+ return common_1.Logger.log(this.getPrefix(eventId) + `: ` + this.formatMsg(msg));
66
+ }
67
+ warn(msg, eventId) {
68
+ return common_1.Logger.warn(this.getPrefix(eventId) + `: ` + this.formatMsg(msg));
69
+ }
70
+ debug(msg, eventId) {
71
+ return common_1.Logger.debug(this.getPrefix(eventId) + `: ` + this.formatMsg(msg));
72
+ }
73
+ error(msg, eventId) {
74
+ return common_1.Logger.error(this.getPrefix(eventId) + `: ` + this.formatMsg(msg));
75
+ }
76
+ verbose(msg, eventId) {
77
+ return common_1.Logger.verbose(this.getPrefix(eventId) + `: ` + this.formatMsg(msg));
78
+ }
79
+ fatal(msg, eventId) {
80
+ return common_1.Logger.fatal(this.getPrefix(eventId) + `: ` + this.formatMsg(msg));
81
+ }
82
+ };
83
+ exports.FoxLoggerService = FoxLoggerService;
84
+ exports.FoxLoggerService = FoxLoggerService = __decorate([
85
+ (0, common_1.Injectable)(),
86
+ __param(0, (0, common_1.Inject)(fox_logger_const_1.FOXLOGGER_SERVICE_OPTIONS)),
87
+ __metadata("design:paramtypes", [Object, nestjs_cls_1.ClsService])
88
+ ], FoxLoggerService);
89
+ //# sourceMappingURL=fox-logger.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fox-logger.service.js","sourceRoot":"","sources":["../src/fox-logger.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA4D;AAC5D,2CAAwC;AAExC,yDAA+D;AAIxD,IAAM,gBAAgB,GAAtB,MAAM,gBAAiB,SAAQ,eAAM;IAG1C,YAEW,OAAgC,EACxB,GAAgB;QAEjC,KAAK,EAAE,CAAC;QAHC,YAAO,GAAP,OAAO,CAAyB;QACxB,QAAG,GAAH,GAAG,CAAa;QAGjC,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAC3B,CAAC;IAGO,SAAS,CAAC,GAAY;QAE5B,QAAQ,OAAO,GAAG,EAAE,CAAC;YACnB,KAAK,QAAQ;gBACX,OAAO,GAAG,CAAC;YACb,KAAK,QAAQ,CAAC;YACd,KAAK,QAAQ,CAAC;YACd,KAAK,SAAS,CAAC;YACf,KAAK,QAAQ,CAAC;YACd,KAAK,WAAW,CAAC;YACjB,KAAK,UAAU;gBACb,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC;YACrB,KAAK,QAAQ;gBAKX,MAAM,MAAM,GAAG;oBACb,YAAY,IAAI,GAAG,IAAI,IAAI,GAAG,CAAC,UAAU,GAAG;oBAC5C,QAAQ,IAAI,GAAG,IAAI,IAAI,GAAG,CAAC,MAAM,GAAG;oBACpC,OAAO,IAAI,GAAG,IAAI,IAAI,GAAG,CAAC,KAAK,GAAG;iBACnC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;gBAClB,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC;oBAAE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;gBACzC,MAAM,OAAO,GAAG;oBACd,GAAG,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Property(exports, "__esModule", { value: true });
3
+ const common_1 = require("@nestjs/common");
4
+ const testing_1 = require("@nestjs/testing");
5
+ const jest_mock_extended_1 = require("jest-mock-extended");
6
+ const nestjs_cls_1 = require("nestjs-cls");
7
+ const fox_logger_module_1 = require("./fox-logger.module");
8
+ const fox_logger_service_1 = require("./fox-logger.service");
9
+ describe('FoxLoggerService', () => {
10
+ let cls;
11
+ let service;
12
+ beforeEach(async () => {
13
+ const module = await testing_1.Test.createTestingModule({
14
+ imports: [
15
+ nestjs_cls_1.ClsModule.forRoot({
16
+ global: true,
17
+ }),
18
+ fox_logger_module_1.FoxLoggerModule.forFeature({
19
+ name: 'TEST',
20
+ }),
21
+ ],
22
+ providers: [fox_logger_service_1.FoxLoggerService, nestjs_cls_1.ClsService],
23
+ })
24
+ .overrideProvider(nestjs_cls_1.ClsService)
25
+ .useValue((0, jest_mock_extended_1.mockDeep)(nestjs_cls_1.ClsService))
26
+ .compile();
27
+ service = module.get(fox_logger_service_1.FoxLoggerService);
28
+ cls = module.get(nestjs_cls_1.ClsService);
29
+ });
30
+ it('should be defined', async () => {
31
+ expect(service).toBeDefined();
32
+ });
33
+ describe('.log', () => {
34
+ beforeEach(async () => {
35
+ jest.spyOn(common_1.Logger, 'log');
36
+ cls.getId.mockReturnValue('testLogId');
37
+ });
38
+ it('should call Logger.log', async () => {
39
+ service.log('test');
40
+ expect(common_1.Logger.log).toHaveBeenCalledTimes(1);
41
+ });
42
+ it('should call cls.getId()', async () => {
43
+ expect(cls.getId).toHaveBeenCalledTimes(2);
44
+ });
45
+ it('should call Logger.log with correct message', () => {
46
+ expect(common_1.Logger.log).toHaveBeenCalledWith(`[TEST][testLogId]: test`);
47
+ });
48
+ });
49
+ describe('.warn', () => {
50
+ beforeEach(() => {
51
+ jest.spyOn(common_1.Logger, 'warn');
52
+ cls.getId.mockReturnValue('testWarnId');
53
+ });
54
+ it('should call Logger.warn', async () => {
55
+ service.warn('test');
56
+ expect(common_1.Logger.warn).toHaveBeenCalledTimes(1);
57
+ });
58
+ it('should call cls.getId()', async () => {
59
+ expect(cls.getId).toHaveBeenCalledTimes(4);
60
+ });
61
+ it('should call Logger.warn with correct message', () => {
62
+ expect(common_1.Logger.warn).toHaveBeenCalledWith(`[TEST][testWarnId]: test`);
63
+ });
64
+ });
65
+ describe('.error', () => {
66
+ beforeEach(async () => {
67
+ jest.spyOn(common_1.Logger, 'error');
68
+ cls.getId.mockReturnValue('testErrId');
69
+ });
70
+ it('should call Logger.error', async () => {
71
+ service.error('error');
72
+ expect(common_1.Logger.error).toHaveBeenCalledTimes(1);
73
+ });
74
+ it('should call cls.getId()', async () => {
75
+ expect(cls.getId).toHaveBeenCalledWith();
76
+ });
77
+ it('should call Logger.warn with correct message', () => {
78
+ expect(common_1.Logger.error).toHaveBeenCalledWith(`[TEST][testErrId]: error`);
79
+ });
80
+ });
81
+ describe('.error (object)', () => {
82
+ beforeEach(async () => {
83
+ jest.spyOn(common_1.Logger, 'error');
84
+ });
85
+ it('should call Logger.error', async () => {
86
+ cls.getId.mockReturnValue('testErrId');
87
+ service.error({ message: `error!`, statusCode: 500 });
88
+ expect(common_1.Logger.error).toHaveBeenCalledTimes(2);
89
+ });
90
+ it('should call cls.getId()', async () => {
91
+ expect(cls.getId).toHaveBeenCalledTimes(8);
92
+ });
93
+ it('should call Logger.warn with correct message', () => {
94
+ expect(common_1.Logger.error).toHaveBeenCalledWith(`[TEST][testErrId]: [500]: error!`);
95
+ });
96
+ });
97
+ describe('.verbose', () => {
98
+ beforeEach(() => {
99
+ jest.spyOn(common_1.Logger, 'verbose');
100
+ });
101
+ it('should call Logger.verbose', async () => {
102
+ cls.getId.mockReturnValue('testVerboseId');
103
+ service.verbose('verbose');
104
+ expect(common_1.Logger.verbose).toHaveBeenCalledTimes(1);
105
+ });
106
+ it('should call cls.getId()', async () => {
107
+ expect(cls.getId).toHaveBeenCalledTimes(10);
108
+ });
109
+ it('should call Logger.verbose with correct message', () => {
110
+ expect(common_1.Logger.verbose).toHaveBeenCalledWith(`[TEST][testVerboseId]: verbose`);
111
+ });
112
+ });
113
+ describe('.fatal', () => {
114
+ beforeEach(() => {
115
+ jest.spyOn(common_1.Logger, 'fatal');
116
+ });
117
+ it('should call Logger.fatal', async () => {
118
+ cls.getId.mockReturnValue('testFatalId');
119
+ service.fatal('fatal');
120
+ expect(common_1.Logger.fatal).toHaveBeenCalledTimes(1);
121
+ });
122
+ it('should call cls.getId()', async () => {
123
+ expect(cls.getId).toHaveBeenCalledTimes(12);
124
+ });
125
+ it('should call Logger.verbose with correct message', () => {
126
+ expect(common_1.Logger.fatal).toHaveBeenCalledWith(`[TEST][testFatalId]: fatal`);
127
+ });
128
+ });
129
+ });
130
+ //# sourceMappingURL=fox-logger.service.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fox-logger.service.spec.js","sourceRoot":"","sources":["../src/fox-logger.service.spec.ts"],"names":[],"mappings":";;AAAA,2CAAwC;AACxC,6CAAsD;AACtD,2DAA6D;AAC7D,2CAAmD;AAEnD,2DAAsD;AACtD,6DAAwD;AAExD,QAAQ,CAAC,kBAAkB,EAAE,GAAG,EAAE;IAChC,IAAI,GAA8B,CAAC;IACnC,IAAI,OAAyB,CAAC;IAE9B,UAAU,CAAC,KAAK,IAAI,EAAE;QACpB,MAAM,MAAM,GAAkB,MAAM,cAAI,CAAC,mBAAmB,CAAC;YAC3D,OAAO,EAAE;gBACP,sBAAS,CAAC,OAAO,CAAC;oBAChB,MAAM,EAAE,IAAI;iBACb,CAAC;gBACF,mCAAe,CAAC,UAAU,CAAC;oBACzB,IAAI,EAAE,MAAM;iBACb,CAAC;aACH;YACD,SAAS,EAAE,CAAC,qCAAgB,EAAE,uBAAU,CAAC;SAC1C,CAAC;aACC,gBAAgB,CAAC,uBAAU,CAAC;aAC5B,QAAQ,CAAC,IAAA,6BAAQ,EAAC,uBAAU,CAAC,CAAC;aAC9B,OAAO,EAAE,CAAC;QAEb,OAAO,GAAG,MAAM,CAAC,GAAG,CA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