@viplance/nestjs-logger 0.3.8 → 0.4.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 +37 -4
- package/dist/defaults.js +1 -1
- package/dist/entities/log.entity.d.ts +2 -2
- package/dist/entities/log.entity.js +1 -1
- package/dist/guards/access.guard.d.ts +1 -1
- package/dist/guards/access.guard.js +2 -2
- package/dist/index.d.ts +4 -4
- package/dist/interceptors/log.interceptor.d.ts +4 -4
- package/dist/log.module.d.ts +1 -1
- package/dist/log.module.js +33 -7
- package/dist/log.module.js.map +1 -1
- package/dist/services/log.service.d.ts +15 -9
- package/dist/services/log.service.js +87 -30
- package/dist/services/log.service.js.map +1 -1
- package/dist/services/memory-db.service.d.ts +1 -1
- package/dist/services/memory-db.service.js +5 -5
- 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/index.d.ts +3 -3
- package/dist/types/options.type.d.ts +7 -0
- package/dist/utils/entity2table.d.ts +1 -1
- package/dist/utils/entity2table.js +6 -6
- package/package.json +9 -4
- package/public/index.html +7 -2
- package/public/scripts/common.js +74 -43
- package/public/scripts/details-popup.js +18 -9
- package/public/scripts/json-viewer.js +4 -4
- package/public/scripts/ws.js +83 -0
- package/public/styles/index.css +5 -0
- package/src/defaults.ts +1 -1
- package/src/entities/log.entity.ts +3 -3
- package/src/guards/access.guard.ts +5 -5
- package/src/index.ts +4 -4
- package/src/interceptors/log.interceptor.ts +5 -5
- package/src/log.module.ts +50 -17
- package/src/services/log.service.ts +118 -40
- package/src/services/memory-db.service.ts +9 -9
- package/src/services/ws.d.ts +1 -0
- package/src/services/ws.service.ts +110 -0
- package/src/types/index.ts +3 -3
- package/src/types/log.type.ts +5 -5
- package/src/types/options.type.ts +7 -0
- package/src/utils/entity2table.ts +8 -8
- package/public/json.html +0 -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';
|
|
@@ -54,16 +67,36 @@ Connect the database to store logs.<br />
|
|
|
54
67
|
|
|
55
68
|
### Additional information
|
|
56
69
|
|
|
57
|
-
- `path`, `key` and `
|
|
58
|
-
- The
|
|
70
|
+
- `path`, `key`, `database` and `websocket` properties are optional.
|
|
71
|
+
- The log UI could be available at `your_application_url`/`path`?key=`key` or WebSocket port
|
|
59
72
|
- The log API could be available at `your_application_url`/`path`/api?key=`key`
|
|
60
73
|
- By default the logs will be stored in memory and deleted when the application stops.<br />
|
|
61
74
|
<br />
|
|
62
75
|
|
|
76
|
+
### The LogModule options:
|
|
77
|
+
- path?: string;
|
|
78
|
+
- key?: string; // access key
|
|
79
|
+
- join?: boolean; // merge the message duplicates
|
|
80
|
+
- maxRecords?: number; // max log records
|
|
81
|
+
- maxAge?: number; // in days
|
|
82
|
+
- maxSize?: number; // in megabytes
|
|
83
|
+
- database?: DataSourceOptions & {
|
|
84
|
+
host?: string;
|
|
85
|
+
port?: string;
|
|
86
|
+
table?: string;
|
|
87
|
+
collection?: string;
|
|
88
|
+
};
|
|
89
|
+
- websocket?: {
|
|
90
|
+
port?: number;
|
|
91
|
+
namespace?: string;
|
|
92
|
+
host?: string;
|
|
93
|
+
secure?: boolean;
|
|
94
|
+
};
|
|
95
|
+
|
|
63
96
|
### The LogService methods:
|
|
64
97
|
- log(message: string)
|
|
65
98
|
- error(message: string)
|
|
66
99
|
- warn(message: string)
|
|
67
100
|
- debug(message: string)
|
|
68
101
|
- verbose(message: string)
|
|
69
|
-
- addBreadcrumb(breadcrumb: any)
|
|
102
|
+
- addBreadcrumb(breadcrumb: any) - adds extra details to the logs for the current request
|
package/dist/defaults.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { DataSourceOptions, EntitySchema } from
|
|
2
|
-
export declare function createLogEntity(name: string, dbType: DataSourceOptions[
|
|
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;
|
|
@@ -18,9 +18,9 @@ let LogAccessGuard = class LogAccessGuard {
|
|
|
18
18
|
const req = !!context.switchToHttp
|
|
19
19
|
? context.switchToHttp().getRequest()
|
|
20
20
|
: context; // hook for using as method
|
|
21
|
-
const params = node_querystring_1.default.parse(req.url.split(
|
|
21
|
+
const params = node_querystring_1.default.parse(req.url.split('?')[1]);
|
|
22
22
|
if (log_service_1.LogService.options.key && params.key !== log_service_1.LogService.options.key) {
|
|
23
|
-
throw new common_1.HttpException(
|
|
23
|
+
throw new common_1.HttpException('Unauthorized', 401);
|
|
24
24
|
}
|
|
25
25
|
return true;
|
|
26
26
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
1
|
+
export * from './interceptors/log.interceptor';
|
|
2
|
+
export * from './log.module';
|
|
3
|
+
export * from './types/index';
|
|
4
|
+
export * from './services/log.service';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { CallHandler, NestInterceptor } from
|
|
2
|
-
import { Observable } from
|
|
3
|
-
import { LogService } from
|
|
4
|
-
import { ExecutionContextHost } from
|
|
1
|
+
import type { CallHandler, NestInterceptor } from '@nestjs/common';
|
|
2
|
+
import { Observable } from 'rxjs';
|
|
3
|
+
import { LogService } from '../services/log.service';
|
|
4
|
+
import { ExecutionContextHost } from '@nestjs/core/helpers/execution-context-host';
|
|
5
5
|
export declare class LogInterceptor implements NestInterceptor {
|
|
6
6
|
private readonly logService;
|
|
7
7
|
constructor(logService: LogService);
|
package/dist/log.module.d.ts
CHANGED
package/dist/log.module.js
CHANGED
|
@@ -19,34 +19,54 @@ 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);
|
|
29
31
|
}
|
|
30
32
|
app.useGlobalInterceptors(new log_interceptor_1.LogInterceptor(logService)); // intercept all errors
|
|
31
33
|
if (options === null || options === void 0 ? void 0 : options.path) {
|
|
32
|
-
app.useStaticAssets((0, node_path_1.join)(__dirname,
|
|
34
|
+
app.useStaticAssets((0, node_path_1.join)(__dirname, '..', 'public'), {
|
|
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
|
-
httpAdapter.get((0, node_path_1.join)(options.path,
|
|
53
|
+
httpAdapter.get((0, node_path_1.join)(options.path, 'api'), async (req, res) => {
|
|
38
54
|
logAccessGuard.canActivate(req);
|
|
39
55
|
res.json(await logService.getAll());
|
|
40
56
|
});
|
|
41
57
|
// delete log endpoint
|
|
42
|
-
httpAdapter.delete((0, node_path_1.join)(options.path,
|
|
58
|
+
httpAdapter.delete((0, node_path_1.join)(options.path, 'api'), async (req, res) => {
|
|
43
59
|
logAccessGuard.canActivate(req);
|
|
44
|
-
const params = node_querystring_1.default.parse(req.url.split(
|
|
60
|
+
const params = node_querystring_1.default.parse(req.url.split('?')[1]);
|
|
45
61
|
if (!params.id) {
|
|
46
|
-
throw new common_1.HttpException(
|
|
62
|
+
throw new common_1.HttpException('id is required', 400);
|
|
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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;YAC9B,IAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,SAAS,EAAE,CAAC;gBACvB,SAAS,CAAC,eAAe,CAAC,OAAO,CAAC,SAAS,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC;YAC5D,CAAC;QACH,CAAC;QAED,IAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,QAAQ,EAAE,CAAC;YACtB,MAAM,UAAU,CAAC,SAAS,CAAC,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
|
|
2
|
-
import { MemoryDbService } from
|
|
3
|
-
import { LogModuleOptions } from
|
|
4
|
-
import { DataSource, EntitySchema } from
|
|
5
|
-
import { ExecutionContextHost } from
|
|
6
|
-
import { setInterval } from
|
|
7
|
-
|
|
1
|
+
import { LoggerService, OnApplicationShutdown } from '@nestjs/common';
|
|
2
|
+
import { MemoryDbService } from './memory-db.service';
|
|
3
|
+
import { LogModuleOptions } from '../types';
|
|
4
|
+
import { DataSource, EntitySchema } from 'typeorm';
|
|
5
|
+
import { ExecutionContextHost } from '@nestjs/core/helpers/execution-context-host';
|
|
6
|
+
import { setInterval } from 'timers';
|
|
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;
|
|
@@ -19,15 +19,24 @@ const typeorm_1 = require("typeorm");
|
|
|
19
19
|
const log_entity_1 = require("../entities/log.entity");
|
|
20
20
|
const timers_1 = require("timers");
|
|
21
21
|
const entity2table_1 = require("../utils/entity2table");
|
|
22
|
+
const ws_service_1 = require("./ws.service");
|
|
22
23
|
let LogService = LogService_1 = class LogService {
|
|
23
|
-
constructor(memoryDbService) {
|
|
24
|
+
constructor(memoryDbService, wsService) {
|
|
24
25
|
this.memoryDbService = memoryDbService;
|
|
26
|
+
this.wsService = wsService;
|
|
25
27
|
this.breadcrumbs = [];
|
|
26
28
|
}
|
|
29
|
+
onApplicationShutdown() {
|
|
30
|
+
if (LogService_1.timer) {
|
|
31
|
+
clearInterval(LogService_1.timer);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
27
34
|
async connectDb(options) {
|
|
28
35
|
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) ||
|
|
30
|
-
|
|
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
|
+
}
|
|
31
40
|
const dataSourceOptions = {
|
|
32
41
|
type: (_d = options.database) === null || _d === void 0 ? void 0 : _d.type,
|
|
33
42
|
database: (_e = options.database) === null || _e === void 0 ? void 0 : _e.database,
|
|
@@ -37,8 +46,7 @@ let LogService = LogService_1 = class LogService {
|
|
|
37
46
|
};
|
|
38
47
|
LogService_1.connection = new typeorm_1.DataSource(dataSourceOptions);
|
|
39
48
|
await LogService_1.connection.initialize();
|
|
40
|
-
if (dataSourceOptions.type !==
|
|
41
|
-
// LogService.idName = "id";
|
|
49
|
+
if (dataSourceOptions.type !== 'mongodb') {
|
|
42
50
|
const queryRunner = LogService_1.connection.createQueryRunner();
|
|
43
51
|
try {
|
|
44
52
|
await queryRunner.connect();
|
|
@@ -57,6 +65,21 @@ let LogService = LogService_1 = class LogService {
|
|
|
57
65
|
}
|
|
58
66
|
setOptions(options) {
|
|
59
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
|
+
}
|
|
60
83
|
}
|
|
61
84
|
addBreadcrumb(breadcrumb) {
|
|
62
85
|
this.breadcrumbs.push(breadcrumb);
|
|
@@ -103,43 +126,62 @@ let LogService = LogService_1 = class LogService {
|
|
|
103
126
|
async getAll() {
|
|
104
127
|
return this.getConnection().find(LogService_1.Log, {
|
|
105
128
|
select: [
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
129
|
+
'_id',
|
|
130
|
+
'type',
|
|
131
|
+
'message',
|
|
132
|
+
'count',
|
|
133
|
+
'createdAt',
|
|
134
|
+
'updatedAt',
|
|
135
|
+
'context',
|
|
136
|
+
'trace',
|
|
137
|
+
'breadcrumbs',
|
|
115
138
|
],
|
|
116
|
-
order: { updatedAt:
|
|
139
|
+
order: { updatedAt: 'DESC' },
|
|
117
140
|
});
|
|
118
141
|
}
|
|
119
|
-
async delete(
|
|
120
|
-
|
|
142
|
+
async delete(_id) {
|
|
143
|
+
this.wsService.sendMessage({
|
|
144
|
+
action: 'delete',
|
|
145
|
+
data: { _id },
|
|
146
|
+
});
|
|
147
|
+
return this.getConnection().delete(LogService_1.Log, _id);
|
|
121
148
|
}
|
|
122
149
|
async smartInsert(data) {
|
|
123
150
|
const currentDate = new Date();
|
|
124
151
|
const connection = this.getConnection();
|
|
125
152
|
// find the same log in DB
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
153
|
+
let log;
|
|
154
|
+
if (LogService_1.options.join) {
|
|
155
|
+
log = await connection.findOne(LogService_1.Log, {
|
|
156
|
+
where: {
|
|
157
|
+
type: data.type,
|
|
158
|
+
message: data.message,
|
|
159
|
+
},
|
|
160
|
+
});
|
|
161
|
+
}
|
|
132
162
|
const context = data.context ? this.parseContext(data.context) : undefined;
|
|
133
163
|
if (log) {
|
|
134
|
-
|
|
164
|
+
const updatedLog = {
|
|
165
|
+
context,
|
|
166
|
+
trace: data.trace,
|
|
167
|
+
breadcrumbs: this.breadcrumbs,
|
|
168
|
+
count: log.count + 1,
|
|
169
|
+
updatedAt: currentDate,
|
|
170
|
+
};
|
|
171
|
+
this.wsService.sendMessage({
|
|
172
|
+
action: 'update',
|
|
173
|
+
data: { ...log, ...updatedLog },
|
|
174
|
+
});
|
|
175
|
+
await connection.update(LogService_1.Log, log['_id'], {
|
|
135
176
|
context,
|
|
136
177
|
trace: data.trace,
|
|
137
178
|
breadcrumbs: this.breadcrumbs,
|
|
138
179
|
count: log.count + 1,
|
|
139
180
|
updatedAt: currentDate,
|
|
140
181
|
});
|
|
182
|
+
return { ...log, ...updatedLog };
|
|
141
183
|
}
|
|
142
|
-
|
|
184
|
+
const insertedLog = {
|
|
143
185
|
type: data.type,
|
|
144
186
|
message: data.message,
|
|
145
187
|
context,
|
|
@@ -148,7 +190,21 @@ let LogService = LogService_1 = class LogService {
|
|
|
148
190
|
count: 1,
|
|
149
191
|
createdAt: currentDate,
|
|
150
192
|
updatedAt: currentDate,
|
|
193
|
+
};
|
|
194
|
+
const res = await connection.insert(LogService_1.Log, insertedLog);
|
|
195
|
+
const _id = this.getNewObjectId(res);
|
|
196
|
+
this.wsService.sendMessage({
|
|
197
|
+
action: 'insert',
|
|
198
|
+
data: { _id, ...insertedLog },
|
|
151
199
|
});
|
|
200
|
+
return { _id, ...insertedLog };
|
|
201
|
+
}
|
|
202
|
+
getNewObjectId(result) {
|
|
203
|
+
if (result.identifiers) {
|
|
204
|
+
return result.identifiers[0]._id;
|
|
205
|
+
}
|
|
206
|
+
console.log(result);
|
|
207
|
+
return result._id;
|
|
152
208
|
}
|
|
153
209
|
getConnection() {
|
|
154
210
|
var _a;
|
|
@@ -184,9 +240,9 @@ let LogService = LogService_1 = class LogService {
|
|
|
184
240
|
var _a, _b;
|
|
185
241
|
if ((_a = LogService_1.options) === null || _a === void 0 ? void 0 : _a.maxSize) {
|
|
186
242
|
const latest = await this.getConnection().find(LogService_1.Log, {
|
|
187
|
-
order: { updatedAt:
|
|
243
|
+
order: { updatedAt: 'DESC' },
|
|
188
244
|
take: (_b = LogService_1.options) === null || _b === void 0 ? void 0 : _b.maxSize,
|
|
189
|
-
select: [
|
|
245
|
+
select: ['_id'],
|
|
190
246
|
});
|
|
191
247
|
const latestIds = latest.map((item) => item.id);
|
|
192
248
|
await LogService_1.connection
|
|
@@ -194,15 +250,16 @@ let LogService = LogService_1 = class LogService {
|
|
|
194
250
|
.createQueryBuilder()
|
|
195
251
|
.delete()
|
|
196
252
|
.from(LogService_1.Log)
|
|
197
|
-
.where(
|
|
253
|
+
.where('_id NOT IN (:...ids)', { ids: latestIds })
|
|
198
254
|
.execute();
|
|
199
255
|
}
|
|
200
256
|
}
|
|
201
257
|
};
|
|
202
258
|
exports.LogService = LogService;
|
|
203
|
-
LogService.Log = (0, log_entity_1.createLogEntity)(defaults_1.defaultTable,
|
|
259
|
+
LogService.Log = (0, log_entity_1.createLogEntity)(defaults_1.defaultTable, 'memory');
|
|
204
260
|
exports.LogService = LogService = LogService_1 = __decorate([
|
|
205
261
|
(0, common_1.Injectable)({ scope: common_1.Scope.TRANSIENT }),
|
|
206
|
-
__metadata("design:paramtypes", [memory_db_service_1.MemoryDbService
|
|
262
|
+
__metadata("design:paramtypes", [memory_db_service_1.MemoryDbService,
|
|
263
|
+
ws_service_1.WsService])
|
|
207
264
|
], LogService);
|
|
208
265
|
//# 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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AC,CAAC,GAAG,CAAC,CAAC,CAAC;gBAC5D,CAAC;YACH,CAAC;QACH,CAAC;QAED,OAAO,GAAG,CAAC;IACb,CAAC;IAEO,KAAK,CAAC,YAAY;;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;;AAzSU,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,CA0StB"}
|
|
@@ -26,8 +26,8 @@ let MemoryDbService = class MemoryDbService {
|
|
|
26
26
|
insert(entity, data) {
|
|
27
27
|
const table = this.getTableName(entity);
|
|
28
28
|
// generate new random _id
|
|
29
|
-
const randomData = (0, crypto_1.randomBytes)(24).toString(
|
|
30
|
-
const _id = (0, crypto_1.createHash)(
|
|
29
|
+
const randomData = (0, crypto_1.randomBytes)(24).toString('hex');
|
|
30
|
+
const _id = (0, crypto_1.createHash)('sha256').update(randomData).digest('hex');
|
|
31
31
|
this.db[table].push({
|
|
32
32
|
...data,
|
|
33
33
|
_id, // unique index
|
|
@@ -37,7 +37,7 @@ let MemoryDbService = class MemoryDbService {
|
|
|
37
37
|
async update(entity, condition, data) {
|
|
38
38
|
const table = this.getTableName(entity);
|
|
39
39
|
let index = null;
|
|
40
|
-
if (typeof condition ===
|
|
40
|
+
if (typeof condition === 'string') {
|
|
41
41
|
index = this.findIndex(entity, { where: { _id: condition } });
|
|
42
42
|
}
|
|
43
43
|
if (condition === null || condition === void 0 ? void 0 : condition.where) {
|
|
@@ -94,8 +94,8 @@ let MemoryDbService = class MemoryDbService {
|
|
|
94
94
|
// handle null or non-object values
|
|
95
95
|
if (obj1 == null ||
|
|
96
96
|
obj2 == null ||
|
|
97
|
-
typeof obj1 !==
|
|
98
|
-
typeof obj2 !==
|
|
97
|
+
typeof obj1 !== 'object' ||
|
|
98
|
+
typeof obj2 !== 'object') {
|
|
99
99
|
return false;
|
|
100
100
|
}
|
|
101
101
|
// compare keys length
|
|
@@ -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
|
+
}
|