@mhmdhammoud/meritt-utils 1.2.0 → 1.3.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/ReleaseNotes.md CHANGED
@@ -1,8 +1,18 @@
1
1
  # Changes
2
2
 
3
- ## Version 1.0.5
3
+ ## Version 1.3.0
4
+
5
+ - Added toUpperTitle method that accepts a string and removes all non alphanumeric characters and capitalizes each letter of every first word
4
6
 
5
- ### Added
7
+ ```typescript
8
+ import {Logger} from '@mhmdhammoud/meritt-utils'
9
+
10
+ // Usage Example
11
+ Logger.info('className', ' functionName', 'logMessage', 'userIp')
12
+ // Available levels info warn error
13
+ ```
14
+
15
+ ## Version 1.0.5
6
16
 
7
17
  - Added toUpperTitle method that accepts a string and removes all non alphanumeric characters and capitalizes each letter of every first word
8
18
 
@@ -19,8 +29,6 @@ console : Hello World 99
19
29
 
20
30
  ## Version 1.0.4
21
31
 
22
- ### Added
23
-
24
32
  - Added generateKeys method that returns public and private keys
25
33
 
26
34
  ```typescript
@@ -38,14 +46,10 @@ console.log(response)
38
46
 
39
47
  ```
40
48
 
41
- ### Fixes and Improvements
42
-
43
49
  - Checking for prime numbers discarding even and odd numbers and skips 6 iterations at a time until radical I
44
50
 
45
51
  ## Version 1.0.3
46
52
 
47
- ### Added
48
-
49
53
  - Added Formatter class for manipulating strings
50
54
 
51
55
  ```typescript
@@ -55,8 +59,6 @@ import {Formatter} from '@mhmdhammoud/meritt-utils'
55
59
  const slug = Formatter.slugify('My Product Name') // my-product-name
56
60
  ```
57
61
 
58
- ### Fixes and Improvements
59
-
60
62
  - Fixed bug in Crypto class where encrypting a string with a key that is not a number would throw an error
61
63
  - Improved Crypto class to allow encrypting and decrypting numbers and objects
62
64
  - Documented Crypto class
@@ -0,0 +1 @@
1
+ export { default as WinstonConfiguaration } from './logger-config';
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.WinstonConfiguaration = void 0;
7
+ var logger_config_1 = require("./logger-config");
8
+ Object.defineProperty(exports, "WinstonConfiguaration", { enumerable: true, get: function () { return __importDefault(logger_config_1).default; } });
@@ -0,0 +1,5 @@
1
+ import { ElasticsearchTransport } from 'winston-elasticsearch';
2
+ declare const loggerConfiguration: {
3
+ transports: ElasticsearchTransport[];
4
+ };
5
+ export default loggerConfiguration;
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ const winston_elasticsearch_1 = require("winston-elasticsearch");
27
+ const dotenv = __importStar(require("dotenv"));
28
+ dotenv.config();
29
+ const { ELASTICSEARCH_USERNAME, ELASTICSEARCH_PASSWORD, ELASTICSEARCH_NODE, SERVER_NICKNAME, LOG_LEVEL, } = process.env;
30
+ const transports = process.env.NODE_ENV !== 'local'
31
+ ? [
32
+ // Elasticsearch Transport for 'info' logs
33
+ new winston_elasticsearch_1.ElasticsearchTransport({
34
+ level: 'info',
35
+ indexPrefix: process.env.SERVER_NICKNAME,
36
+ clientOpts: {
37
+ node: ELASTICSEARCH_NODE,
38
+ tls: {
39
+ rejectUnauthorized: false, // Only for development, not recommended in production
40
+ },
41
+ auth: {
42
+ username: ELASTICSEARCH_USERNAME,
43
+ password: ELASTICSEARCH_PASSWORD,
44
+ },
45
+ },
46
+ // format: winston.format.combine(winston.format.json()), // Adjust as needed
47
+ }),
48
+ // Elasticsearch Transport for 'warn' logs
49
+ new winston_elasticsearch_1.ElasticsearchTransport({
50
+ level: LOG_LEVEL,
51
+ indexPrefix: SERVER_NICKNAME,
52
+ clientOpts: {
53
+ node: ELASTICSEARCH_NODE,
54
+ tls: {
55
+ rejectUnauthorized: false, // Only for development, not recommended in production
56
+ },
57
+ auth: {
58
+ username: ELASTICSEARCH_USERNAME,
59
+ password: ELASTICSEARCH_PASSWORD,
60
+ },
61
+ },
62
+ // format: winston.format.combine(winston.format.json()), // Adjust as needed
63
+ }),
64
+ // Elasticsearch Transport for 'error' logs
65
+ new winston_elasticsearch_1.ElasticsearchTransport({
66
+ level: 'error',
67
+ indexPrefix: process.env.SERVER_NICKNAME,
68
+ clientOpts: {
69
+ node: ELASTICSEARCH_NODE,
70
+ tls: {
71
+ rejectUnauthorized: false, // Only for development, not recommended in production
72
+ },
73
+ auth: {
74
+ username: ELASTICSEARCH_USERNAME,
75
+ password: ELASTICSEARCH_PASSWORD,
76
+ },
77
+ },
78
+ // format: winston.format.combine(winston.format.json()), // Adjust as needed
79
+ }),
80
+ // eslint-disable-next-line no-mixed-spaces-and-tabs
81
+ ]
82
+ : [];
83
+ const loggerConfiguration = {
84
+ transports,
85
+ };
86
+ exports.default = loggerConfiguration;
package/dist/index.d.ts CHANGED
@@ -1 +1 @@
1
- export { Crypto, Formatter, Colorful } from './lib';
1
+ export * from './lib';
package/dist/index.js CHANGED
@@ -1,7 +1,17 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
2
16
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Colorful = exports.Formatter = exports.Crypto = void 0;
4
- var lib_1 = require("./lib");
5
- Object.defineProperty(exports, "Crypto", { enumerable: true, get: function () { return lib_1.Crypto; } });
6
- Object.defineProperty(exports, "Formatter", { enumerable: true, get: function () { return lib_1.Formatter; } });
7
- Object.defineProperty(exports, "Colorful", { enumerable: true, get: function () { return lib_1.Colorful; } });
17
+ __exportStar(require("./lib"), exports);
@@ -3,3 +3,4 @@ export { default as Formatter } from './formatter';
3
3
  export { default as Pdf } from './formatter';
