dl-commons 0.0.2-testing.40 → 0.0.2-testing.42

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.
@@ -1,8 +1,8 @@
1
1
  export declare class Logger {
2
2
  private _isGraylog;
3
- private _host;
4
- private _port;
5
- private _hostname;
6
- private _facility;
7
3
  constructor(host: string, port: number, hostname: string, facility: string, isGraylog?: boolean);
4
+ info(message: string, data?: any): Promise<void>;
5
+ error(message: string, data?: any): Promise<void>;
6
+ warn(message: string, data?: any): Promise<void>;
7
+ debug(message: string, data?: any): Promise<void>;
8
8
  }
@@ -1,12 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Logger = void 0;
4
- const gelf_pro_1 = require("gelf-pro");
4
+ const gelf = require('gelf-pro');
5
5
  class Logger {
6
6
  constructor(host, port, hostname, facility, isGraylog = false) {
7
7
  this._isGraylog = isGraylog;
8
8
  if (this._isGraylog) {
9
- gelf_pro_1.default.setConfig({
9
+ gelf.setConfig({
10
10
  adapterName: 'udp',
11
11
  adapterOptions: {
12
12
  host,
@@ -16,6 +16,38 @@ class Logger {
16
16
  });
17
17
  }
18
18
  }
19
+ async info(message, data) {
20
+ if (this._isGraylog) {
21
+ gelf.info(message, data);
22
+ }
23
+ else {
24
+ console.info(message, data);
25
+ }
26
+ }
27
+ async error(message, data) {
28
+ if (this._isGraylog) {
29
+ gelf.error(message, data);
30
+ }
31
+ else {
32
+ console.error(message, data);
33
+ }
34
+ }
35
+ async warn(message, data) {
36
+ if (this._isGraylog) {
37
+ gelf.warn(message, data);
38
+ }
39
+ else {
40
+ console.warn(message, data);
41
+ }
42
+ }
43
+ async debug(message, data) {
44
+ if (this._isGraylog) {
45
+ gelf.debug(message, data);
46
+ }
47
+ else {
48
+ console.debug(message, data);
49
+ }
50
+ }
19
51
  }
20
52
  exports.Logger = Logger;
21
53
  //# sourceMappingURL=logger.class.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"logger.class.js","sourceRoot":"","sources":["../../src/utils/logger.class.ts"],"names":[],"mappings":";;;AAAA,uCAA4B;AAE5B,MAAa,MAAM;IASf,YAAY,IAAY,EAAE,IAAY,EAAE,QAAgB,EAAE,QAAgB,EAAE,YAAqB,KAAK;QAClG,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;QAE5B,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YAClB,kBAAI,CAAC,SAAS,CAAC;gBACX,WAAW,EAAE,KAAK;gBAClB,cAAc,EAAE;oBACZ,IAAI;oBACJ,IAAI;iBACP;gBACD,MAAM,EAAE,EAAE,QAAQ,EAAE,QAAQ,EAAE;aACjC,CAAC,CAAC;QACP,CAAC;IACL,CAAC;CACJ;AAvBD,wBAuBC"}
1
+ {"version":3,"file":"logger.class.js","sourceRoot":"","sources":["../../src/utils/logger.class.ts"],"names":[],"mappings":";;;AAAA,MAAM,IAAI,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AAEjC,MAAa,MAAM;IAMf,YAAY,IAAY,EAAE,IAAY,EAAE,QAAgB,EAAE,QAAgB,EAAE,YAAqB,KAAK;QAClG,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;QAE5B,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YAClB,IAAI,CAAC,SAAS,CAAC;gBACX,WAAW,EAAE,KAAK;gBAClB,cAAc,EAAE;oBACZ,IAAI;oBACJ,IAAI;iBACP;gBACD,MAAM,EAAE,EAAE,QAAQ,EAAE,QAAQ,EAAE;aACjC,CAAC,CAAC;QACP,CAAC;IACL,CAAC;IAIM,KAAK,CAAC,IAAI,CAAC,OAAe,EAAE,IAAU;QACzC,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YAClB,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QAC7B,CAAC;aAAM,CAAC;YACJ,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QAChC,CAAC;IACL,CAAC;IAEM,KAAK,CAAC,KAAK,CAAC,OAAe,EAAE,IAAU;QAC1C,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YAClB,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QAC9B,CAAC;aAAM,CAAC;YACJ,OAAO,CAAC,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QACjC,CAAC;IACL,CAAC;IAEM,KAAK,CAAC,IAAI,CAAC,OAAe,EAAE,IAAU;QACzC,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YAClB,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QAC7B,CAAC;aAAM,CAAC;YACJ,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QAChC,CAAC;IACL,CAAC;IAEM,KAAK,CAAC,KAAK,CAAC,OAAe,EAAE,IAAU;QAC1C,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YAClB,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QAC9B,CAAC;aAAM,CAAC;YACJ,OAAO,CAAC,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QACjC,CAAC;IACL,CAAC;CAEJ;AAvDD,wBAuDC"}
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.40",
4
+ "version": "0.0.2-testing.42",
5
5
  "description": "distance learning commons",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
package/src/index.ts CHANGED
@@ -130,8 +130,15 @@ import { IArchive } from './models/interfaces/archive.interface';
130
130
  import { Archive, ArchiveDocument, ArchiveSchema } from './models/schemas/embedded/archive.schema';
131
131
  import { StudentsService } from './services/students.service';
132
132
  import { GroupsService } from './services/groups.service';
133
+ import { Logger } from './utils/logger.class';
134
+ import { AppLoggerService } from './services/app-logger.service';
133
135
 
134
136
  export {
137
+ /**
138
+ * Utils
139
+ */
140
+ Logger,
141
+
135
142
  /**
136
143
  * Services
137
144
  */
@@ -143,6 +150,7 @@ export {
143
150
  IAMService,
144
151
  StudentsService,
145
152
  GroupsService,
153
+ AppLoggerService,
146
154
 
147
155
  /**
148
156
  * Rest Wrapper
@@ -1,66 +1,39 @@
1
1
  import { Injectable } from '@nestjs/common';
2
2
  import { ConfigService } from '@nestjs/config';
3
- const gelf = require('gelf-pro');
3
+ import { Logger } from '../utils/logger.class';
4
4
 
5
5
  @Injectable()
6
6
  export class AppLoggerService {
7
7
  //#region Private Members
8
- private readonly _isGraylogEnabled: boolean = this._configService.get<boolean>('GRAYLOG__ENABLED') || false;
8
+ private _logger: Logger;
9
9
  //#endregion
10
10
 
11
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
- }
12
+ constructor(_configService: ConfigService) {
13
+ const isGraylog = _configService.get<boolean>('GRAYLOG__ENABLED') || false;
14
+ const host = _configService.get('GRAYLOG__HOST') || 'graylog-input.emis.ge';
15
+ const port = _configService.get<number>('GRAYLOG__PORT');
16
+ const facility = _configService.get('GRAYLOG__FACILITY');
17
+ const hostname = _configService.get('GRAYLOG__HOSTNAME');
18
+ this._logger = new Logger(host, port, facility, hostname, isGraylog);
23
19
  }
24
20
  //#endregion
25
21
 
26
22
  //#region Public API
27
23
  public async info(message: string, data?: any) {
28
- if (this._isGraylogEnabled) {
29
- gelf.info(message, data);
30
- } else {
31
- console.info(message, data);
32
- }
24
+ this._logger.info(message, data);
33
25
  }
34
26
 
35
27
  public async error(message: string, data?: any) {
36
- if (this._isGraylogEnabled) {
37
- gelf.error(message, data);
38
- } else {
39
- console.error(message, data);
40
- }
28
+ this._logger.error(message, data);
41
29
  }
42
30
 
43
31
  public async warn(message: string, data?: any) {
44
- if (this._isGraylogEnabled) {
45
- gelf.warn(message, data);
46
- } else {
47
- console.warn(message, data);
48
- }
32
+ this._logger.warn(message, data);
49
33
  }
50
34
 
51
35
  public async debug(message: string, data?: any) {
52
- if (this._isGraylogEnabled) {
53
- gelf.debug(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);
36
+ this._logger.debug(message, data);
64
37
  }
65
38
  //#endregion
66
39
  }
@@ -1,14 +1,11 @@
1
- import gelf from 'gelf-pro';
1
+ const gelf = require('gelf-pro');
2
2
 
3
3
  export class Logger {
4
4
  //#region Private Members
5
5
  private _isGraylog: boolean;
6
- private _host: string;
7
- private _port: number;
8
- private _hostname: string;
9
- private _facility: string;
10
6
  //#endregion
11
7
 
8
+ //#region Constructor
12
9
  constructor(host: string, port: number, hostname: string, facility: string, isGraylog: boolean = false) {
13
10
  this._isGraylog = isGraylog;
14
11
 
@@ -23,4 +20,39 @@ export class Logger {
23
20
  });
24
21
  }
25
22
  }
23
+ //#endregion
24
+
25
+ //#region Public API
26
+ public async info(message: string, data?: any) {
27
+ if (this._isGraylog) {
28
+ gelf.info(message, data);
29
+ } else {
30
+ console.info(message, data);
31
+ }
32
+ }
33
+
34
+ public async error(message: string, data?: any) {
35
+ if (this._isGraylog) {
36
+ gelf.error(message, data);
37
+ } else {
38
+ console.error(message, data);
39
+ }
40
+ }
41
+
42
+ public async warn(message: string, data?: any) {
43
+ if (this._isGraylog) {
44
+ gelf.warn(message, data);
45
+ } else {
46
+ console.warn(message, data);
47
+ }
48
+ }
49
+
50
+ public async debug(message: string, data?: any) {
51
+ if (this._isGraylog) {
52
+ gelf.debug(message, data);
53
+ } else {
54
+ console.debug(message, data);
55
+ }
56
+ }
57
+ //#endregion
26
58
  }