@viplance/nestjs-logger 0.3.7 → 0.3.8
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/dist/entities/log.entity.d.ts +2 -2
- package/dist/entities/log.entity.js +3 -2
- package/dist/entities/log.entity.js.map +1 -1
- package/dist/services/log.service.js +21 -8
- package/dist/services/log.service.js.map +1 -1
- package/dist/utils/entity2table.d.ts +2 -0
- package/dist/utils/entity2table.js +35 -0
- package/dist/utils/entity2table.js.map +1 -0
- package/package.json +6 -1
- package/public/scripts/common.js +8 -1
- package/public/scripts/details-popup.js +14 -4
- package/src/entities/log.entity.ts +7 -3
- package/src/services/log.service.ts +21 -4
- package/src/utils/entity2table.ts +33 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { EntitySchema } from "typeorm";
|
|
2
|
-
export declare function createLogEntity(name: string): EntitySchema<{
|
|
1
|
+
import { DataSourceOptions, EntitySchema } from "typeorm";
|
|
2
|
+
export declare function createLogEntity(name: string, dbType: DataSourceOptions["type"] | "memory"): EntitySchema<{
|
|
3
3
|
_id: unknown;
|
|
4
4
|
type: unknown;
|
|
5
5
|
message: unknown;
|
|
@@ -2,14 +2,15 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createLogEntity = createLogEntity;
|
|
4
4
|
const typeorm_1 = require("typeorm");
|
|
5
|
-
function createLogEntity(name) {
|
|
5
|
+
function createLogEntity(name, dbType) {
|
|
6
6
|
return new typeorm_1.EntitySchema({
|
|
7
7
|
name,
|
|
8
8
|
columns: {
|
|
9
9
|
_id: {
|
|
10
|
-
type: String,
|
|
10
|
+
type: dbType === "mongodb" ? String : Number,
|
|
11
11
|
objectId: true,
|
|
12
12
|
primary: true,
|
|
13
|
+
generated: true,
|
|
13
14
|
},
|
|
14
15
|
type: { type: String },
|
|
15
16
|
message: { type: String },
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"log.entity.js","sourceRoot":"","sources":["../../src/entities/log.entity.ts"],"names":[],"mappings":";;AAEA,
|
|
1
|
+
{"version":3,"file":"log.entity.js","sourceRoot":"","sources":["../../src/entities/log.entity.ts"],"names":[],"mappings":";;AAEA,0CAuBC;AAzBD,qCAA0D;AAE1D,SAAgB,eAAe,CAC7B,IAAY,EACZ,MAA4C;IAE5C,OAAO,IAAI,sBAAY,CAAC;QACtB,IAAI;QACJ,OAAO,EAAE;YACP,GAAG,EAAE;gBACH,IAAI,EAAE,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM;gBAC5C,QAAQ,EAAE,IAAI;gBACd,OAAO,EAAE,IAAI;gBACb,SAAS,EAAE,IAAI;aAChB;YACD,IAAI,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE;YACtB,OAAO,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE;YACzB,KAAK,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,EAAE;YACnC,OAAO,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE;YACzC,KAAK,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE;YACvC,WAAW,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE;YAC7C,SAAS,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE;YACzB,SAAS,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE;SAC1B;KACF,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -18,24 +18,37 @@ const types_1 = require("../types");
|
|
|
18
18
|
const typeorm_1 = require("typeorm");
|
|
19
19
|
const log_entity_1 = require("../entities/log.entity");
|
|
20
20
|
const timers_1 = require("timers");
|
|
21
|
+
const entity2table_1 = require("../utils/entity2table");
|
|
21
22
|
let LogService = LogService_1 = class LogService {
|
|
22
23
|
constructor(memoryDbService) {
|
|
23
24
|
this.memoryDbService = memoryDbService;
|
|
24
25
|
this.breadcrumbs = [];
|
|
25
26
|
}
|
|
26
27
|
async connectDb(options) {
|
|
27
|
-
var _a, _b, _c, _d, _e, _f;
|
|
28
|
-
LogService_1.Log = (0, log_entity_1.createLogEntity)(((_a = options.database) === null || _a === void 0 ? void 0 : _a.collection) || ((_b = options.database) === null || _b === void 0 ? void 0 : _b.table) || defaults_1.defaultTable);
|
|
28
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
29
|
+
LogService_1.Log = (0, log_entity_1.createLogEntity)(((_a = options.database) === null || _a === void 0 ? void 0 : _a.collection) || ((_b = options.database) === null || _b === void 0 ? void 0 : _b.table) || defaults_1.defaultTable, ((_c = options.database) === null || _c === void 0 ? void 0 : _c.type) || "mongodb");
|
|
29
30
|
this.setOptions(options);
|
|
30
31
|
const dataSourceOptions = {
|
|
31
|
-
type: (
|
|
32
|
-
database: (
|
|
33
|
-
host: (
|
|
34
|
-
port: (
|
|
32
|
+
type: (_d = options.database) === null || _d === void 0 ? void 0 : _d.type,
|
|
33
|
+
database: (_e = options.database) === null || _e === void 0 ? void 0 : _e.database,
|
|
34
|
+
host: (_f = options.database) === null || _f === void 0 ? void 0 : _f.host,
|
|
35
|
+
port: (_g = options.database) === null || _g === void 0 ? void 0 : _g.port,
|
|
35
36
|
entities: [LogService_1.Log],
|
|
36
37
|
};
|
|
37
38
|
LogService_1.connection = new typeorm_1.DataSource(dataSourceOptions);
|
|
38
39
|
await LogService_1.connection.initialize();
|
|
40
|
+
if (dataSourceOptions.type !== "mongodb") {
|
|
41
|
+
// LogService.idName = "id";
|
|
42
|
+
const queryRunner = LogService_1.connection.createQueryRunner();
|
|
43
|
+
try {
|
|
44
|
+
await queryRunner.connect();
|
|
45
|
+
const table = (0, entity2table_1.entity2table)(LogService_1.Log);
|
|
46
|
+
await queryRunner.createTable(table, true);
|
|
47
|
+
}
|
|
48
|
+
finally {
|
|
49
|
+
await queryRunner.release();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
39
52
|
if (LogService_1.timer) {
|
|
40
53
|
clearInterval(LogService_1.timer);
|
|
41
54
|
}
|
|
@@ -118,7 +131,7 @@ let LogService = LogService_1 = class LogService {
|
|
|
118
131
|
});
|
|
119
132
|
const context = data.context ? this.parseContext(data.context) : undefined;
|
|
120
133
|
if (log) {
|
|
121
|
-
return await connection.update(LogService_1.Log, log
|
|
134
|
+
return await connection.update(LogService_1.Log, log["_id"], {
|
|
122
135
|
context,
|
|
123
136
|
trace: data.trace,
|
|
124
137
|
breadcrumbs: this.breadcrumbs,
|
|
@@ -187,7 +200,7 @@ let LogService = LogService_1 = class LogService {
|
|
|
187
200
|
}
|
|
188
201
|
};
|
|
189
202
|
exports.LogService = LogService;
|
|
190
|
-
LogService.Log = (0, log_entity_1.createLogEntity)(defaults_1.defaultTable);
|
|
203
|
+
LogService.Log = (0, log_entity_1.createLogEntity)(defaults_1.defaultTable, "memory");
|
|
191
204
|
exports.LogService = LogService = LogService_1 = __decorate([
|
|
192
205
|
(0, common_1.Injectable)({ scope: common_1.Scope.TRANSIENT }),
|
|
193
206
|
__metadata("design:paramtypes", [memory_db_service_1.MemoryDbService])
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"log.service.js","sourceRoot":"","sources":["../../src/services/log.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAAkE;AAClE,2DAAsD;AACtD,0CAA2C;AAC3C,oCAA8D;AAC9D,qCAKiB;AACjB,uDAAyD;AAEzD,mCAAqC;
|
|
1
|
+
{"version":3,"file":"log.service.js","sourceRoot":"","sources":["../../src/services/log.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAAkE;AAClE,2DAAsD;AACtD,0CAA2C;AAC3C,oCAA8D;AAC9D,qCAKiB;AACjB,uDAAyD;AAEzD,mCAAqC;AACrC,wDAAqD;AAG9C,IAAM,UAAU,kBAAhB,MAAM,UAAU;IAQrB,YAA6B,eAAgC;QAAhC,oBAAe,G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IADtB,IAAA,mBAAU,EAAC,EAAE,KAAK,EAAE,cAAK,CAAC,SAAS,EAAE,CAAC;qCASS,mCAAe;GARlD,UAAU,CAmOtB"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.entity2table = entity2table;
|
|
4
|
+
const typeorm_1 = require("typeorm");
|
|
5
|
+
const defaults_1 = require("../defaults");
|
|
6
|
+
function entity2table(entity) {
|
|
7
|
+
return new typeorm_1.Table({
|
|
8
|
+
name: entity.options.tableName || defaults_1.defaultTable,
|
|
9
|
+
columns: Object.entries(entity.options.columns).map(([name, col]) => ({
|
|
10
|
+
name,
|
|
11
|
+
type: resolveColumnType(col === null || col === void 0 ? void 0 : col.type),
|
|
12
|
+
isPrimary: !!(col === null || col === void 0 ? void 0 : col.primary),
|
|
13
|
+
isGenerated: !!(col === null || col === void 0 ? void 0 : col.generated),
|
|
14
|
+
generationStrategy: (col === null || col === void 0 ? void 0 : col.generated) ? "increment" : undefined,
|
|
15
|
+
isUnique: !!(col === null || col === void 0 ? void 0 : col.unique),
|
|
16
|
+
isNullable: !!(col === null || col === void 0 ? void 0 : col.nullable),
|
|
17
|
+
default: col === null || col === void 0 ? void 0 : col.default,
|
|
18
|
+
})),
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
function resolveColumnType(type) {
|
|
22
|
+
switch (type) {
|
|
23
|
+
case String:
|
|
24
|
+
return "text";
|
|
25
|
+
case Number:
|
|
26
|
+
return "int";
|
|
27
|
+
case Date:
|
|
28
|
+
return "timestamp";
|
|
29
|
+
case Boolean:
|
|
30
|
+
return "boolean";
|
|
31
|
+
default:
|
|
32
|
+
return "text";
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=entity2table.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entity2table.js","sourceRoot":"","sources":["../../src/utils/entity2table.ts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AC;QACnB;YACE,OAAO,MAAM,CAAC;IAClB,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@viplance/nestjs-logger",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.8",
|
|
4
4
|
"description": "NestJS internal logging system",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -13,8 +13,13 @@
|
|
|
13
13
|
"nest",
|
|
14
14
|
"logger",
|
|
15
15
|
"logs",
|
|
16
|
+
"internal",
|
|
16
17
|
"typeorm",
|
|
17
18
|
"mongodb",
|
|
19
|
+
"postgresql",
|
|
20
|
+
"mysql",
|
|
21
|
+
"mariadb",
|
|
22
|
+
"sqlite",
|
|
18
23
|
"memory",
|
|
19
24
|
"free"
|
|
20
25
|
],
|
package/public/scripts/common.js
CHANGED
|
@@ -69,7 +69,14 @@ document.addEventListener(`click`, (e) => {
|
|
|
69
69
|
(target.classList?.contains(`row`) && target.id);
|
|
70
70
|
|
|
71
71
|
if (logId) {
|
|
72
|
-
|
|
72
|
+
let id = logId;
|
|
73
|
+
|
|
74
|
+
try {
|
|
75
|
+
if (Number(id) > 0) id = Number(id); // SQL DB numeric index
|
|
76
|
+
} catch (e) {}
|
|
77
|
+
|
|
78
|
+
const log = logs.find((log) => log._id === id);
|
|
79
|
+
|
|
73
80
|
showLogDetails(log);
|
|
74
81
|
}
|
|
75
82
|
});
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
function showLogDetails(log) {
|
|
2
2
|
const popup = document.getElementById(`popup`);
|
|
3
|
+
const context = getObject(log.context);
|
|
4
|
+
const breadcrumbs = getObject(log.breadcrumbs);
|
|
3
5
|
|
|
4
6
|
popup.innerHTML = `
|
|
5
7
|
<div class="content center">
|
|
@@ -15,18 +17,18 @@ function showLogDetails(log) {
|
|
|
15
17
|
: ""
|
|
16
18
|
}
|
|
17
19
|
${
|
|
18
|
-
|
|
20
|
+
context
|
|
19
21
|
? `
|
|
20
22
|
<h3 class="mt-15">Context</h3>
|
|
21
|
-
<p>${jsonViewer(
|
|
23
|
+
<p>${jsonViewer(context)}</p>
|
|
22
24
|
`
|
|
23
25
|
: ""
|
|
24
26
|
}
|
|
25
27
|
${
|
|
26
|
-
|
|
28
|
+
breadcrumbs && breadcrumbs.length > 0
|
|
27
29
|
? `
|
|
28
30
|
<h3 class="mt-15">Breadcrumbs</h3>
|
|
29
|
-
<p>${jsonViewer(
|
|
31
|
+
<p>${jsonViewer(breadcrumbs)}</p>
|
|
30
32
|
`
|
|
31
33
|
: ""
|
|
32
34
|
}
|
|
@@ -42,6 +44,14 @@ function showLogDetails(log) {
|
|
|
42
44
|
popup.style.display = "block";
|
|
43
45
|
}
|
|
44
46
|
|
|
47
|
+
function getObject(context) {
|
|
48
|
+
if (typeof context === "string") {
|
|
49
|
+
return JSON.parse(context);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return context;
|
|
53
|
+
}
|
|
54
|
+
|
|
45
55
|
function getTrace(trace) {
|
|
46
56
|
return trace.replace(new RegExp(String.fromCharCode(10), "g"), "<br />");
|
|
47
57
|
}
|
|
@@ -1,13 +1,17 @@
|
|
|
1
|
-
import { EntitySchema } from "typeorm";
|
|
1
|
+
import { DataSourceOptions, EntitySchema } from "typeorm";
|
|
2
2
|
|
|
3
|
-
export function createLogEntity(
|
|
3
|
+
export function createLogEntity(
|
|
4
|
+
name: string,
|
|
5
|
+
dbType: DataSourceOptions["type"] | "memory"
|
|
6
|
+
) {
|
|
4
7
|
return new EntitySchema({
|
|
5
8
|
name,
|
|
6
9
|
columns: {
|
|
7
10
|
_id: {
|
|
8
|
-
type: String,
|
|
11
|
+
type: dbType === "mongodb" ? String : Number,
|
|
9
12
|
objectId: true,
|
|
10
13
|
primary: true,
|
|
14
|
+
generated: true,
|
|
11
15
|
},
|
|
12
16
|
type: { type: String },
|
|
13
17
|
message: { type: String },
|
|
@@ -11,12 +11,13 @@ import {
|
|
|
11
11
|
import { createLogEntity } from "../entities/log.entity";
|
|
12
12
|
import { ExecutionContextHost } from "@nestjs/core/helpers/execution-context-host";
|
|
13
13
|
import { setInterval } from "timers";
|
|
14
|
+
import { entity2table } from "../utils/entity2table";
|
|
14
15
|
|
|
15
16
|
@Injectable({ scope: Scope.TRANSIENT })
|
|
16
17
|
export class LogService implements LoggerService {
|
|
17
18
|
static connection: DataSource;
|
|
18
19
|
static options: LogModuleOptions;
|
|
19
|
-
static Log: EntitySchema = createLogEntity(defaultTable);
|
|
20
|
+
static Log: EntitySchema = createLogEntity(defaultTable, "memory");
|
|
20
21
|
static timer: ReturnType<typeof setInterval>;
|
|
21
22
|
|
|
22
23
|
breadcrumbs: any[] = [];
|
|
@@ -25,7 +26,8 @@ export class LogService implements LoggerService {
|
|
|
25
26
|
|
|
26
27
|
async connectDb(options: LogModuleOptions): Promise<DataSource> {
|
|
27
28
|
LogService.Log = createLogEntity(
|
|
28
|
-
options.database?.collection || options.database?.table || defaultTable
|
|
29
|
+
options.database?.collection || options.database?.table || defaultTable,
|
|
30
|
+
options.database?.type || "mongodb"
|
|
29
31
|
);
|
|
30
32
|
|
|
31
33
|
this.setOptions(options);
|
|
@@ -39,9 +41,24 @@ export class LogService implements LoggerService {
|
|
|
39
41
|
} as DataSourceOptions;
|
|
40
42
|
|
|
41
43
|
LogService.connection = new DataSource(dataSourceOptions);
|
|
42
|
-
|
|
43
44
|
await LogService.connection.initialize();
|
|
44
45
|
|
|
46
|
+
if (dataSourceOptions.type !== "mongodb") {
|
|
47
|
+
// LogService.idName = "id";
|
|
48
|
+
|
|
49
|
+
const queryRunner = LogService.connection.createQueryRunner();
|
|
50
|
+
|
|
51
|
+
try {
|
|
52
|
+
await queryRunner.connect();
|
|
53
|
+
|
|
54
|
+
const table = entity2table(LogService.Log);
|
|
55
|
+
|
|
56
|
+
await queryRunner.createTable(table, true);
|
|
57
|
+
} finally {
|
|
58
|
+
await queryRunner.release();
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
45
62
|
if (LogService.timer) {
|
|
46
63
|
clearInterval(LogService.timer);
|
|
47
64
|
}
|
|
@@ -146,7 +163,7 @@ export class LogService implements LoggerService {
|
|
|
146
163
|
const context = data.context ? this.parseContext(data.context) : undefined;
|
|
147
164
|
|
|
148
165
|
if (log) {
|
|
149
|
-
return await connection.update(LogService.Log, log
|
|
166
|
+
return await connection.update(LogService.Log, log["_id"], {
|
|
150
167
|
context,
|
|
151
168
|
trace: data.trace,
|
|
152
169
|
breadcrumbs: this.breadcrumbs,
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { EntitySchema, Table } from "typeorm";
|
|
2
|
+
import { defaultTable } from "../defaults";
|
|
3
|
+
|
|
4
|
+
export function entity2table(entity: EntitySchema): Table {
|
|
5
|
+
return new Table({
|
|
6
|
+
name: entity.options.tableName || defaultTable,
|
|
7
|
+
columns: Object.entries(entity.options.columns).map(([name, col]) => ({
|
|
8
|
+
name,
|
|
9
|
+
type: resolveColumnType(col?.type),
|
|
10
|
+
isPrimary: !!col?.primary,
|
|
11
|
+
isGenerated: !!col?.generated,
|
|
12
|
+
generationStrategy: col?.generated ? "increment" : undefined,
|
|
13
|
+
isUnique: !!col?.unique,
|
|
14
|
+
isNullable: !!col?.nullable,
|
|
15
|
+
default: col?.default,
|
|
16
|
+
})),
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function resolveColumnType(type: any): string {
|
|
21
|
+
switch (type) {
|
|
22
|
+
case String:
|
|
23
|
+
return "text";
|
|
24
|
+
case Number:
|
|
25
|
+
return "int";
|
|
26
|
+
case Date:
|
|
27
|
+
return "timestamp";
|
|
28
|
+
case Boolean:
|
|
29
|
+
return "boolean";
|
|
30
|
+
default:
|
|
31
|
+
return "text";
|
|
32
|
+
}
|
|
33
|
+
}
|