nestjs-fox-logger 0.0.1 → 0.0.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/README.md +8 -12
- package/dist/fox-logger.service.d.ts +3 -2
- package/dist/fox-logger.service.js +35 -37
- package/dist/fox-logger.service.js.map +1 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/fox-logger.service.ts +51 -42
- package/src/index.ts +5 -0
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
</a>
|
|
5
5
|
</div>
|
|
6
6
|
|
|
7
|
-
<h3 align="center">NestJS Logger Module with Cls</h3>
|
|
7
|
+
<h3 align="center">NestJS Logger Module with Cls suitable for Winston-Graylog transport</h3>
|
|
8
8
|
|
|
9
9
|
<div align="center">
|
|
10
10
|
<a href="https://nestjs.com" target="_blank">
|
|
@@ -12,22 +12,18 @@
|
|
|
12
12
|
</a>
|
|
13
13
|
</div>
|
|
14
14
|
|
|
15
|
-
###
|
|
16
|
-
|
|
17
|
-
Модуль логгера с поддержкой CLS
|
|
18
|
-
|
|
19
|
-
### Установка
|
|
15
|
+
### Installation
|
|
20
16
|
|
|
21
17
|
```bash
|
|
22
|
-
npm install --save nestjs-fox-logger
|
|
18
|
+
npm install --save nestjs-fox-logger nest-cls
|
|
23
19
|
```
|
|
24
20
|
|
|
25
|
-
###
|
|
21
|
+
### Usage
|
|
26
22
|
|
|
27
|
-
####
|
|
23
|
+
#### Import
|
|
28
24
|
|
|
29
25
|
```ts
|
|
30
|
-
//
|
|
26
|
+
// In your root module
|
|
31
27
|
import { ClsModule } from 'nestjs-cls';
|
|
32
28
|
|
|
33
29
|
@Module({
|
|
@@ -44,7 +40,7 @@ import { ClsModule } from 'nestjs-cls';
|
|
|
44
40
|
})
|
|
45
41
|
export class AppModule {}
|
|
46
42
|
|
|
47
|
-
|
|
43
|
+
/// ...in a feature module
|
|
48
44
|
import { FoxLoggerModule } from 'nestjs-fox-logger';
|
|
49
45
|
|
|
50
46
|
@Module({
|
|
@@ -60,7 +56,7 @@ import { FoxLoggerModule } from 'nestjs-fox-logger';
|
|
|
60
56
|
export class UsersModule {}
|
|
61
57
|
```
|
|
62
58
|
|
|
63
|
-
####
|
|
59
|
+
#### Call
|
|
64
60
|
|
|
65
61
|
```typescript
|
|
66
62
|
import { LoopService } from 'nestjs-fox-logger';
|
|
@@ -4,9 +4,10 @@ import { FoxLoggerServiceOptions } from './fox-logger.interfaces';
|
|
|
4
4
|
export declare class FoxLoggerService extends Logger {
|
|
5
5
|
readonly options: FoxLoggerServiceOptions;
|
|
6
6
|
private readonly cls?;
|
|
7
|
-
private readonly name?;
|
|
7
|
+
private readonly $name?;
|
|
8
8
|
constructor(options: FoxLoggerServiceOptions, cls?: ClsService);
|
|
9
|
-
|
|
9
|
+
static FormatObjectMessage(msg: object): string;
|
|
10
|
+
static FormatMessage(msg: unknown): string;
|
|
10
11
|
private getPrefix;
|
|
11
12
|
log(msg: any, eventId?: string): void;
|
|
12
13
|
warn(msg: any, eventId?: string): void;
|
|
@@ -11,77 +11,75 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
11
11
|
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
12
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
13
|
};
|
|
14
|
+
var FoxLoggerService_1;
|
|
14
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
16
|
exports.FoxLoggerService = void 0;
|
|
16
17
|
const common_1 = require("@nestjs/common");
|
|
17
18
|
const nestjs_cls_1 = require("nestjs-cls");
|
|
18
19
|
const fox_logger_const_1 = require("./fox-logger.const");
|
|
19
|
-
let FoxLoggerService = class FoxLoggerService extends common_1.Logger {
|
|
20
|
+
let FoxLoggerService = FoxLoggerService_1 = class FoxLoggerService extends common_1.Logger {
|
|
20
21
|
constructor(options, cls) {
|
|
21
22
|
super();
|
|
22
23
|
this.options = options;
|
|
23
24
|
this.cls = cls;
|
|
24
|
-
this
|
|
25
|
+
this.$name = options.name;
|
|
25
26
|
}
|
|
26
|
-
|
|
27
|
+
static FormatObjectMessage(msg) {
|
|
28
|
+
const prefix = [
|
|
29
|
+
'statusCode' in msg && `[${msg.statusCode}]`,
|
|
30
|
+
'status' in msg && `[${msg.status}]`,
|
|
31
|
+
'error' in msg && `[${msg.error}]`,
|
|
32
|
+
].filter(Boolean);
|
|
33
|
+
if (prefix.length > 0)
|
|
34
|
+
prefix.push(': ');
|
|
35
|
+
const message = [
|
|
36
|
+
msg['response']?.['data']?.['message'] && `: ${msg['data']['message']}`,
|
|
37
|
+
msg['data']?.['message'] && `: ${msg['data']['message']}`,
|
|
38
|
+
msg['message'] && `${msg['message']}`,
|
|
39
|
+
msg['msg'] && `${msg['msg']}`,
|
|
40
|
+
].filter(Boolean);
|
|
41
|
+
if (prefix.length + message.length > 0) {
|
|
42
|
+
return prefix.join(``) + message.join(' ');
|
|
43
|
+
}
|
|
44
|
+
return JSON.stringify(msg);
|
|
45
|
+
}
|
|
46
|
+
static FormatMessage(msg) {
|
|
27
47
|
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
48
|
case 'object':
|
|
38
|
-
|
|
39
|
-
|
|
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(' ');
|
|
49
|
+
if (Array.isArray(msg)) {
|
|
50
|
+
return msg.map(this.FormatObjectMessage).join(`\n`);
|
|
54
51
|
}
|
|
52
|
+
return this.FormatObjectMessage(msg);
|
|
55
53
|
default:
|
|
56
|
-
|
|
54
|
+
return String(msg);
|
|
57
55
|
}
|
|
58
56
|
}
|
|
59
57
|
getPrefix(eventId) {
|
|
60
|
-
return (`${this
|
|
58
|
+
return (`${this.$name ? `[${this.$name}]` : ``}` +
|
|
61
59
|
`${this.cls.getId() ? `[${this.cls.getId()}]` : ''}` +
|
|
62
60
|
`${eventId ? `[${eventId}]` : ``}`);
|
|
63
61
|
}
|
|
64
62
|
log(msg, eventId) {
|
|
65
|
-
return common_1.Logger.log(this.getPrefix(eventId)
|
|
63
|
+
return common_1.Logger.log(`${this.getPrefix(eventId)}: ${FoxLoggerService_1.FormatMessage(msg)}`);
|
|
66
64
|
}
|
|
67
65
|
warn(msg, eventId) {
|
|
68
|
-
return common_1.Logger.warn(this.getPrefix(eventId)
|
|
66
|
+
return common_1.Logger.warn(`${this.getPrefix(eventId)}: ${FoxLoggerService_1.FormatMessage(msg)}`);
|
|
69
67
|
}
|
|
70
68
|
debug(msg, eventId) {
|
|
71
|
-
return common_1.Logger.debug(this.getPrefix(eventId)
|
|
69
|
+
return common_1.Logger.debug(`${this.getPrefix(eventId)}: ${FoxLoggerService_1.FormatMessage(msg)}`);
|
|
72
70
|
}
|
|
73
71
|
error(msg, eventId) {
|
|
74
|
-
return common_1.Logger.error(this.getPrefix(eventId)
|
|
72
|
+
return common_1.Logger.error(`${this.getPrefix(eventId)}: ${FoxLoggerService_1.FormatMessage(msg)}`);
|
|
75
73
|
}
|
|
76
74
|
verbose(msg, eventId) {
|
|
77
|
-
return common_1.Logger.verbose(this.getPrefix(eventId)
|
|
75
|
+
return common_1.Logger.verbose(`${this.getPrefix(eventId)}: ${FoxLoggerService_1.FormatMessage(msg)}`);
|
|
78
76
|
}
|
|
79
77
|
fatal(msg, eventId) {
|
|
80
|
-
return common_1.Logger.fatal(this.getPrefix(eventId)
|
|
78
|
+
return common_1.Logger.fatal(`${this.getPrefix(eventId)}: ${FoxLoggerService_1.FormatMessage(msg)}`);
|
|
81
79
|
}
|
|
82
80
|
};
|
|
83
81
|
exports.FoxLoggerService = FoxLoggerService;
|
|
84
|
-
exports.FoxLoggerService = FoxLoggerService = __decorate([
|
|
82
|
+
exports.FoxLoggerService = FoxLoggerService = FoxLoggerService_1 = __decorate([
|
|
85
83
|
(0, common_1.Injectable)(),
|
|
86
84
|
__param(0, (0, common_1.Inject)(fox_logger_const_1.FOXLOGGER_SERVICE_OPTIONS)),
|
|
87
85
|
__metadata("design:paramtypes", [Object, nestjs_cls_1.ClsService])
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fox-logger.service.js","sourceRoot":"","sources":["../src/fox-logger.service.ts"],"names":[],"mappings":"
|
|
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,wBAAtB,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,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC;IAC5B,CAAC;IAMD,MAAM,CAAC,mBAAmB,CAAC,GAAW;QACpC,MAAM,MAAM,GAAG;YACb,YAAY,IAAI,GAAG,IAAI,IAAI,GAAG,CAAC,UAA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kBAAgB,CAAC,aAAa,CAAC,GAAG,CAAC,EAAE,CACrE,CAAC;IACJ,CAAC;IACM,OAAO,CAAC,GAAQ,EAAE,OAAgB;QACvC,OAAO,eAAM,CAAC,OAAO,CACnB,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,KAAK,kBAAgB,CAAC,aAAa,CAAC,GAAG,CAAC,EAAE,CACrE,CAAC;IACJ,CAAC;IACM,KAAK,CAAC,GAAQ,EAAE,OAAgB;QACrC,OAAO,eAAM,CAAC,KAAK,CACjB,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,KAAK,kBAAgB,CAAC,aAAa,CAAC,GAAG,CAAC,EAAE,CACrE,CAAC;IACJ,CAAC;CACF,CAAA;AAzFY,4CAAgB;2BAAhB,gBAAgB;IAD5B,IAAA,mBAAU,GAAE;IAKR,WAAA,IAAA,eAAM,EAAC,4CAAyB,CAAC,CAAA;6CAEX,uBAAU;GANxB,gBAAgB,CAyF5B"}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.FoxLoggerService = exports.FoxLoggerModule = void 0;
|
|
18
|
+
__exportStar(require("./fox-logger.const"), exports);
|
|
19
|
+
__exportStar(require("./fox-logger.interfaces"), exports);
|
|
20
|
+
var fox_logger_module_1 = require("./fox-logger.module");
|
|
21
|
+
Object.defineProperty(exports, "FoxLoggerModule", { enumerable: true, get: function () { return fox_logger_module_1.FoxLoggerModule; } });
|
|
22
|
+
var fox_logger_service_1 = require("./fox-logger.service");
|
|
23
|
+
Object.defineProperty(exports, "FoxLoggerService", { enumerable: true, get: function () { return fox_logger_service_1.FoxLoggerService; } });
|
|
24
|
+
__exportStar(require("nestjs-cls"), exports);
|
|
25
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,qDAAmC;AACnC,0DAAwC;AACxC,yDAAsD;AAA7C,oHAAA,eAAe,OAAA;AACxB,2DAAwD;AAA/C,sHAAA,gBAAgB,OAAA;AACzB,6CAA2B"}
|