4
4
  export { default as Colorful } from './colorful';
5
5
  export { default as ImageFull } from './imagefull';
6
+ export { default as Logger } from './logger';
package/dist/lib/index.js CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.ImageFull = exports.Colorful = exports.Pdf = exports.Formatter = exports.Crypto = void 0;
6
+ exports.Logger = exports.ImageFull = exports.Colorful = exports.Pdf = exports.Formatter = exports.Crypto = void 0;
7
7
  var cypto_1 = require("./cypto");
8
8
  Object.defineProperty(exports, "Crypto", { enumerable: true, get: function () { return __importDefault(cypto_1).default; } });
9
9
  var formatter_1 = require("./formatter");
@@ -14,3 +14,5 @@ var colorful_1 = require("./colorful");
14
14
  Object.defineProperty(exports, "Colorful", { enumerable: true, get: function () { return __importDefault(colorful_1).default; } });
15
15
  var imagefull_1 = require("./imagefull");
16
16
  Object.defineProperty(exports, "ImageFull", { enumerable: true, get: function () { return __importDefault(imagefull_1).default; } });
17
+ var logger_1 = require("./logger");
18
+ Object.defineProperty(exports, "Logger", { enumerable: true, get: function () { return __importDefault(logger_1).default; } });
@@ -0,0 +1,43 @@
1
+ import { LoggerOptions } from 'winston';
2
+ /**
3
+ * Service for logging information, warnings, and errors using Winston.
4
+ */
5
+ declare class LoggerService {
6
+ private logger;
7
+ /**
8
+ * Creates an instance of LoggerService.
9
+ * @param config - The configuration options for Winston logger.
10
+ */
11
+ constructor(config: LoggerOptions);
12
+ /**
13
+ * Logs an informational message.
14
+ * @param className - The name of the class that generated the log.
15
+ * @param functionName - The name of the function that generated the log.
16
+ * @param logMessage - The log message text.
17
+ * @param userIp - The user's IP address associated with the log.
18
+ * @param data - Additional data associated with the log.
19
+ */
20
+ info(className: string, functionName: string, logMessage: string, userIp: string): void;
21
+ /**
22
+ * Logs a warning message.
23
+ * @param className - The name of the class that generated the log.
24
+ * @param functionName - The name of the function that generated the log.
25
+ * @param logMessage - The log message text.
26
+ * @param userIp - The user's IP address associated with the log.
27
+ * @param data - Additional data associated with the log.
28
+ */
29
+ warn(className: string, functionName: string, logMessage: string, userIp: string): void;
30
+ /**
31
+ * Logs an error message.
32
+ * @param className - The name of the class that generated the log.
33
+ * @param functionName - The name of the function that generated the log.
34
+ * @param logMessage - The log message text.
35
+ * @param userIp - The user's IP address associated with the log.
36
+ * @param data - Additional data associated with the log.
37
+ */
38
+ error(className: string, functionName: string, logMessage: string, userIp: string, data?: Object): void;
39
+ private createLogMessage;
40
+ private log;
41
+ }
42
+ declare const Logger: LoggerService;
43
+ export default Logger;
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const winston_1 = __importDefault(require("winston"));
7
+ const config_1 = require("../config");
8
+ /**
9
+ * Service for logging information, warnings, and errors using Winston.
10
+ */
11
+ class LoggerService {
12
+ /**
13
+ * Creates an instance of LoggerService.
14
+ * @param config - The configuration options for Winston logger.
15
+ */
16
+ constructor(config) {
17
+ this.logger = winston_1.default.createLogger({
18
+ ...config,
19
+ level: process.env.LOG_LEVEL,
20
+ });
21
+ if (process.env.NODE_ENV === 'local') {
22
+ this.logger.add(new winston_1.default.transports.Console({
23
+ level: 'info',
24
+ format: winston_1.default.format.combine(winston_1.default.format.simple(), winston_1.default.format.colorize(), winston_1.default.format.printf(({ level, message }) => {
25
+ return `[${level}]: ${JSON.stringify(message)}`;
26
+ // Parse the message as JSON and include in the log
27
+ })),
28
+ }));
29
+ }
30
+ this.logger.level = process.env.LOG_LEVEL;
31
+ }
32
+ /**
33
+ * Logs an informational message.
34
+ * @param className - The name of the class that generated the log.
35
+ * @param functionName - The name of the function that generated the log.
36
+ * @param logMessage - The log message text.
37
+ * @param userIp - The user's IP address associated with the log.
38
+ * @param data - Additional data associated with the log.
39
+ */
40
+ info(className, functionName, logMessage, userIp) {
41
+ const message = this.createLogMessage(className, functionName, logMessage, userIp);
42
+ this.log('info', message);
43
+ }
44
+ /**
45
+ * Logs a warning message.
46
+ * @param className - The name of the class that generated the log.
47
+ * @param functionName - The name of the function that generated the log.
48
+ * @param logMessage - The log message text.
49
+ * @param userIp - The user's IP address associated with the log.
50
+ * @param data - Additional data associated with the log.
51
+ */
52
+ warn(className, functionName, logMessage, userIp) {
53
+ const message = this.createLogMessage(className, functionName, logMessage, userIp);
54
+ this.log('warn', message);
55
+ }
56
+ /**
57
+ * Logs an error message.
58
+ * @param className - The name of the class that generated the log.
59
+ * @param functionName - The name of the function that generated the log.
60
+ * @param logMessage - The log message text.
61
+ * @param userIp - The user's IP address associated with the log.
62
+ * @param data - Additional data associated with the log.
63
+ */
64
+ error(className, functionName, logMessage, userIp, data = {}) {
65
+ const message = this.createLogMessage(className, functionName, logMessage, userIp, data);
66
+ this.log('error', message);
67
+ }
68
+ createLogMessage(className, functionName, logMessage, userIp, data = {}) {
69
+ return {
70
+ className,
71
+ functionName,
72
+ logMessage,
73
+ userIp,
74
+ data,
75
+ };
76
+ }
77
+ log(level, logMessage) {
78
+ this.logger.log({
79
+ level,
80
+ //@ts-ignore
81
+ message: logMessage,
82
+ });
83
+ process.on('unhandledRejection', (reason, promise) => {
84
+ this.logger.error('Unhandled Rejection at:', promise, 'reason:', reason);
85
+ });
86
+ process.on('uncaughtException', (err) => {
87
+ this.logger.error('Uncaught Exception:', err);
88
+ });
89
+ }
90
+ }
91
+ const Logger = new LoggerService(config_1.WinstonConfiguaration);
92
+ exports.default = Logger;
package/example.env ADDED
@@ -0,0 +1,6 @@
1
+ ELASTICSEARCH_USERNAME=
2
+ ELASTICSEARCH_PASSWORD=
3
+ ELASTICSEARCH_NODE=
4
+ SERVER_NICKNAME=
5
+ NODE_ENV=
6
+ LOG_LEVEL=info
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mhmdhammoud/meritt-utils",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "private": false,
@@ -40,6 +40,9 @@
40
40
  "license": "ISC",
