@nicollasfrazao/liguelead-log-service 1.0.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.
Files changed (67) hide show
  1. package/LICENSE +15 -0
  2. package/README.md +689 -0
  3. package/dist/configs/log.service.config.d.ts +8 -0
  4. package/dist/configs/log.service.config.d.ts.map +1 -0
  5. package/dist/configs/log.service.config.js +50 -0
  6. package/dist/configs/log.service.config.js.map +1 -0
  7. package/dist/configs/log.storage.external.s3.config.d.ts +8 -0
  8. package/dist/configs/log.storage.external.s3.config.d.ts.map +1 -0
  9. package/dist/configs/log.storage.external.s3.config.js +27 -0
  10. package/dist/configs/log.storage.external.s3.config.js.map +1 -0
  11. package/dist/errors/log.error.d.ts +25 -0
  12. package/dist/errors/log.error.d.ts.map +1 -0
  13. package/dist/errors/log.error.js +27 -0
  14. package/dist/errors/log.error.js.map +1 -0
  15. package/dist/index.d.ts +22 -0
  16. package/dist/index.d.ts.map +1 -0
  17. package/dist/index.js +35 -0
  18. package/dist/index.js.map +1 -0
  19. package/dist/interfaces/log.service.config.interface.d.ts +84 -0
  20. package/dist/interfaces/log.service.config.interface.d.ts.map +1 -0
  21. package/dist/interfaces/log.service.config.interface.js +3 -0
  22. package/dist/interfaces/log.service.config.interface.js.map +1 -0
  23. package/dist/interfaces/log.storage.base.service.interface.d.ts +21 -0
  24. package/dist/interfaces/log.storage.base.service.interface.d.ts.map +1 -0
  25. package/dist/interfaces/log.storage.base.service.interface.js +3 -0
  26. package/dist/interfaces/log.storage.base.service.interface.js.map +1 -0
  27. package/dist/interfaces/log.storage.external.s3.service.config.interface.d.ts +39 -0
  28. package/dist/interfaces/log.storage.external.s3.service.config.interface.d.ts.map +1 -0
  29. package/dist/interfaces/log.storage.external.s3.service.config.interface.js +3 -0
  30. package/dist/interfaces/log.storage.external.s3.service.config.interface.js.map +1 -0
  31. package/dist/middlewares/log.middleware.d.ts +12 -0
  32. package/dist/middlewares/log.middleware.d.ts.map +1 -0
  33. package/dist/middlewares/log.middleware.js +63 -0
  34. package/dist/middlewares/log.middleware.js.map +1 -0
  35. package/dist/services/log.service.d.ts +224 -0
  36. package/dist/services/log.service.d.ts.map +1 -0
  37. package/dist/services/log.service.js +572 -0
  38. package/dist/services/log.service.js.map +1 -0
  39. package/dist/services/log.storage.base.service.d.ts +77 -0
  40. package/dist/services/log.storage.base.service.d.ts.map +1 -0
  41. package/dist/services/log.storage.base.service.js +107 -0
  42. package/dist/services/log.storage.base.service.js.map +1 -0
  43. package/dist/services/log.storage.external.s3.service.d.ts +66 -0
  44. package/dist/services/log.storage.external.s3.service.d.ts.map +1 -0
  45. package/dist/services/log.storage.external.s3.service.js +121 -0
  46. package/dist/services/log.storage.external.s3.service.js.map +1 -0
  47. package/dist/services/log.storage.external.service.d.ts +17 -0
  48. package/dist/services/log.storage.external.service.d.ts.map +1 -0
  49. package/dist/services/log.storage.external.service.js +22 -0
  50. package/dist/services/log.storage.external.service.js.map +1 -0
  51. package/dist/services/log.storage.local.service.d.ts +38 -0
  52. package/dist/services/log.storage.local.service.d.ts.map +1 -0
  53. package/dist/services/log.storage.local.service.js +96 -0
  54. package/dist/services/log.storage.local.service.js.map +1 -0
  55. package/dist/services/log.storage.service.d.ts +62 -0
  56. package/dist/services/log.storage.service.d.ts.map +1 -0
  57. package/dist/services/log.storage.service.js +92 -0
  58. package/dist/services/log.storage.service.js.map +1 -0
  59. package/dist/types/log.context.type.d.ts +74 -0
  60. package/dist/types/log.context.type.d.ts.map +1 -0
  61. package/dist/types/log.context.type.js +3 -0
  62. package/dist/types/log.context.type.js.map +1 -0
  63. package/dist/types/log.type.d.ts +45 -0
  64. package/dist/types/log.type.d.ts.map +1 -0
  65. package/dist/types/log.type.js +3 -0
  66. package/dist/types/log.type.js.map +1 -0
  67. package/package.json +64 -0
