dl-commons 0.0.2-testing.36 → 0.0.2-testing.38
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/dl-commons.module.js +3 -2
- package/dist/dl-commons.module.js.map +1 -1
- package/dist/filters/base-exception.filter.d.ts +3 -3
- package/dist/filters/base-exception.filter.js +4 -11
- package/dist/filters/base-exception.filter.js.map +1 -1
- package/dist/models/interfaces/author.interface.d.ts +1 -0
- package/dist/models/schemas/embedded/author.schema.d.ts +1 -0
- package/dist/models/schemas/embedded/author.schema.js +4 -0
- package/dist/models/schemas/embedded/author.schema.js.map +1 -1
- package/dist/services/app-logger.service.d.ts +11 -0
- package/dist/services/app-logger.service.js +72 -0
- package/dist/services/app-logger.service.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -1
- package/src/dl-commons.module.ts +3 -2
- package/src/filters/base-exception.filter.ts +5 -12
- package/src/models/interfaces/author.interface.ts +1 -0
- package/src/models/schemas/embedded/author.schema.ts +3 -0
- package/src/services/app-logger.service.ts +66 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dl-commons",
|
|
3
3
|
"type": "commonjs",
|
|
4
|
-
"version": "0.0.2-testing.
|
|
4
|
+
"version": "0.0.2-testing.38",
|
|
5
5
|
"description": "distance learning commons",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
"class-transformer": "^0.5.1",
|
|
22
22
|
"class-validator": "^0.14.0",
|
|
23
23
|
"express": "^4.18.2",
|
|
24
|
+
"gelf-pro": "^1.4.0",
|
|
24
25
|
"mongoose": "^8.0.4",
|
|
25
26
|
"reflect-metadata": "^0.2.2"
|
|
26
27
|
},
|
package/src/dl-commons.module.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { Session, SessionSchema } from './models/schemas/session.schema';
|
|
|
7
7
|
import { HttpModule } from '@nestjs/axios';
|
|
8
8
|
import { ISession } from './models/interfaces/session.interface';
|
|
9
9
|
import { DictionariesService } from './services/dictionaries.service';
|
|
10
|
+
import { AppLoggerService } from './services/app-logger.service';
|
|
10
11
|
|
|
11
12
|
declare global {
|
|
12
13
|
namespace Express {
|
|
@@ -30,7 +31,7 @@ declare global {
|
|
|
30
31
|
MongooseModule.forFeature([{ name: Session.name, schema: SessionSchema }], 'sessions-store'),
|
|
31
32
|
],
|
|
32
33
|
controllers: [],
|
|
33
|
-
providers: [SessionsService, DictionariesService],
|
|
34
|
-
exports: [SessionsService, DictionariesService],
|
|
34
|
+
providers: [SessionsService, DictionariesService, AppLoggerService],
|
|
35
|
+
exports: [SessionsService, DictionariesService, AppLoggerService],
|
|
35
36
|
})
|
|
36
37
|
export class DLCommonsModule {}
|
|
@@ -27,27 +27,20 @@ import { mongo } from 'mongoose';
|
|
|
27
27
|
import { ValidationError } from 'class-validator';
|
|
28
28
|
import { HandledException } from '../exceptions/custom.exception';
|
|
29
29
|
import { RESTError } from '../models/dtos/wrappers/rest-wrapper.class';
|
|
30
|
+
import { AppLoggerService } from '../services/app-logger.service';
|
|
30
31
|
|
|
31
32
|
export class BaseExceptionsFilter implements ExceptionFilter {
|
|
32
|
-
|
|
33
|
-
private _log: boolean = false;
|
|
33
|
+
|
|
34
34
|
|
|
35
|
-
constructor(
|
|
36
|
-
this._debug = debug;
|
|
37
|
-
this._log = log;
|
|
35
|
+
constructor(private readonly _appLoggerService: AppLoggerService) {
|
|
38
36
|
}
|
|
39
37
|
|
|
40
38
|
catch(exception: any, host: ArgumentsHost) {
|
|
41
39
|
const context = host.switchToHttp();
|
|
42
40
|
const response = context.getResponse<Response>();
|
|
43
41
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
if (this._log) {
|
|
49
|
-
console.log(exception);
|
|
50
|
-
}
|
|
42
|
+
this._appLoggerService.info('BaseExceptionsFilter - name:', exception.constructor.name);
|
|
43
|
+
this._appLoggerService.info('BaseExceptionsFilter - exception:', exception);
|
|
51
44
|
|
|
52
45
|
let handledException: HandledException | any = null;
|
|
53
46
|
|
|
@@ -18,6 +18,9 @@ export class Author implements IAuthor {
|
|
|
18
18
|
|
|
19
19
|
@Prop({ type: String, required: false, default: null })
|
|
20
20
|
lastName: string | null | undefined;
|
|
21
|
+
|
|
22
|
+
@Prop({ type: String, required: false, default: null })
|
|
23
|
+
organisationName: string | null | undefined;
|
|
21
24
|
}
|
|
22
25
|
|
|
23
26
|
export const AuthorSchema = SchemaFactory.createForClass(Author);
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { Injectable } from '@nestjs/common';
|
|
2
|
+
import { ConfigService } from '@nestjs/config';
|
|
3
|
+
import gelf from 'gelf-pro';
|
|
4
|
+
|
|
5
|
+
@Injectable()
|
|
6
|
+
export class AppLoggerService {
|
|
7
|
+
//#region Private Members
|
|
8
|
+
private readonly _isGraylogEnabled: boolean = this._configService.get<boolean>('GRAYLOG__ENABLED') || false;
|
|
9
|
+
//#endregion
|
|
10
|
+
|
|
11
|
+
//#region Constructor
|
|
12
|
+
constructor(private readonly _configService: ConfigService) {
|
|
13
|
+
if (this._isGraylogEnabled) {
|
|
14
|
+
gelf.setConfig({
|
|
15
|
+
adapterName: 'udp',
|
|
16
|
+
adapterOptions: {
|
|
17
|
+
host: _configService.get('GRAYLOG__HOST') || 'graylog-input.emis.ge',
|
|
18
|
+
port: _configService.get<number>('GRAYLOG__PORT'),
|
|
19
|
+
},
|
|
20
|
+
fields: { facility: _configService.get('GRAYLOG__FACILITY'), hostname: _configService.get('GRAYLOG__HOSTNAME') },
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
//#endregion
|
|
25
|
+
|
|
26
|
+
//#region Public API
|
|
27
|
+
public async info(message: string, data?: any) {
|
|
28
|
+
if (this._isGraylogEnabled) {
|
|
29
|
+
this._send(5, message, data);
|
|
30
|
+
} else {
|
|
31
|
+
console.info(message, data);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
public async error(message: string, data?: any) {
|
|
36
|
+
if (this._isGraylogEnabled) {
|
|
37
|
+
this._send(2, message, data);
|
|
38
|
+
} else {
|
|
39
|
+
console.error(message, data);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
public async warn(message: string, data?: any) {
|
|
44
|
+
if (this._isGraylogEnabled) {
|
|
45
|
+
this._send(3, message, data);
|
|
46
|
+
} else {
|
|
47
|
+
console.warn(message, data);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
public async debug(message: string, data?: any) {
|
|
52
|
+
if (this._isGraylogEnabled) {
|
|
53
|
+
this._send(5, message, data);
|
|
54
|
+
} else {
|
|
55
|
+
console.debug(message, data);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
//#endregion
|
|
59
|
+
|
|
60
|
+
//#region Private APIs
|
|
61
|
+
private _send(level: number, message: string, extra: any = {}) {
|
|
62
|
+
// 1 = fatal, 2 = error, 3 = warn, 4 = info, 5 = debug, 6 = trace
|
|
63
|
+
gelf.message('gelf.log', level, extra);
|
|
64
|
+
}
|
|
65
|
+
//#endregion
|
|
66
|
+
}
|