41
41
  "dependencies": {
42
42
  "axios": "^1.4.0",
43
- "imagesloaded": "^5.0.0"
43
+ "dotenv": "^16.4.1",
44
+ "imagesloaded": "^5.0.0",
45
+ "winston": "^3.11.0",
46
+ "winston-elasticsearch": "^0.17.4"
44
47
  }
45
48
  }
@@ -0,0 +1 @@
1
+ export {default as WinstonConfiguaration} from './logger-config'
@@ -0,0 +1,73 @@
1
+ import {ElasticsearchTransport} from 'winston-elasticsearch'
2
+ import * as dotenv from 'dotenv'
3
+ dotenv.config()
4
+ const {
5
+ ELASTICSEARCH_USERNAME,
6
+ ELASTICSEARCH_PASSWORD,
7
+ ELASTICSEARCH_NODE,
8
+ SERVER_NICKNAME,
9
+ LOG_LEVEL,
10
+ } = process.env
11
+
12
+ const transports =
13
+ process.env.NODE_ENV !== 'local'
14
+ ? [
15
+ // Elasticsearch Transport for 'info' logs
16
+ new ElasticsearchTransport({
17
+ level: 'info',
18
+ indexPrefix: process.env.SERVER_NICKNAME, // Index prefix for Elasticsearch
19
+ clientOpts: {
20
+ node: ELASTICSEARCH_NODE,
21
+ tls: {
22
+ rejectUnauthorized: false, // Only for development, not recommended in production
23
+ },
24
+ auth: {
25
+ username: ELASTICSEARCH_USERNAME,
26
+ password: ELASTICSEARCH_PASSWORD,
27
+ },
28
+ },
29
+ // format: winston.format.combine(winston.format.json()), // Adjust as needed
30
+ }),
31
+
32
+ // Elasticsearch Transport for 'warn' logs
33
+ new ElasticsearchTransport({
34
+ level: LOG_LEVEL,
35
+ indexPrefix: SERVER_NICKNAME, // Index prefix for Elasticsearch
36
+ clientOpts: {
37
+ node: ELASTICSEARCH_NODE,
38
+ tls: {
39
+ rejectUnauthorized: false, // Only for development, not recommended in production
40
+ },
41
+ auth: {
42
+ username: ELASTICSEARCH_USERNAME,
43
+ password: ELASTICSEARCH_PASSWORD,
44
+ },
45
+ },
46
+ // format: winston.format.combine(winston.format.json()), // Adjust as needed
47
+ }),
48
+
49
+ // Elasticsearch Transport for 'error' logs
50
+ new ElasticsearchTransport({
51
+ level: 'error',
52
+ indexPrefix: process.env.SERVER_NICKNAME, // Index prefix for Elasticsearch
53
+ clientOpts: {
54
+ node: ELASTICSEARCH_NODE,
55
+ tls: {
56
+ rejectUnauthorized: false, // Only for development, not recommended in production
57
+ },
58
+ auth: {
59
+ username: ELASTICSEARCH_USERNAME,
60
+ password: ELASTICSEARCH_PASSWORD,
61
+ },
62
+ },
63
+ // format: winston.format.combine(winston.format.json()), // Adjust as needed
64
+ }),
65
+ // eslint-disable-next-line no-mixed-spaces-and-tabs
66
+ ]
67
+ : []
68
+
69
+ const loggerConfiguration = {
70
+ transports,
71
+ }
72
+
73
+ export default loggerConfiguration
package/src/env.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ declare namespace NodeJS {
2
+ export interface ProcessEnv {
3
+ NODE_ENV: 'development' | 'production' | 'test' | 'local'
4
+ ELASTICSEARCH_NODE: string
5
+ ELASTICSEARCH_USERNAME: string
6
+ ELASTICSEARCH_PASSWORD: string
7
+ LOG_LEVEL: string
8
+ }
9
+ }
package/src/index.ts CHANGED
@@ -1 +1 @@
1
- export {Crypto, Formatter, Colorful} from './lib'
1
+ export * from './lib'
package/src/lib/index.ts CHANGED
@@ -3,3 +3,4 @@ export {default as Formatter} from './formatter'
3
3
  export {default as Pdf} from './formatter'