@@ -0,0 +1,224 @@
1
+ import { Request, Response } from "express";
2
+ import { LogType } from "../types/log.type";
3
+ import { LogContextType } from "../types/log.context.type";
4
+ /**
5
+ * Class LogService
6
+ *
7
+ * Responsible for logging messages with different severity levels
8
+ *
9
+ * @property {LogServiceConfigInterface} config
10
+ * @property {LogStorageService} logStorageService
11
+ * @property {string} correlationId
12
+ * @property {Promise<void>} writeQueue
13
+ */
14
+ export declare class LogService {
15
+ /**
16
+ * @var {LogServiceConfigInterface}
17
+ */
18
+ private static config;
19
+ /**
20
+ * @var {string}
21
+ */
22
+ private static correlationId;
23
+ /**
24
+ * @var {LogStorageService|null}
25
+ */
26
+ private static logStorageService;
27
+ /**
28
+ * @var {Promise<void>}
29
+ */
30
+ private static writeQueue;
31
+ /**
32
+ * Sets the correlation ID for log entries
33
+ *
34
+ * @param {string} correlationId
35
+ *
36
+ * @returns {void}
37
+ */
38
+ static setCorrelationId(correlationId?: string): void;
39
+ /**
40
+ * Gets the current correlation ID
41
+ *
42
+ * @returns {string} The current correlation ID
43
+ */
44
+ static getCorrelationId(): string;
45
+ /**
46
+ * Determines if a log message should be logged based on its level
47
+ *
48
+ * @param {LogType['level']} level The level of the log message
49
+ *
50
+ * @returns {boolean} True if the message should be logged, false otherwise
51
+ */
52
+ private static shouldLog;
53
+ /**
54
+ * Formats the log data into a string
55
+ *
56
+ * @param {LogType} data The log data to format
57
+ *
58
+ * @returns {string} The formatted log string
59
+ */
60
+ static formatLog(data: LogType): string;
61
+ /**
62
+ * Gets the current timestamp
63
+ *
64
+ * @returns {string} The current timestamp
65
+ */
66
+ private static getTimestamp;
67
+ /**
68
+ * Colorizes the log text based on the log level
69
+ *
70
+ * @param {LogType['level']} data The log level
71
+ *
72
+ * @returns {string} The colorized log text
73
+ */
74
+ private static colorizeLogOutput;
75
+ /**
76
+ * Creates a log entry
77
+ *
78
+ * @param {LogType['level']} level The log level
79
+ * @param {string} message The log message
80
+ * @param {LogContextType} context The log context
81
+ *
82
+ * @returns {LogType} The created log entry
83
+ */
84
+ private static createLogEntry;
85
+ /**
86
+ * Logs an informational message
87
+ *
88
+ * @param {string} message The log message
89
+ * @param {LogContextType} context The log context
90
+ *
91
+ * @returns {void}
92
+ */
93
+ static info(message: string, context?: LogContextType): void;
94
+ /**
95
+ * Logs a warning message
96
+ *
97
+ * @param {string} message The warning message
98
+ * @param {LogContextType} context The log context
99
+ *
100
+ * @returns {void}
101
+ */
102
+ static warn(message: string, context?: LogContextType): void;
103
+ /**
104
+ * Logs an error message
105
+ *
106
+ * @param {string} message The error message
107
+ * @param {LogContextType} context The log context
108
+ *
109
+ * @returns {void}
110
+ */
111
+ static error(message: string, context?: LogContextType): void;
112
+ /**
113
+ * Logs a debug message
114
+ *
115
+ * @param {string} message The debug message
116
+ * @param {LogContextType} context The log context
117
+ *
118
+ * @returns {void}
119
+ */
120
+ static debug(message: string, context: LogContextType): void;
121
+ /**
122
+ * Function to sanitize sensitive data
123
+ *
124
+ * @param {any} body
125
+ *
126
+ * @returns {any}
127
+ */
128
+ static sanitizeBody(body: any): any;
129
+ /**
130
+ * Get the client IP address from the request
131
+ *
132
+ * @param {Request} request The Express request object
133
+ *
134
+ * @returns {string} The client IP address
135
+ */
136
+ static getClientIp(request?: Request): string;
137
+ /**
138
+ * Writes log data to the configured destinations (console, storage, or both)
139
+ *
140
+ * @param {LogType} data The log data to write
141
+ *
142
+ * @returns {void}
143
+ */
144
+ private static writeLog;
145
+ /**
146
+ * Initializes the LoggingStorageService if not already initialized
147
+ *
148
+ * @returns {void}
149
+ */
150
+ private static initializeLogStorageService;
151
+ /**
152
+ * Writes log data to the appropriate storage (file or S3)
153
+ *
154
+ * @param {LogType} data The log data to write
155
+ *
156
+ * @returns {Promise<void>}
157
+ */
158
+ private static writeToStorage;
159
+ /**
160
+ * Writes log data to the console with appropriate color coding
161
+ *
162
+ * @param {LogType} data The log data to write
163
+ *
164
+ * @returns {void}
165
+ */
166
+ private static writeToConsole;
167
+ /**
168
+ * Helper method to execute request calls with logging
169
+ *
170
+ * @param {() => Promise<any>} requestCall - The request call function
171
+ * @param {string} requestMethod - The HTTP method (GET, POST, etc.)
172
+ * @param {string} requestUrl - The request endpoint URL
173
+ * @param {string} requestName - The name of the external request for logging purposes
174
+ * @param {any} requestBody - The request body (if applicable)
175
+ * @param {Request} requestOrigin - The original Express request
176
+ *
177
+ * @returns {Promise<T>} - The request response
178
+ */
179
+ static executeRequestWithLogging<T>(requestCall: () => Promise<any>, requestMethod: string, requestUrl: string, requestName?: string, requestBody?: any, requestOrigin?: Request): Promise<T>;
180
+ /**
181
+ * Logs an external request call
182
+ *
183
+ * @param {string} requestMethod
184
+ * @param {string} requestUrl
185
+ * @param {string} requestName
186
+ * @param {Request} requestOrigin
187
+ * @param {any} requestBody
188
+ * @param {number} statusCode
189
+ * @param {number} duration
190
+ * @param {any} responseBody
191
+ * @param {Error} error
192
+ *
193
+ * @returns {void}
194
+ */
195
+ private static logExternalRequestCall;
196
+ /**
197
+ * Creates a log context from an Express request
198
+ *
199
+ * @param {Request} request The Express request
200
+ * @param {Partial<LogContextType>} additionalData Additional data to include in the context
201
+ *
202
+ * @returns {LogContextType} The created log context
203
+ */
204
+ static createContextFromRequest(request: Request, additionalData?: Partial<LogContextType>): LogContextType;
205
+ /**
206
+ * Creates a log context from an Express response
207
+ *
208
+ * @param {Request} request The Express request object
209
+ * @param {Response} response The Express response object
210
+ * @param {Partial<LogContextType>} additionalData Additional data to include in the context
211
+ *
212
+ * @returns {LogContextType} The created log context
213
+ */
214
+ static createContextFromResponse(request: Request, response: Response, additionalData?: Partial<LogContextType>): LogContextType;
215
+ /**
216
+ * Creates a log context from arbitrary data
217
+ *
218
+ * @param {Partial<LogContextType>} data The data to create the context from
219
+ *
220
+ * @returns {LogContextType} The created log context
221
+ */
222
+ static createContextFromData(data?: Partial<LogContextType>): LogContextType;
223
+ }
224
+ //# sourceMappingURL=log.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"log.service.d.ts","sourceRoot":"","sources":["../../src/services/log.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAK5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