@viplance/nestjs-logger 0.3.7 → 0.4.0
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 +14 -1
- 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/log.module.js +28 -2
- package/dist/log.module.js.map +1 -1
- package/dist/services/log.service.d.ts +10 -4
- package/dist/services/log.service.js +81 -14
- package/dist/services/log.service.js.map +1 -1
- package/dist/services/ws.service.d.ts +18 -0
- package/dist/services/ws.service.js +106 -0
- package/dist/services/ws.service.js.map +1 -0
- package/dist/types/options.type.d.ts +6 -0
- 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 +11 -4
- package/public/index.html +7 -2
- package/public/scripts/common.js +70 -32
- package/public/scripts/details-popup.js +25 -6
- package/public/scripts/ws.js +83 -0
- package/public/styles/index.css +5 -0
- package/src/entities/log.entity.ts +7 -3
- package/src/log.module.ts +35 -2
- package/src/services/log.service.ts +102 -11
- package/src/services/ws.d.ts +1 -0
- package/src/services/ws.service.ts +110 -0
- package/src/types/options.type.ts +6 -0
- package/src/utils/entity2table.ts +33 -0
package/README.md
CHANGED
|
@@ -24,12 +24,13 @@
|
|
|
24
24
|
import { LogModule } from '@viplance/nestjs-logger';
|
|
25
25
|
|
|
26
26
|
await LogModule.init(app, {
|
|
27
|
+
..., // some other properties
|
|
27
28
|
path: '/logs', // define the public URL for the log list
|
|
28
29
|
key: 'kjhjmi321lqq7a', // use the key to protect data from unauthorized access
|
|
29
30
|
});
|
|
30
31
|
```
|
|
31
32
|
|
|
32
|
-
Connect
|
|
33
|
+
Connect a SQL or NoSQL database to store logs.<br />
|
|
33
34
|
```typescript
|
|
34
35
|
await LogModule.init(app, {
|
|
35
36
|
...,
|
|
@@ -42,6 +43,18 @@ Connect the database to store logs.<br />
|
|
|
42
43
|
});
|
|
43
44
|
```
|
|
44
45
|
|
|
46
|
+
Enable a WebSocket connection to receive the logs in real time.<br />
|
|
47
|
+
```typescript
|
|
48
|
+
await LogModule.init(app, {
|
|
49
|
+
...,
|
|
50
|
+
websocket: {
|
|
51
|
+
secure: true, // enable WSS
|
|
52
|
+
port: 81,
|
|
53
|
+
host: 'your-domain.name',
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
```
|
|
57
|
+
|
|
45
58
|
4. Use the `LogService` in case of custom logs to debug the application.<br />
|
|
46
59
|
```typescript
|
|
47
60
|
import { LogService } from '@viplance/nestjs-logger';
|
|
@@ -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"}
|
package/dist/log.module.js
CHANGED
|
@@ -19,10 +19,12 @@ const node_querystring_1 = __importDefault(require("node:querystring"));
|
|
|
19
19
|
const core_1 = require("@nestjs/core");
|
|
20
20
|
const node_path_1 = require("node:path");
|
|
21
21
|
const access_guard_1 = require("./guards/access.guard");
|
|
22
|
+
const ws_service_1 = require("./services/ws.service");
|
|
22
23
|
let LogModule = class LogModule {
|
|
23
24
|
static async init(app, options) {
|
|
24
25
|
app.resolve(log_service_1.LogService);
|
|
25
26
|
const logService = await app.resolve(log_service_1.LogService);
|
|
27
|
+
const wsService = await app.resolve(ws_service_1.WsService);
|
|
26
28
|
const logAccessGuard = await app.get(access_guard_1.LogAccessGuard);
|
|
27
29
|
if (options) {
|
|
28
30
|
logService.setOptions(options);
|
|
@@ -33,6 +35,20 @@ let LogModule = class LogModule {
|
|
|
33
35
|
prefix: options.path,
|
|
34
36
|
});
|
|
35
37
|
const httpAdapter = app.getHttpAdapter();
|
|
38
|
+
// frontend settings endpoint
|
|
39
|
+
httpAdapter.get((0, node_path_1.join)(options.path, "settings"), async (req, res) => {
|
|
40
|
+
var _a, _b, _c, _d;
|
|
41
|
+
logAccessGuard.canActivate(req);
|
|
42
|
+
const result = {};
|
|
43
|
+
if (options === null || options === void 0 ? void 0 : options.websocket) {
|
|
44
|
+
result.websocket = {
|
|
45
|
+
namespace: (_a = options.websocket) === null || _a === void 0 ? void 0 : _a.namespace,
|
|
46
|
+
port: (_b = options.websocket) === null || _b === void 0 ? void 0 : _b.port,
|
|
47
|
+
host: ((_c = options.websocket) === null || _c === void 0 ? void 0 : _c.host) || ((_d = req.headers) === null || _d === void 0 ? void 0 : _d.host.split(":")[0]),
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
res.json(result);
|
|
51
|
+
});
|
|
36
52
|
// get all logs endpoint
|
|
37
53
|
httpAdapter.get((0, node_path_1.join)(options.path, "api"), async (req, res) => {
|
|
38
54
|
logAccessGuard.canActivate(req);
|
|
@@ -47,6 +63,10 @@ let LogModule = class LogModule {
|
|
|
47
63
|
}
|
|
48
64
|
res.json(await logService.delete(params.id.toString()));
|
|
49
65
|
});
|
|
66
|
+
// set up WebSocket connection
|
|
67
|
+
if (options === null || options === void 0 ? void 0 : options.websocket) {
|
|
68
|
+
wsService.setupConnection(options.websocket, options.key);
|
|
69
|
+
}
|
|
50
70
|
}
|
|
51
71
|
if (options === null || options === void 0 ? void 0 : options.database) {
|
|
52
72
|
await logService.connectDb(options);
|
|
@@ -58,8 +78,14 @@ exports.LogModule = LogModule = __decorate([
|
|
|
58
78
|
(0, common_1.Global)(),
|
|
59
79
|
(0, common_1.Module)({
|
|
60
80
|
imports: [typeorm_1.TypeOrmModule],
|
|
61
|
-
providers: [
|
|
62
|
-
|
|
81
|
+
providers: [
|
|
82
|
+
core_1.ApplicationConfig,
|
|
83
|
+
access_guard_1.LogAccessGuard,
|
|
84
|
+
log_service_1.LogService,
|
|
85
|
+
memory_db_service_1.MemoryDbService,
|
|
86
|
+
ws_service_1.WsService,
|
|
87
|
+
],
|
|
88
|
+
exports: [typeorm_1.TypeOrmModule, log_service_1.LogService, memory_db_service_1.MemoryDbService, ws_service_1.WsService],
|
|
63
89
|
})
|
|
64
90
|
], LogModule);
|
|
65
91
|
//# sourceMappingURL=log.module.js.map
|
package/dist/log.module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"log.module.js","sourceRoot":"","sources":["../src/log.module.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA+D;AAC/D,wDAAoD;AACpD,oEAA+D;AAC/D,oEAAgE;AAEhE,6CAAgD;AAChD,wEAA2C;AAC3C,uCAAiD;AACjD,yCAAiC;AACjC,wDAAuD;
|
|
1
|
+
{"version":3,"file":"log.module.js","sourceRoot":"","sources":["../src/log.module.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA+D;AAC/D,wDAAoD;AACpD,oEAA+D;AAC/D,oEAAgE;AAEhE,6CAAgD;AAChD,wEAA2C;AAC3C,uCAAiD;AACjD,yCAAiC;AACjC,wDAAuD;AACvD,sDAAkD;AAc3C,IAAM,SAAS,GAAf,MAAM,SAAS;IACb,MAAM,CAAC,KAAK,CAAC,IAAI,CACtB,GAAQ,EACR,OAA0B;QAE1B,GAAG,CAAC,OAAO,CAAC,wBAAU,CAAC,CAAC;QAExB,MAAM,UAAU,GAAe,MAAM,GAAG,CAAC,OAAO,CAAC,wBAAU,CAAC,CAAC;QAC7D,MAAM,SAAS,GAAc,MAAM,GAAG,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OAAO,CAAC,CAAC;QACtC,CAAC;IACH,CAAC;CACF,CAAA;AA7EY,8BAAS;oBAAT,SAAS;IAZrB,IAAA,eAAM,GAAE;IACR,IAAA,eAAM,EAAC;QACN,OAAO,EAAE,CAAC,uBAAa,CAAC;QACxB,SAAS,EAAE;YACT,wBAAiB;YACjB,6BAAc;YACd,wBAAU;YACV,mCAAe;YACf,sBAAS;SACV;QACD,OAAO,EAAE,CAAC,uBAAa,EAAE,wBAAU,EAAE,mCAAe,EAAE,sBAAS,CAAC;KACjE,CAAC;GACW,SAAS,CA6ErB"}
|
|
@@ -1,17 +1,22 @@
|
|
|
1
|
-
import { LoggerService } from "@nestjs/common";
|
|
1
|
+
import { LoggerService, OnApplicationShutdown } from "@nestjs/common";
|
|
2
2
|
import { MemoryDbService } from "./memory-db.service";
|
|
3
3
|
import { LogModuleOptions } from "../types";
|
|
4
4
|
import { DataSource, EntitySchema } from "typeorm";
|
|
5
5
|
import { ExecutionContextHost } from "@nestjs/core/helpers/execution-context-host";
|
|
6
6
|
import { setInterval } from "timers";
|
|
7
|
-
|
|
7
|
+
import { WsService } from "./ws.service";
|
|
8
|
+
import { Subscription } from "rxjs";
|
|
9
|
+
export declare class LogService implements LoggerService, OnApplicationShutdown {
|
|
8
10
|
private readonly memoryDbService;
|
|
11
|
+
private readonly wsService;
|
|
9
12
|
static connection: DataSource;
|
|
10
13
|
static options: LogModuleOptions;
|
|
11
14
|
static Log: EntitySchema;
|
|
12
15
|
static timer: ReturnType<typeof setInterval>;
|
|
16
|
+
static subscription: Subscription;
|
|
13
17
|
breadcrumbs: any[];
|
|
14
|
-
constructor(memoryDbService: MemoryDbService);
|
|
18
|
+
constructor(memoryDbService: MemoryDbService, wsService: WsService);
|
|
19
|
+
onApplicationShutdown(): void;
|
|
15
20
|
connectDb(options: LogModuleOptions): Promise<DataSource>;
|
|
16
21
|
setOptions(options: LogModuleOptions): void;
|
|
17
22
|
addBreadcrumb(breadcrumb: any): void;
|
|
@@ -22,8 +27,9 @@ export declare class LogService implements LoggerService {
|
|
|
22
27
|
debug(message: string, context?: ExecutionContextHost): void;
|
|
23
28
|
verbose(message: string, context?: ExecutionContextHost): void;
|
|
24
29
|
getAll(): Promise<any[]>;
|
|
25
|
-
delete(
|
|
30
|
+
delete(_id: string): Promise<import("typeorm").DeleteResult>;
|
|
26
31
|
private smartInsert;
|
|
32
|
+
private getNewObjectId;
|
|
27
33
|
private getConnection;
|
|
28
34
|
private parseContext;
|
|
29
35
|
private checkRecords;
|
|
@@ -18,24 +18,45 @@ 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");
|
|
22
|
+
const ws_service_1 = require("./ws.service");
|
|
21
23
|
let LogService = LogService_1 = class LogService {
|
|
22
|
-
constructor(memoryDbService) {
|
|
24
|
+
constructor(memoryDbService, wsService) {
|
|
23
25
|
this.memoryDbService = memoryDbService;
|
|
26
|
+
this.wsService = wsService;
|
|
24
27
|
this.breadcrumbs = [];
|
|
25
28
|
}
|
|
29
|
+
onApplicationShutdown() {
|
|
30
|
+
if (LogService_1.timer) {
|
|
31
|
+
clearInterval(LogService_1.timer);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
26
34
|
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);
|
|
29
|
-
|
|
35
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
36
|
+
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");
|
|
37
|
+
if (!LogService_1.options) {
|
|
38
|
+
this.setOptions(options);
|
|
39
|
+
}
|
|
30
40
|
const dataSourceOptions = {
|
|
31
|
-
type: (
|
|
32
|
-
database: (
|
|
33
|
-
host: (
|
|
34
|
-
port: (
|
|
41
|
+
type: (_d = options.database) === null || _d === void 0 ? void 0 : _d.type,
|
|
42
|
+
database: (_e = options.database) === null || _e === void 0 ? void 0 : _e.database,
|
|
43
|
+
host: (_f = options.database) === null || _f === void 0 ? void 0 : _f.host,
|
|
44
|
+
port: (_g = options.database) === null || _g === void 0 ? void 0 : _g.port,
|
|
35
45
|
entities: [LogService_1.Log],
|
|
36
46
|
};
|
|
37
47
|
LogService_1.connection = new typeorm_1.DataSource(dataSourceOptions);
|
|
38
48
|
await LogService_1.connection.initialize();
|
|
49
|
+
if (dataSourceOptions.type !== "mongodb") {
|
|
50
|
+
const queryRunner = LogService_1.connection.createQueryRunner();
|
|
51
|
+
try {
|
|
52
|
+
await queryRunner.connect();
|
|
53
|
+
const table = (0, entity2table_1.entity2table)(LogService_1.Log);
|
|
54
|
+
await queryRunner.createTable(table, true);
|
|
55
|
+
}
|
|
56
|
+
finally {
|
|
57
|
+
await queryRunner.release();
|
|
58
|
+
}
|
|
59
|
+
}
|
|
39
60
|
if (LogService_1.timer) {
|
|
40
61
|
clearInterval(LogService_1.timer);
|
|
41
62
|
}
|
|
@@ -44,6 +65,21 @@ let LogService = LogService_1 = class LogService {
|
|
|
44
65
|
}
|
|
45
66
|
setOptions(options) {
|
|
46
67
|
LogService_1.options = options;
|
|
68
|
+
if (options.websocket && !LogService_1.subscription) {
|
|
69
|
+
LogService_1.subscription = this.wsService.onMessage.subscribe(async (message) => {
|
|
70
|
+
switch (message.action) {
|
|
71
|
+
case "getLogs":
|
|
72
|
+
this.wsService.sendMessage({
|
|
73
|
+
action: "list",
|
|
74
|
+
data: await this.getAll(),
|
|
75
|
+
});
|
|
76
|
+
break;
|
|
77
|
+
case "delete":
|
|
78
|
+
this.delete(message.data._id);
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
}
|
|
47
83
|
}
|
|
48
84
|
addBreadcrumb(breadcrumb) {
|
|
49
85
|
this.breadcrumbs.push(breadcrumb);
|
|
@@ -103,8 +139,12 @@ let LogService = LogService_1 = class LogService {
|
|
|
103
139
|
order: { updatedAt: "DESC" },
|
|
104
140
|
});
|
|
105
141
|
}
|
|
106
|
-
async delete(
|
|
107
|
-
|
|
142
|
+
async delete(_id) {
|
|
143
|
+
this.wsService.sendMessage({
|
|
144
|
+
action: "delete",
|
|
145
|
+
data: { _id },
|
|
146
|
+
});
|
|
147
|
+
return this.getConnection().delete(LogService_1.Log, _id);
|
|
108
148
|
}
|
|
109
149
|
async smartInsert(data) {
|
|
110
150
|
const currentDate = new Date();
|
|
@@ -118,15 +158,27 @@ let LogService = LogService_1 = class LogService {
|
|
|
118
158
|
});
|
|
119
159
|
const context = data.context ? this.parseContext(data.context) : undefined;
|
|
120
160
|
if (log) {
|
|
121
|
-
|
|
161
|
+
const updatedLog = {
|
|
162
|
+
context,
|
|
163
|
+
trace: data.trace,
|
|
164
|
+
breadcrumbs: this.breadcrumbs,
|
|
165
|
+
count: log.count + 1,
|
|
166
|
+
updatedAt: currentDate,
|
|
167
|
+
};
|
|
168
|
+
this.wsService.sendMessage({
|
|
169
|
+
action: "update",
|
|
170
|
+
data: { ...log, ...updatedLog },
|
|
171
|
+
});
|
|
172
|
+
await connection.update(LogService_1.Log, log["_id"], {
|
|
122
173
|
context,
|
|
123
174
|
trace: data.trace,
|
|
124
175
|
breadcrumbs: this.breadcrumbs,
|
|
125
176
|
count: log.count + 1,
|
|
126
177
|
updatedAt: currentDate,
|
|
127
178
|
});
|
|
179
|
+
return { ...log, ...updatedLog };
|
|
128
180
|
}
|
|
129
|
-
|
|
181
|
+
const insertedLog = {
|
|
130
182
|
type: data.type,
|
|
131
183
|
message: data.message,
|
|
132
184
|
context,
|
|
@@ -135,7 +187,21 @@ let LogService = LogService_1 = class LogService {
|
|
|
135
187
|
count: 1,
|
|
136
188
|
createdAt: currentDate,
|
|
137
189
|
updatedAt: currentDate,
|
|
190
|
+
};
|
|
191
|
+
const res = await connection.insert(LogService_1.Log, insertedLog);
|
|
192
|
+
const _id = this.getNewObjectId(res);
|
|
193
|
+
this.wsService.sendMessage({
|
|
194
|
+
action: "insert",
|
|
195
|
+
data: { _id, ...insertedLog },
|
|
138
196
|
});
|
|
197
|
+
return { _id, ...insertedLog };
|
|
198
|
+
}
|
|
199
|
+
getNewObjectId(result) {
|
|
200
|
+
if (result.identifiers) {
|
|
201
|
+
return result.identifiers[0]._id;
|
|
202
|
+
}
|
|
203
|
+
console.log(result);
|
|
204
|
+
return result._id;
|
|
139
205
|
}
|
|
140
206
|
getConnection() {
|
|
141
207
|
var _a;
|
|
@@ -187,9 +253,10 @@ let LogService = LogService_1 = class LogService {
|
|
|
187
253
|
}
|
|
188
254
|
};
|
|
189
255
|
exports.LogService = LogService;
|
|
190
|
-
LogService.Log = (0, log_entity_1.createLogEntity)(defaults_1.defaultTable);
|
|
256
|
+
LogService.Log = (0, log_entity_1.createLogEntity)(defaults_1.defaultTable, "memory");
|
|
191
257
|
exports.LogService = LogService = LogService_1 = __decorate([
|
|
192
258
|
(0, common_1.Injectable)({ scope: common_1.Scope.TRANSIENT }),
|
|
193
|
-
__metadata("design:paramtypes", [memory_db_service_1.MemoryDbService
|
|
259
|
+
__metadata("design:paramtypes", [memory_db_service_1.MemoryDbService,
|
|
260
|
+
ws_service_1.WsService])
|
|
194
261
|
], LogService);
|
|
195
262
|
//# sourceMappingURL=log.service.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"log.service.js","sourceRoot":"","sources":["../../src/services/log.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"log.service.js","sourceRoot":"","sources":["../../src/services/log.service.ts"],"names":[],"mappings":";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AY;;QACxB,IAAI,MAAA,YAAU,CAAC,OAAO,0CAAE,OAAO,EAAE,CAAC;YAChC,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,aAAa,EAAE,CAAC,IAAI,CAAC,YAAU,CAAC,GAAG,EAAE;gBAC7D,KAAK,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE;gBAC5B,IAAI,EAAE,MAAA,YAAU,CAAC,OAAO,0CAAE,OAAO;gBACjC,MAAM,EAAE,CAAC,KAAK,CAAC;aAChB,CAAC,CAAC;YAEH,MAAM,SAAS,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YAEhD,MAAM,YAAU,CAAC,UAAU;iBACxB,aAAa,CAAC,YAAU,CAAC,GAAG,CAAC;iBAC7B,kBAAkB,EAAE;iBACpB,MAAM,EAAE;iBACR,IAAI,CAAC,YAAU,CAAC,GAAG,CAAC;iBACpB,KAAK,CAAC,sBAAsB,EAAE,EAAE,GAAG,EAAE,SAAS,EAAE,CAAC;iBACjD,OAAO,EAAE,CAAC;QACf,CAAC;IACH,CAAC;;AArSU,gCAAU;AAGd,cAAG,GAAiB,IAAA,4BAAe,EAAC,uBAAY,EAAE,QAAQ,CAAC,AAAxD,CAAyD;qBAHxD,UAAU;IADtB,IAAA,mBAAU,EAAC,EAAE,KAAK,EAAE,cAAK,CAAC,SAAS,EAAE,CAAC;qCAWD,mCAAe;QACrB,sBAAS;GAX5B,UAAU,CAsStB"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { LogModuleOptions } from "../types";
|
|
2
|
+
import { Subject } from "rxjs";
|
|
3
|
+
export declare class WsService {
|
|
4
|
+
onMessage: Subject<any>;
|
|
5
|
+
private ws;
|
|
6
|
+
private connected;
|
|
7
|
+
private connectionTimeout;
|
|
8
|
+
private options;
|
|
9
|
+
private key;
|
|
10
|
+
setupConnection(options: LogModuleOptions["websocket"], key?: string): void;
|
|
11
|
+
sendMessage(message: any): void;
|
|
12
|
+
private handleError;
|
|
13
|
+
private closeConnection;
|
|
14
|
+
private ping;
|
|
15
|
+
private handleMessage;
|
|
16
|
+
private getServerUrl;
|
|
17
|
+
private handleOpenConnection;
|
|
18
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.WsService = void 0;
|
|
10
|
+
const common_1 = require("@nestjs/common");
|
|
11
|
+
const ws_1 = require("ws");
|
|
12
|
+
const rxjs_1 = require("rxjs");
|
|
13
|
+
let WsService = class WsService {
|
|
14
|
+
constructor() {
|
|
15
|
+
this.onMessage = new rxjs_1.Subject();
|
|
16
|
+
this.ws = null;
|
|
17
|
+
this.connected = false;
|
|
18
|
+
this.connectionTimeout = 500;
|
|
19
|
+
this.options = {
|
|
20
|
+
port: 8080,
|
|
21
|
+
host: "localhost",
|
|
22
|
+
};
|
|
23
|
+
this.key = "";
|
|
24
|
+
this.handleError = () => {
|
|
25
|
+
const serverUrl = this.getServerUrl();
|
|
26
|
+
console.error(`Server ${serverUrl} is not available.`);
|
|
27
|
+
setTimeout(this.setupConnection, this.connectionTimeout);
|
|
28
|
+
};
|
|
29
|
+
this.closeConnection = (connection) => {
|
|
30
|
+
clearTimeout(connection.pingTimeout);
|
|
31
|
+
if (this.connected) {
|
|
32
|
+
console.log("Connection has been closed by server.");
|
|
33
|
+
this.connected = false;
|
|
34
|
+
this.handleError();
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
this.ping = (connection) => {
|
|
38
|
+
console.log("Ping remote server.");
|
|
39
|
+
clearTimeout(connection.pingTimeout);
|
|
40
|
+
connection.pingTimeout = setTimeout(() => {
|
|
41
|
+
connection.terminate();
|
|
42
|
+
}, 30000 + this.connectionTimeout);
|
|
43
|
+
};
|
|
44
|
+
this.handleMessage = (message) => {
|
|
45
|
+
try {
|
|
46
|
+
const data = JSON.parse((message.data || message).toString());
|
|
47
|
+
if (this.key !== "" && data.key !== this.key) {
|
|
48
|
+
throw new Error("WebSocket unauthorized");
|
|
49
|
+
}
|
|
50
|
+
if (this.options)
|
|
51
|
+
if (data.action) {
|
|
52
|
+
this.onMessage.next(data);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
catch (err) {
|
|
56
|
+
console.error(err);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
this.getServerUrl = () => {
|
|
60
|
+
var _a, _b, _c;
|
|
61
|
+
return `${((_a = this.options) === null || _a === void 0 ? void 0 : _a.secure) ? "wss" : "ws"}://${(_b = this.options) === null || _b === void 0 ? void 0 : _b.host}:${(_c = this.options) === null || _c === void 0 ? void 0 : _c.port}`;
|
|
62
|
+
};
|
|
63
|
+
this.handleOpenConnection = async () => {
|
|
64
|
+
this.connected = true;
|
|
65
|
+
const serverUrl = this.getServerUrl();
|
|
66
|
+
console.log(`${serverUrl} has been connected.`);
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
setupConnection(options, key = "") {
|
|
70
|
+
var _a;
|
|
71
|
+
this.options = {
|
|
72
|
+
...this.options,
|
|
73
|
+
...options,
|
|
74
|
+
};
|
|
75
|
+
this.key = key;
|
|
76
|
+
// Set up Web Socket server
|
|
77
|
+
if (this.ws) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
const wsServer = new ws_1.WebSocketServer({
|
|
81
|
+
retryCount: 1,
|
|
82
|
+
reconnectInterval: 1,
|
|
83
|
+
handshakeTimeout: this.connectionTimeout,
|
|
84
|
+
port: (_a = this.options) === null || _a === void 0 ? void 0 : _a.port,
|
|
85
|
+
});
|
|
86
|
+
console.log(`Logs WebSocket server is listening on port ${this.options.port}`);
|
|
87
|
+
wsServer.on("error", this.handleError);
|
|
88
|
+
wsServer.on("open", () => this.handleOpenConnection());
|
|
89
|
+
wsServer.on("ping", () => this.ping(this.ws));
|
|
90
|
+
wsServer.on("close", () => this.closeConnection(this.ws));
|
|
91
|
+
wsServer.on("message", this.handleMessage);
|
|
92
|
+
wsServer.on("connection", (connection) => {
|
|
93
|
+
this.ws = connection;
|
|
94
|
+
connection.onmessage = this.handleMessage;
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
sendMessage(message) {
|
|
98
|
+
var _a;
|
|
99
|
+
(_a = this.ws) === null || _a === void 0 ? void 0 : _a.send(JSON.stringify(message));
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
exports.WsService = WsService;
|
|
103
|
+
exports.WsService = WsService = __decorate([
|
|
104
|
+
(0, common_1.Injectable)()
|
|
105
|
+
], WsService);
|
|
106
|
+
//# sourceMappingURL=ws.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ws.service.js","sourceRoot":"","sources":["../../src/services/ws.service.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAA4C;AAC5C,2BAAgD;AAEhD,+BAA+B;AAGxB,IAAM,SAAS,GAAf,MAAM,SAAS;IAAf;QACE,cAAS,GAAiB,IAAI,cAAO,EAAE,CAAC;QACvC,OAAE,GAAqB,IAAI,CAAC;QAC5B,cAAS,GAAY,KAAK,CAAC;QAC3B,sBAAiB,GAAW,GAAG,CAAC;QAChC,YAAO,GAAkC;YAC/C,IAAI,EAAE,IAAI;YACV,IAAI,EAAE,WAAW;SAClB,CAAC;QACM,QAAG,GAAW,EAAE,CA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A8C,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAClE,CAAC;QAEF,QAAQ,CAAC,EAAE,CAAC,OAAO,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;QACvC,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,oBAAoB,EAAE,CAAC,CAAC;QACvD,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;QAC9C,QAAQ,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;QAC1D,QAAQ,CAAC,EAAE,CAAC,SAAS,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;QAC3C,QAAQ,CAAC,EAAE,CAAC,YAAY,EAAE,CAAC,UAAqB,EAAE,EAAE;YAClD,IAAI,CAAC,EAAE,GAAG,UAAU,CAAC;YACrB,UAAU,CAAC,SAAS,GAAG,IAAI,CAAC,aAAa,CAAC;QAC5C,CAAC,CAAC,CAAC;IACL,CAAC;IAED,WAAW,CAAC,OAAY;;QACtB,MAAA,IAAI,CAAC,EAAE,0CAAE,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC;IACzC,CAAC;CAwDF,CAAA;AAvGY,8BAAS;oBAAT,SAAS;IADrB,IAAA,mBAAU,GAAE;GACA,SAAS,CAuGrB"}
|
|
@@ -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"],"names":[],"mappings":";;AAGA,oCAcC;AAjBD,qCAA8C;AAC9C,0CAA2C;AAE3C,SAAgB,YAAY,CAAC,MAAoB;IAC/C,OAAO,IAAI,eAAK,CAAC;QACf,IAAI,EAAE,MAAM,CAAC,OAAO,CAAC,SAAS,IAAI,uBAAY;QAC9C,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC;YACpE,IAAI;YACJ,IAAI,EAAE,iBAAiB,CAAC,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,IAAI,CAAC;YAClC,SAAS,EAAE,CAAC,CAAC,CAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,OAAO,CAAA;YACzB,WAAW,EAAE,CAAC,CAAC,CAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,SAAS,CAAA;YAC7B,kBAAkB,EAAE,CAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,SAAS,EAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS;YAC5D,QAAQ,EAAE,CAAC,CAAC,CAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,MAAM,CAAA;YACvB,UAAU,EAAE,CAAC,CAAC,CAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,QAAQ,CAAA;YAC3B,OAAO,EAAE,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,OAAO;SACtB,CAAC,CAAC;KACJ,CAAC,CAAC;AACL,CAAC;AAED,SAAS,iBAAiB,CAAC,IAAS;IAClC,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,MAAM;YACT,OAAO,MAAM,CAAC;QAChB,KAAK,MAAM;YACT,OAAO,KAAK,CAAC;QACf,KAAK,IAAI;YACP,OAAO,WAAW,CAAC;QACrB,KAAK,OAAO;YACV,OAAO,SAAS,CAAC;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
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "NestJS internal logging system",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -13,20 +13,27 @@
|
|
|
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
|
],
|
|
21
26
|
"author": "Dzmitry Sharko",
|
|
22
27
|
"license": "ISC",
|
|
23
28
|
"peerDependencies": {
|
|
24
|
-
"@nestjs/common": "^
|
|
25
|
-
"@nestjs/core": "^
|
|
29
|
+
"@nestjs/common": "^11.0.0",
|
|
30
|
+
"@nestjs/core": "^11.0.0",
|
|
26
31
|
"@nestjs/typeorm": "^11.0.0",
|
|
32
|
+
"@nestjs/websockets": "^11.1.7",
|
|
27
33
|
"reflect-metadata": "^0.2.2",
|
|
28
34
|
"rxjs": "^7.8.2",
|
|
29
|
-
"typeorm": "^0.3.27"
|
|
35
|
+
"typeorm": "^0.3.27",
|
|
36
|
+
"ws": "^8.18.3"
|
|
30
37
|
},
|
|
31
38
|
"devDependencies": {
|
|
32
39
|
"@types/node": "^24.5.2",
|
package/public/index.html
CHANGED
|
@@ -8,6 +8,11 @@
|
|
|
8
8
|
<link rel="stylesheet" href="styles/reset.css" />
|
|
9
9
|
<link rel="stylesheet" href="styles/colors.css" />
|
|
10
10
|
<link rel="stylesheet" href="styles/index.css" />
|
|
11
|
+
<script
|
|
12
|
+
defer="defer"
|
|
13
|
+
src="scripts/ws.js
|
|
14
|
+
"
|
|
15
|
+
></script>
|
|
11
16
|
<script
|
|
12
17
|
defer="defer"
|
|
13
18
|
src="scripts/json-viewer.js
|
|
@@ -42,12 +47,12 @@
|
|
|
42
47
|
</ul>
|
|
43
48
|
</nav>
|
|
44
49
|
<input id="search" onkeyup="search(event)" type="text" placeholder="Search" />
|
|
45
|
-
<div onclick="getLogs()"><button class="white">Refresh</button></div>
|
|
50
|
+
<div id="refresh" onclick="getLogs()"><button class="white">Refresh</button></div>
|
|
51
|
+
<div id="freeze" onclick="toggleFreeze()"><button class="white">Freeze</button></div>
|
|
46
52
|
</div>
|
|
47
53
|
<div class="container table-header">
|
|
48
54
|
<div class="col">Type</div>
|
|
49
55
|
<div class="col">Info</div>
|
|
50
|
-
<div class="col">Trace</div>
|
|
51
56
|
<div class="col">Count</div>
|
|
52
57
|
</div>
|
|
53
58
|
</header>
|