4
4
  export {default as Colorful} from './colorful'
5
5
  export {default as ImageFull} from './imagefull'
6
+ export {default as Logger} from './logger'
@@ -0,0 +1,172 @@
1
+ import Winston, {Logger as WinstonLogger, LoggerOptions} from 'winston'
2
+ import {WinstonConfiguaration} from '../config'
3
+
4
+ /**
5
+ * Represents a log message with structured information.
6
+ */
7
+ interface LogMessage {
8
+ /**
9
+ * The name of the class that generated the log.
10
+ */
11
+ className: string
12
+
13
+ /**
14
+ * The name of the function that generated the log.
15
+ */
16
+ functionName: string
17
+
18
+ /**
19
+ * The log message text.
20
+ */
21
+ logMessage: string
22
+
23
+ /**
24
+ * The user's IP address associated with the log.
25
+ */
26
+ userIp: string
27
+
28
+ /**
29
+ * Additional data associated with the log.
30
+ */
31
+ data?: Record<string, any>
32
+ }
33
+
34
+ /**
35
+ * Service for logging information, warnings, and errors using Winston.
36
+ */
37
+ class LoggerService {
38
+ private logger: WinstonLogger
39
+
40
+ /**
41
+ * Creates an instance of LoggerService.
42
+ * @param config - The configuration options for Winston logger.
43
+ */
44
+ constructor(config: LoggerOptions) {
45
+ this.logger = Winston.createLogger({
46
+ ...config,
47
+ level: process.env.LOG_LEVEL,
48
+ })
49
+ if (process.env.NODE_ENV === 'local') {
50
+ this.logger.add(
51
+ new Winston.transports.Console({
52
+ level: 'info',
53
+ format: Winston.format.combine(
54
+ Winston.format.simple(),
55
+ Winston.format.colorize(),
56
+ Winston.format.printf(({level, message}) => {
57
+ return `[${level}]: ${JSON.stringify(message)}`
58
+ // Parse the message as JSON and include in the log
59
+ })
60
+ ),
61
+ })
62
+ )
63
+ }
64
+
65
+ this.logger.level = process.env.LOG_LEVEL
66
+ }
67
+
68
+ /**
69
+ * Logs an informational message.
70
+ * @param className - The name of the class that generated the log.
71
+ * @param functionName - The name of the function that generated the log.
72
+ * @param logMessage - The log message text.
73
+ * @param userIp - The user's IP address associated with the log.
74
+ * @param data - Additional data associated with the log.
75
+ */
76
+ info(
77
+ className: string,
78
+ functionName: string,
79
+ logMessage: string,
80
+ userIp: string
81
+ ): void {
82
+ const message = this.createLogMessage(
83
+ className,
84
+ functionName,
85
+ logMessage,
86
+ userIp
87
+ )
88
+ this.log('info', message)
89
+ }
90
+
91
+ /**
92
+ * Logs a warning message.
93
+ * @param className - The name of the class that generated the log.
94
+ * @param functionName - The name of the function that generated the log.
95
+ * @param logMessage - The log message text.
96
+ * @param userIp - The user's IP address associated with the log.
97
+ * @param data - Additional data associated with the log.
98
+ */
99
+ warn(
100
+ className: string,
101
+ functionName: string,
102
+ logMessage: string,
103
+ userIp: string
104
+ ): void {
105
+ const message = this.createLogMessage(
106
+ className,
107
+ functionName,
108
+ logMessage,
109
+ userIp
110
+ )
111
+ this.log('warn', message)
112
+ }
113
+
114
+ /**
115
+ * Logs an error message.
116
+ * @param className - The name of the class that generated the log.
117
+ * @param functionName - The name of the function that generated the log.
118
+ * @param logMessage - The log message text.
119
+ * @param userIp - The user's IP address associated with the log.
120
+ * @param data - Additional data associated with the log.
121
+ */
122
+ error(
123
+ className: string,
124
+ functionName: string,
125
+ logMessage: string,
126
+ userIp: string,
127
+ data: Object = {}
128
+ ): void {
129
+ const message = this.createLogMessage(
130
+ className,
131
+ functionName,
132
+ logMessage,
133
+ userIp,
134
+ data
135
+ )
136
+ this.log('error', message)
137
+ }
138
+
139
+ private createLogMessage(
140
+ className: string,
141
+ functionName: string,
142
+ logMessage: string,
143
+ userIp: string,
144
+ data: Record<string, any> = {}
145
+ ): LogMessage {
146
+ return {
147
+ className,
148
+ functionName,
149
+ logMessage,
150
+ userIp,
151
+ data,
152
+ }
153
+ }
154
+
155
+ private log(level: string, logMessage: LogMessage): void {
156
+ this.logger.log({
157
+ level,
158
+ //@ts-ignore
159
+ message: logMessage,
160
+ })
161
+ process.on('unhandledRejection', (reason, promise) => {
162
+ this.logger.error('Unhandled Rejection at:', promise, 'reason:', reason)
163
+ })
164
+
165
+ process.on('uncaughtException', (err) => {
166
+ this.logger.error('Uncaught Exception:', err)
167
+ })
168
+ }
169
+ }
170
+
171
+ const Logger = new LoggerService(WinstonConfiguaration)
172
+ export default Logger