@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.
- package/LICENSE +15 -0
- package/README.md +689 -0
- package/dist/configs/log.service.config.d.ts +8 -0
- package/dist/configs/log.service.config.d.ts.map +1 -0
- package/dist/configs/log.service.config.js +50 -0
- package/dist/configs/log.service.config.js.map +1 -0
- package/dist/configs/log.storage.external.s3.config.d.ts +8 -0
- package/dist/configs/log.storage.external.s3.config.d.ts.map +1 -0
- package/dist/configs/log.storage.external.s3.config.js +27 -0
- package/dist/configs/log.storage.external.s3.config.js.map +1 -0
- package/dist/errors/log.error.d.ts +25 -0
- package/dist/errors/log.error.d.ts.map +1 -0
- package/dist/errors/log.error.js +27 -0
- package/dist/errors/log.error.js.map +1 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +35 -0
- package/dist/index.js.map +1 -0
- package/dist/interfaces/log.service.config.interface.d.ts +84 -0
- package/dist/interfaces/log.service.config.interface.d.ts.map +1 -0
- package/dist/interfaces/log.service.config.interface.js +3 -0
- package/dist/interfaces/log.service.config.interface.js.map +1 -0
- package/dist/interfaces/log.storage.base.service.interface.d.ts +21 -0
- package/dist/interfaces/log.storage.base.service.interface.d.ts.map +1 -0
- package/dist/interfaces/log.storage.base.service.interface.js +3 -0
- package/dist/interfaces/log.storage.base.service.interface.js.map +1 -0
- package/dist/interfaces/log.storage.external.s3.service.config.interface.d.ts +39 -0
- package/dist/interfaces/log.storage.external.s3.service.config.interface.d.ts.map +1 -0
- package/dist/interfaces/log.storage.external.s3.service.config.interface.js +3 -0
- package/dist/interfaces/log.storage.external.s3.service.config.interface.js.map +1 -0
- package/dist/middlewares/log.middleware.d.ts +12 -0
- package/dist/middlewares/log.middleware.d.ts.map +1 -0
- package/dist/middlewares/log.middleware.js +63 -0
- package/dist/middlewares/log.middleware.js.map +1 -0
- package/dist/services/log.service.d.ts +224 -0
- package/dist/services/log.service.d.ts.map +1 -0
- package/dist/services/log.service.js +572 -0
- package/dist/services/log.service.js.map +1 -0
- package/dist/services/log.storage.base.service.d.ts +77 -0
- package/dist/services/log.storage.base.service.d.ts.map +1 -0
- package/dist/services/log.storage.base.service.js +107 -0
- package/dist/services/log.storage.base.service.js.map +1 -0
- package/dist/services/log.storage.external.s3.service.d.ts +66 -0
- package/dist/services/log.storage.external.s3.service.d.ts.map +1 -0
- package/dist/services/log.storage.external.s3.service.js +121 -0
- package/dist/services/log.storage.external.s3.service.js.map +1 -0
- package/dist/services/log.storage.external.service.d.ts +17 -0
- package/dist/services/log.storage.external.service.d.ts.map +1 -0
- package/dist/services/log.storage.external.service.js +22 -0
- package/dist/services/log.storage.external.service.js.map +1 -0
- package/dist/services/log.storage.local.service.d.ts +38 -0
- package/dist/services/log.storage.local.service.d.ts.map +1 -0
- package/dist/services/log.storage.local.service.js +96 -0
- package/dist/services/log.storage.local.service.js.map +1 -0
- package/dist/services/log.storage.service.d.ts +62 -0
- package/dist/services/log.storage.service.d.ts.map +1 -0
- package/dist/services/log.storage.service.js +92 -0
- package/dist/services/log.storage.service.js.map +1 -0
- package/dist/types/log.context.type.d.ts +74 -0
- package/dist/types/log.context.type.d.ts.map +1 -0
- package/dist/types/log.context.type.js +3 -0
- package/dist/types/log.context.type.js.map +1 -0
- package/dist/types/log.type.d.ts +45 -0
- package/dist/types/log.type.d.ts.map +1 -0
- package/dist/types/log.type.js +3 -0
- package/dist/types/log.type.js.map +1 -0
- package/package.json +64 -0
|
@@ -0,0 +1,107 @@
|
|
|
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 () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.LogStorageBaseService = void 0;
|
|
37
|
+
const path = __importStar(require("path"));
|
|
38
|
+
/**
|
|
39
|
+
* Abstract Class LogStorageBaseService
|
|
40
|
+
*
|
|
41
|
+
* Base class for logging storage target services (e.g., local file system, S3)
|
|
42
|
+
*
|
|
43
|
+
* @property {LogServiceConfigInterface} logServiceConfig
|
|
44
|
+
* @property {string} baseLogsDirectory
|
|
45
|
+
*/
|
|
46
|
+
class LogStorageBaseService {
|
|
47
|
+
/**
|
|
48
|
+
* Constructor of the LogStorageTargetService
|
|
49
|
+
*
|
|
50
|
+
* @param logServiceConfig - Configuration for the logging service
|
|
51
|
+
* @param baseLogsDirectory - Base directory for storing logs
|
|
52
|
+
*/
|
|
53
|
+
constructor(logServiceConfig, baseLogsDirectory) {
|
|
54
|
+
this.logServiceConfig = logServiceConfig;
|
|
55
|
+
this.baseLogsDirectory = baseLogsDirectory;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Gets the logs directory for the current environment
|
|
59
|
+
*
|
|
60
|
+
* @returns {string} The environment-specific logs directory
|
|
61
|
+
*/
|
|
62
|
+
getLogsDirectory() {
|
|
63
|
+
return path.join(this.baseLogsDirectory, this.logServiceConfig.environment);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Gets the combined log file name for the current date
|
|
67
|
+
*
|
|
68
|
+
* @returns {string} The combined log file name
|
|
69
|
+
*/
|
|
70
|
+
getCombinedLogFileName() {
|
|
71
|
+
const today = new Date();
|
|
72
|
+
const dateString = today.toISOString().split('T')[0];
|
|
73
|
+
return `${dateString}-combined.log`;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Gets the combined log file path
|
|
77
|
+
*
|
|
78
|
+
* @returns {string} The combined log file path
|
|
79
|
+
*/
|
|
80
|
+
getCombinedLogFilePath() {
|
|
81
|
+
return path.join(this.getLogsDirectory(), this.getCombinedLogFileName());
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Gets the log file name for the date and level
|
|
85
|
+
*
|
|
86
|
+
* @param {LogType['level']} level The log level
|
|
87
|
+
*
|
|
88
|
+
* @returns {string} The log file name
|
|
89
|
+
*/
|
|
90
|
+
getLevelLogFileName(level) {
|
|
91
|
+
const today = new Date();
|
|
92
|
+
const dateString = today.toISOString().split('T')[0];
|
|
93
|
+
return `${dateString}-${level}.log`;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Gets the log file name for the date and level
|
|
97
|
+
*
|
|
98
|
+
* @param {LogType['level']} level The log level
|
|
99
|
+
*
|
|
100
|
+
* @returns {string} The log file path
|
|
101
|
+
*/
|
|
102
|
+
getLevelLogFilePath(level) {
|
|
103
|
+
return path.join(this.getLogsDirectory(), this.getLevelLogFileName(level));
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
exports.LogStorageBaseService = LogStorageBaseService;
|
|
107
|
+
//# sourceMappingURL=log.storage.base.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log.storage.base.service.js","sourceRoot":"","sources":["../../src/services/log.storage.base.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAA6B;AAK7B;;;;;;;GAOG;AACH,MAAsB,qBAAqB;IAYzC;;;;;OAKG;IACH,YACE,gBAA2C,EAC3C,iBAAyB;QAEzB,IAAI,CAAC,gBAAgB,GAAG,gBAAgB,CAAC;QACzC,IAAI,CAAC,iBAAiB,GAAG,iBAAiB,CAAC;IAC7C,CAAC;IAED;;;;OAIG;IACO,gBAAgB;QAExB,OAAO,IAAI,CAAC,IAAI,CACd,IAAI,CAAC,iBAAiB,EACtB,IAAI,CAAC,gBAAgB,CAAC,WAAW,CAClC,CAAC;IACJ,CAAC;IAED;;;;OAIG;IACK,sBAAsB;QAE5B,MAAM,KAAK,GAAG,IAAI,IAAI,EAAE,CAAC;QACzB,MAAM,UAAU,GAAG,KAAK,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QAErD,OAAO,GAAG,UAAU,eAAe,CAAC;IACtC,CAAC;IAED;;;;OAIG;IACO,sBAAsB;QAE9B,OAAO,IAAI,CAAC,IAAI,CACd,IAAI,CAAC,gBAAgB,EAAE,EACvB,IAAI,CAAC,sBAAsB,EAAE,CAC9B,CAAC;IACJ,CAAC;IAED;;;;;;OAMG;IACK,mBAAmB,CAAC,KAAuB;QAEjD,MAAM,KAAK,GAAG,IAAI,IAAI,EAAE,CAAC;QACzB,MAAM,UAAU,GAAG,KAAK,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QAErD,OAAO,GAAG,UAAU,IAAI,KAAK,MAAM,CAAC;IACtC,CAAC;IAED;;;;;;OAMG;IACO,mBAAmB,CAAC,KAAuB;QAEnD,OAAO,IAAI,CAAC,IAAI,CACd,IAAI,CAAC,gBAAgB,EAAE,EACvB,IAAI,CAAC,mBAAmB,CAAC,KAAK,CAAC,CAChC,CAAC;IACJ,CAAC;CAiBF;AA9GD,sDA8GC"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { LogStorageExternalService } from './log.storage.external.service';
|
|
2
|
+
import { LogServiceConfigInterface } from '../interfaces/log.service.config.interface';
|
|
3
|
+
import { LogType } from '../types/log.type';
|
|
4
|
+
/**
|
|
5
|
+
* Class LogStorageExternalS3Service
|
|
6
|
+
*
|
|
7
|
+
* Responsible for uploading logs to S3 bucket via Kinesis Firehose
|
|
8
|
+
*
|
|
9
|
+
* @property {FirehoseClient} firehose
|
|
10
|
+
* @property {LogStorageExternalS3ServiceConfigInterface} config
|
|
11
|
+
* @property {Map<string, Promise<void>>} writeQueue
|
|
12
|
+
*/
|
|
13
|
+
export declare class LogStorageExternalS3Service extends LogStorageExternalService {
|
|
14
|
+
/**
|
|
15
|
+
* @var {FirehoseClient}
|
|
16
|
+
*/
|
|
17
|
+
private firehose;
|
|
18
|
+
/**
|
|
19
|
+
* @var {LogStorageExternalS3ServiceConfigInterface}
|
|
20
|
+
*/
|
|
21
|
+
private config;
|
|
22
|
+
/**
|
|
23
|
+
* @var {Map<string, Promise<void>>}
|
|
24
|
+
*/
|
|
25
|
+
private writeQueue;
|
|
26
|
+
/**
|
|
27
|
+
* Constructor of the LogStorageS3Service
|
|
28
|
+
*
|
|
29
|
+
* @param {LogServiceConfigInterface} logServiceConfig - Configuration for the logging service
|
|
30
|
+
*/
|
|
31
|
+
constructor(logServiceConfig: LogServiceConfigInterface);
|
|
32
|
+
/**
|
|
33
|
+
* Determines if the S3 storage should be used
|
|
34
|
+
*
|
|
35
|
+
* @returns {boolean} True if the storage target should be used, false otherwise
|
|
36
|
+
*/
|
|
37
|
+
shouldUse(): boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Upload log content to Firehose (which delivers to S3)
|
|
40
|
+
*
|
|
41
|
+
* @param {string} key The S3 key (path) for the log file (used for metadata)
|
|
42
|
+
* @param {string} content The log content to upload
|
|
43
|
+
*
|
|
44
|
+
* @returns {Promise<void>}
|
|
45
|
+
*/
|
|
46
|
+
private uploadLog;
|
|
47
|
+
/**
|
|
48
|
+
* Send log content to Firehose with queue management
|
|
49
|
+
* Firehose handles delivery to S3 with buffering and compression
|
|
50
|
+
*
|
|
51
|
+
* @param {string} key The S3 key (path) for the log file (used for metadata)
|
|
52
|
+
* @param {string} newContent The new content to send
|
|
53
|
+
*
|
|
54
|
+
* @returns {Promise<void>}
|
|
55
|
+
*/
|
|
56
|
+
private appendLog;
|
|
57
|
+
/**
|
|
58
|
+
* Writes a log entry to S3 via Firehose
|
|
59
|
+
*
|
|
60
|
+
* @param {LogType} data The log data to write
|
|
61
|
+
*
|
|
62
|
+
* @returns {Promise<void>}
|
|
63
|
+
*/
|
|
64
|
+
write(data: LogType): Promise<void>;
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=log.storage.external.s3.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log.storage.external.s3.service.d.ts","sourceRoot":"","sources":["../../src/services/log.storage.external.s3.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAE3E,OAAO,EAAE,yBAAyB,EAAE,MAAM,4CAA4C,CAAC;AAEvF,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAG5C;;;;;;;;GAQG;AACH,qBAAa,2BAA4B,SAAQ,yBAAyB;IAExE;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAiB;IAEjC;;OAEG;IACH,OAAO,CAAC,MAAM,CAA6C;IAE3D;;OAEG;IACH,OAAO,CAAC,UAAU,CAAyC;IAE3D;;;;OAIG;gBACU,gBAAgB,EAAE,yBAAyB;IA4BxD;;;;OAIG;IACI,SAAS,IAAI,OAAO;IAK3B;;;;;;;OAOG;YACW,SAAS;IAmBvB;;;;;;;;OAQG;YACW,SAAS;IAgCvB;;;;;;OAMG;IACU,KAAK,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;CAoBjD"}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LogStorageExternalS3Service = void 0;
|
|
4
|
+
const client_firehose_1 = require("@aws-sdk/client-firehose");
|
|
5
|
+
const log_storage_external_service_1 = require("./log.storage.external.service");
|
|
6
|
+
const log_service_1 = require("./log.service");
|
|
7
|
+
const log_storage_external_s3_config_1 = require("../configs/log.storage.external.s3.config");
|
|
8
|
+
/**
|
|
9
|
+
* Class LogStorageExternalS3Service
|
|
10
|
+
*
|
|
11
|
+
* Responsible for uploading logs to S3 bucket via Kinesis Firehose
|
|
12
|
+
*
|
|
13
|
+
* @property {FirehoseClient} firehose
|
|
14
|
+
* @property {LogStorageExternalS3ServiceConfigInterface} config
|
|
15
|
+
* @property {Map<string, Promise<void>>} writeQueue
|
|
16
|
+
*/
|
|
17
|
+
class LogStorageExternalS3Service extends log_storage_external_service_1.LogStorageExternalService {
|
|
18
|
+
/**
|
|
19
|
+
* Constructor of the LogStorageS3Service
|
|
20
|
+
*
|
|
21
|
+
* @param {LogServiceConfigInterface} logServiceConfig - Configuration for the logging service
|
|
22
|
+
*/
|
|
23
|
+
constructor(logServiceConfig) {
|
|
24
|
+
super(logServiceConfig);
|
|
25
|
+
/**
|
|
26
|
+
* @var {Map<string, Promise<void>>}
|
|
27
|
+
*/
|
|
28
|
+
this.writeQueue = new Map();
|
|
29
|
+
this.config = (0, log_storage_external_s3_config_1.getLogStorageExternalS3Config)();
|
|
30
|
+
let firehoseConfig = {
|
|
31
|
+
region: this.config.region,
|
|
32
|
+
endpoint: this.config.endpoint,
|
|
33
|
+
};
|
|
34
|
+
if (this.config.accessKeyId
|
|
35
|
+
&& this.config.secretAccessKey) {
|
|
36
|
+
firehoseConfig = {
|
|
37
|
+
region: this.config.region,
|
|
38
|
+
endpoint: this.config.endpoint,
|
|
39
|
+
credentials: {
|
|
40
|
+
accessKeyId: this.config.accessKeyId,
|
|
41
|
+
secretAccessKey: this.config.secretAccessKey,
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
this.firehose = new client_firehose_1.FirehoseClient(firehoseConfig);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Determines if the S3 storage should be used
|
|
49
|
+
*
|
|
50
|
+
* @returns {boolean} True if the storage target should be used, false otherwise
|
|
51
|
+
*/
|
|
52
|
+
shouldUse() {
|
|
53
|
+
return this.logServiceConfig.useS3Storage;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Upload log content to Firehose (which delivers to S3)
|
|
57
|
+
*
|
|
58
|
+
* @param {string} key The S3 key (path) for the log file (used for metadata)
|
|
59
|
+
* @param {string} content The log content to upload
|
|
60
|
+
*
|
|
61
|
+
* @returns {Promise<void>}
|
|
62
|
+
*/
|
|
63
|
+
async uploadLog(key, content) {
|
|
64
|
+
try {
|
|
65
|
+
await this.firehose.send(new client_firehose_1.PutRecordCommand({
|
|
66
|
+
DeliveryStreamName: this.config.firehoseStreamName,
|
|
67
|
+
Record: { Data: Buffer.from(content + '\n') },
|
|
68
|
+
}));
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
console.error(`Failed to upload log to Firehose: ${key}`, error);
|
|
72
|
+
throw error;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Send log content to Firehose with queue management
|
|
77
|
+
* Firehose handles delivery to S3 with buffering and compression
|
|
78
|
+
*
|
|
79
|
+
* @param {string} key The S3 key (path) for the log file (used for metadata)
|
|
80
|
+
* @param {string} newContent The new content to send
|
|
81
|
+
*
|
|
82
|
+
* @returns {Promise<void>}
|
|
83
|
+
*/
|
|
84
|
+
async appendLog(key, newContent) {
|
|
85
|
+
const currentOperation = this.writeQueue.get(key) || Promise.resolve();
|
|
86
|
+
const newOperation = currentOperation.then(async () => {
|
|
87
|
+
try {
|
|
88
|
+
await this.uploadLog(key, newContent);
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
console.error(`Failed to send log to Firehose: ${key}`, error);
|
|
92
|
+
throw error;
|
|
93
|
+
}
|
|
94
|
+
finally {
|
|
95
|
+
this.writeQueue.delete(key);
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
this.writeQueue.set(key, newOperation);
|
|
99
|
+
return newOperation;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Writes a log entry to S3 via Firehose
|
|
103
|
+
*
|
|
104
|
+
* @param {LogType} data The log data to write
|
|
105
|
+
*
|
|
106
|
+
* @returns {Promise<void>}
|
|
107
|
+
*/
|
|
108
|
+
async write(data) {
|
|
109
|
+
try {
|
|
110
|
+
const logEntry = log_service_1.LogService.formatLog(data);
|
|
111
|
+
const combinedFilePath = this.getCombinedLogFilePath();
|
|
112
|
+
await this.appendLog(combinedFilePath, logEntry);
|
|
113
|
+
}
|
|
114
|
+
catch (error) {
|
|
115
|
+
console.error('Failed to write log to Firehose/S3 storage:', error);
|
|
116
|
+
throw error;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
exports.LogStorageExternalS3Service = LogStorageExternalS3Service;
|
|
121
|
+
//# sourceMappingURL=log.storage.external.s3.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log.storage.external.s3.service.js","sourceRoot":"","sources":["../../src/services/log.storage.external.s3.service.ts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AK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CACX,6CAA6C,EAC7C,KAAK,CACN,CAAC;YAEF,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;CACF;AA3JD,kEA2JC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { LogServiceConfigInterface } from "../interfaces/log.service.config.interface";
|
|
2
|
+
import { LogStorageBaseService } from "./log.storage.base.service";
|
|
3
|
+
/**
|
|
4
|
+
* Abstract Class LogStorageExternalService
|
|
5
|
+
*
|
|
6
|
+
* Base class for external logging storage target services (e.g., S3)
|
|
7
|
+
*/
|
|
8
|
+
export declare abstract class LogStorageExternalService extends LogStorageBaseService {
|
|
9
|
+
/**
|
|
10
|
+
* Constructor for LogStorageExternalService
|
|
11
|
+
*
|
|
12
|
+
* @param {LogServiceConfigInterface} loggingServiceConfig - Configuration for the logging service
|
|
13
|
+
* @param {string} baseLogsDirectory - Base directory for storing logs
|
|
14
|
+
*/
|
|
15
|
+
constructor(loggingServiceConfig: LogServiceConfigInterface, baseLogsDirectory?: string);
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=log.storage.external.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log.storage.external.service.d.ts","sourceRoot":"","sources":["../../src/services/log.storage.external.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,4CAA4C,CAAC;AACvF,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAEnE;;;;GAIG;AACH,8BAAsB,yBAA0B,SAAQ,qBAAqB;IAE3E;;;;;OAKG;gBAED,oBAAoB,EAAE,yBAAyB,EAC/C,iBAAiB,GAAE,MAAe;CAOrC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LogStorageExternalService = void 0;
|
|
4
|
+
const log_storage_base_service_1 = require("./log.storage.base.service");
|
|
5
|
+
/**
|
|
6
|
+
* Abstract Class LogStorageExternalService
|
|
7
|
+
*
|
|
8
|
+
* Base class for external logging storage target services (e.g., S3)
|
|
9
|
+
*/
|
|
10
|
+
class LogStorageExternalService extends log_storage_base_service_1.LogStorageBaseService {
|
|
11
|
+
/**
|
|
12
|
+
* Constructor for LogStorageExternalService
|
|
13
|
+
*
|
|
14
|
+
* @param {LogServiceConfigInterface} loggingServiceConfig - Configuration for the logging service
|
|
15
|
+
* @param {string} baseLogsDirectory - Base directory for storing logs
|
|
16
|
+
*/
|
|
17
|
+
constructor(loggingServiceConfig, baseLogsDirectory = 'logs') {
|
|
18
|
+
super(loggingServiceConfig, baseLogsDirectory);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.LogStorageExternalService = LogStorageExternalService;
|
|
22
|
+
//# sourceMappingURL=log.storage.external.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log.storage.external.service.js","sourceRoot":"","sources":["../../src/services/log.storage.external.service.ts"],"names":[],"mappings":";;;AACA,yEAAmE;AAEnE;;;;GAIG;AACH,MAAsB,yBAA0B,SAAQ,gDAAqB;IAE3E;;;;;OAKG;IACH,YACE,oBAA+C,EAC/C,oBAA4B,MAAM;QAElC,KAAK,CACH,oBAAoB,EACpB,iBAAiB,CAClB,CAAC;IACJ,CAAC;CACF;AAjBD,8DAiBC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { LogStorageBaseService } from './log.storage.base.service';
|
|
2
|
+
import { LogServiceConfigInterface } from '../interfaces/log.service.config.interface';
|
|
3
|
+
import { LogType } from '../types/log.type';
|
|
4
|
+
/**
|
|
5
|
+
* Class LogStorageLocalService
|
|
6
|
+
*
|
|
7
|
+
* Responsible for storing logs on the local file system
|
|
8
|
+
*/
|
|
9
|
+
export declare class LogStorageLocalService extends LogStorageBaseService {
|
|
10
|
+
/**
|
|
11
|
+
* Constructor of the LogStorageLocalService
|
|
12
|
+
*
|
|
13
|
+
* @param {LogServiceConfigInterface} loggingServiceConfig - Configuration for the logging service
|
|
14
|
+
* @param {string} baseLogsDirectory - Base directory for storing logs
|
|
15
|
+
*/
|
|
16
|
+
constructor(loggingServiceConfig: LogServiceConfigInterface, baseLogsDirectory?: string);
|
|
17
|
+
/**
|
|
18
|
+
* Indicates if the storage target should be used
|
|
19
|
+
*
|
|
20
|
+
* @returns {boolean} Always true for local storage
|
|
21
|
+
*/
|
|
22
|
+
shouldUse(): boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Ensures the logs directory exists for the current environment
|
|
25
|
+
*
|
|
26
|
+
* @returns {void}
|
|
27
|
+
*/
|
|
28
|
+
private ensureLogsDirectory;
|
|
29
|
+
/**
|
|
30
|
+
* Writes a log entry to local storage
|
|
31
|
+
*
|
|
32
|
+
* @param {LogType} data The log data to write
|
|
33
|
+
*
|
|
34
|
+
* @returns {Promise<void>}
|
|
35
|
+
*/
|
|
36
|
+
write(data: LogType): Promise<void>;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=log.storage.local.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log.storage.local.service.d.ts","sourceRoot":"","sources":["../../src/services/log.storage.local.service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAAE,yBAAyB,EAAE,MAAM,4CAA4C,CAAC;AACvF,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAG5C;;;;GAIG;AACH,qBAAa,sBAAuB,SAAQ,qBAAqB;IAE/D;;;;;OAKG;gBAED,oBAAoB,EAAE,yBAAyB,EAC/C,iBAAiB,GAAE,MAGlB;IAQH;;;;OAIG;IACI,SAAS,IAAI,OAAO;IAK3B;;;;OAIG;IACH,OAAO,CAAC,mBAAmB;IAY3B;;;;;;OAMG;IACU,KAAK,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;CAuBjD"}
|
|
@@ -0,0 +1,96 @@
|
|
|
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 () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.LogStorageLocalService = void 0;
|
|
37
|
+
const fs = __importStar(require("fs"));
|
|
38
|
+
const path = __importStar(require("path"));
|
|
39
|
+
const log_storage_base_service_1 = require("./log.storage.base.service");
|
|
40
|
+
const log_service_1 = require("./log.service");
|
|
41
|
+
/**
|
|
42
|
+
* Class LogStorageLocalService
|
|
43
|
+
*
|
|
44
|
+
* Responsible for storing logs on the local file system
|
|
45
|
+
*/
|
|
46
|
+
class LogStorageLocalService extends log_storage_base_service_1.LogStorageBaseService {
|
|
47
|
+
/**
|
|
48
|
+
* Constructor of the LogStorageLocalService
|
|
49
|
+
*
|
|
50
|
+
* @param {LogServiceConfigInterface} loggingServiceConfig - Configuration for the logging service
|
|
51
|
+
* @param {string} baseLogsDirectory - Base directory for storing logs
|
|
52
|
+
*/
|
|
53
|
+
constructor(loggingServiceConfig, baseLogsDirectory = path.join(process.cwd(), 'src/storage/logs')) {
|
|
54
|
+
super(loggingServiceConfig, baseLogsDirectory);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Indicates if the storage target should be used
|
|
58
|
+
*
|
|
59
|
+
* @returns {boolean} Always true for local storage
|
|
60
|
+
*/
|
|
61
|
+
shouldUse() {
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Ensures the logs directory exists for the current environment
|
|
66
|
+
*
|
|
67
|
+
* @returns {void}
|
|
68
|
+
*/
|
|
69
|
+
ensureLogsDirectory() {
|
|
70
|
+
const logsDirectory = this.getLogsDirectory();
|
|
71
|
+
if (!fs.existsSync(logsDirectory)) {
|
|
72
|
+
fs.mkdirSync(logsDirectory, { recursive: true });
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Writes a log entry to local storage
|
|
77
|
+
*
|
|
78
|
+
* @param {LogType} data The log data to write
|
|
79
|
+
*
|
|
80
|
+
* @returns {Promise<void>}
|
|
81
|
+
*/
|
|
82
|
+
async write(data) {
|
|
83
|
+
try {
|
|
84
|
+
this.ensureLogsDirectory();
|
|
85
|
+
const logEntry = log_service_1.LogService.formatLog(data);
|
|
86
|
+
const combinedFilePath = this.getCombinedLogFilePath();
|
|
87
|
+
fs.appendFileSync(combinedFilePath, logEntry + '\n', 'utf8');
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
console.error('Failed to write log to local storage:', error);
|
|
91
|
+
throw error;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
exports.LogStorageLocalService = LogStorageLocalService;
|
|
96
|
+
//# sourceMappingURL=log.storage.local.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log.storage.local.service.js","sourceRoot":"","sources":["../../src/services/log.storage.local.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAAyB;AACzB,2CAA6B;AAC7B,yEAAmE;AAGnE,+CAA2C;AAE3C;;;;GAIG;AACH,MAAa,sBAAuB,SAAQ,gDAAqB;IAE/D;;;;;OAKG;IACH,YACE,oBAA+C,EAC/C,oBAA4B,IAAI,CAAC,IAAI,CACnC,OAAO,CAAC,GAAG,EAAE,EACb,kBAAkB,CACnB;QAED,KAAK,CACH,oBAAoB,EACpB,iBAAiB,CAClB,CAAC;IACJ,CAAC;IAED;;;;OAIG;IACI,SAAS;QAEd,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;OAIG;IACK,mBAAmB;QAEzB,MAAM,aAAa,GAAG,IAAI,CAAC,gBAAgB,EAAE,CAAC;QAE9C,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,aAAa,CAAC,EAAE,CAAC;YAClC,EAAE,CAAC,SAAS,CACV,aAAa,EACb,EAAE,SAAS,EAAE,IAAI,EAAE,CACpB,CAAC;QACJ,CAAC;IACH,CAAC;IAED;;;;;;OAMG;IACI,KAAK,CAAC,KAAK,CAAC,IAAa;QAE9B,IAAI,CAAC;YACH,IAAI,CAAC,mBAAmB,EAAE,CAAC;YAE3B,MAAM,QAAQ,GAAG,wBAAU,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;YAE5C,MAAM,gBAAgB,GAAG,IAAI,CAAC,sBAAsB,EAAE,CAAC;YAEvD,EAAE,CAAC,cAAc,CACf,gBAAgB,EAChB,QAAQ,GAAG,IAAI,EACf,MAAM,CACP,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CACX,uCAAuC,EACvC,KAAK,CACN,CAAC;YAEF,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;CACF;AA9ED,wDA8EC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { LogServiceConfigInterface } from '../interfaces/log.service.config.interface';
|
|
2
|
+
import { LogType } from '../types/log.type';
|
|
3
|
+
/**
|
|
4
|
+
* Class LogStorageService
|
|
5
|
+
*
|
|
6
|
+
* Responsible for saving logs to local files or S3 bucket organized by date and environment
|
|
7
|
+
*
|
|
8
|
+
* @property {LogStorageLocalService} localService
|
|
9
|
+
* @property {LogStorageExternalService} externalService
|
|
10
|
+
* @property {LogServiceConfigInterface} logServiceConfig
|
|
11
|
+
*/
|
|
12
|
+
export declare class LogStorageService {
|
|
13
|
+
/**
|
|
14
|
+
* @var {LogStorageLocalService}
|
|
15
|
+
*/
|
|
16
|
+
private localService;
|
|
17
|
+
/**
|
|
18
|
+
* @var {LogStorageExternalService}
|
|
19
|
+
*/
|
|
20
|
+
private externalService;
|
|
21
|
+
/**
|
|
22
|
+
* @var {LogServiceConfigInterface}
|
|
23
|
+
*/
|
|
24
|
+
private logServiceConfig;
|
|
25
|
+
/**
|
|
26
|
+
* Constructor of the LogStorageService
|
|
27
|
+
*
|
|
28
|
+
* @param {LogServiceConfigInterface} logServiceConfig - Configuration for the logging service
|
|
29
|
+
*/
|
|
30
|
+
constructor(logServiceConfig: LogServiceConfigInterface);
|
|
31
|
+
/**
|
|
32
|
+
* Writes a log entry to the appropriate storage
|
|
33
|
+
*
|
|
34
|
+
* @param {LogType} data The log data to write
|
|
35
|
+
*
|
|
36
|
+
* @returns {Promise<void>}
|
|
37
|
+
*/
|
|
38
|
+
write(data: LogType): Promise<void>;
|
|
39
|
+
/**
|
|
40
|
+
* Writes a log entry to local storage
|
|
41
|
+
*
|
|
42
|
+
* @param {LogType} data The log data to write
|
|
43
|
+
*
|
|
44
|
+
* @returns {Promise<void>}
|
|
45
|
+
*/
|
|
46
|
+
private writeLocalService;
|
|
47
|
+
/**
|
|
48
|
+
* Writes a log entry to external storage
|
|
49
|
+
*
|
|
50
|
+
* @param {LogType} data The log data to write
|
|
51
|
+
*
|
|
52
|
+
* @returns {Promise<void>}
|
|
53
|
+
*/
|
|
54
|
+
private writeExternalService;
|
|
55
|
+
/**
|
|
56
|
+
* Indicates if any storage target should be used
|
|
57
|
+
*
|
|
58
|
+
* @returns {boolean} True if any storage target should be used, false otherwise
|
|
59
|
+
*/
|
|
60
|
+
shouldUse(): boolean;
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=log.storage.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log.storage.service.d.ts","sourceRoot":"","sources":["../../src/services/log.storage.service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,yBAAyB,EAAE,MAAM,4CAA4C,CAAC;AAEvF,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAG5C;;;;;;;;GAQG;AACH,qBAAa,iBAAiB;IAE5B;;OAEG;IACH,OAAO,CAAC,YAAY,CAAyB;IAE7C;;OAEG;IACH,OAAO,CAAC,eAAe,CAA4B;IAEnD;;OAEG;IACH,OAAO,CAAC,gBAAgB,CAA4B;IAEpD;;;;OAIG;gBACU,gBAAgB,EAAE,yBAAyB;IAQxD;;;;;;OAMG;IACU,KAAK,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAWhD;;;;;;OAMG;YACW,iBAAiB;IAc/B;;;;;;OAMG;YACW,oBAAoB;IAmBlC;;;;OAIG;IACI,SAAS,IAAI,OAAO;CAK5B"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LogStorageService = void 0;
|
|
4
|
+
const log_storage_local_service_1 = require("./log.storage.local.service");
|
|
5
|
+
const log_storage_external_s3_service_1 = require("./log.storage.external.s3.service");
|
|
6
|
+
const log_error_1 = require("../errors/log.error");
|
|
7
|
+
/**
|
|
8
|
+
* Class LogStorageService
|
|
9
|
+
*
|
|
10
|
+
* Responsible for saving logs to local files or S3 bucket organized by date and environment
|
|
11
|
+
*
|
|
12
|
+
* @property {LogStorageLocalService} localService
|
|
13
|
+
* @property {LogStorageExternalService} externalService
|
|
14
|
+
* @property {LogServiceConfigInterface} logServiceConfig
|
|
15
|
+
*/
|
|
16
|
+
class LogStorageService {
|
|
17
|
+
/**
|
|
18
|
+
* Constructor of the LogStorageService
|
|
19
|
+
*
|
|
20
|
+
* @param {LogServiceConfigInterface} logServiceConfig - Configuration for the logging service
|
|
21
|
+
*/
|
|
22
|
+
constructor(logServiceConfig) {
|
|
23
|
+
this.logServiceConfig = logServiceConfig;
|
|
24
|
+
this.localService = new log_storage_local_service_1.LogStorageLocalService(this.logServiceConfig);
|
|
25
|
+
this.externalService = new log_storage_external_s3_service_1.LogStorageExternalS3Service(this.logServiceConfig);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Writes a log entry to the appropriate storage
|
|
29
|
+
*
|
|
30
|
+
* @param {LogType} data The log data to write
|
|
31
|
+
*
|
|
32
|
+
* @returns {Promise<void>}
|
|
33
|
+
*/
|
|
34
|
+
async write(data) {
|
|
35
|
+
if (this.externalService.shouldUse()) {
|
|
36
|
+
await this.writeExternalService(data);
|
|
37
|
+
}
|
|
38
|
+
else if (this.localService.shouldUse()) {
|
|
39
|
+
await this.writeLocalService(data);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
throw new log_error_1.LogError('No available log storage targets.');
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Writes a log entry to local storage
|
|
47
|
+
*
|
|
48
|
+
* @param {LogType} data The log data to write
|
|
49
|
+
*
|
|
50
|
+
* @returns {Promise<void>}
|
|
51
|
+
*/
|
|
52
|
+
async writeLocalService(data) {
|
|
53
|
+
try {
|
|
54
|
+
await this.localService.write(data);
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
console.error('Local logging failed:', error);
|
|
58
|
+
throw error;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Writes a log entry to external storage
|
|
63
|
+
*
|
|
64
|
+
* @param {LogType} data The log data to write
|
|
65
|
+
*
|
|
66
|
+
* @returns {Promise<void>}
|
|
67
|
+
*/
|
|
68
|
+
async writeExternalService(data) {
|
|
69
|
+
try {
|
|
70
|
+
await this.externalService.write(data);
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
console.error('External logging failed:', error);
|
|
74
|
+
if (!this.localService.shouldUse()) {
|
|
75
|
+
throw error;
|
|
76
|
+
}
|
|
77
|
+
console.info('Falling back to local logging storage.');
|
|
78
|
+
await this.writeLocalService(data);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Indicates if any storage target should be used
|
|
83
|
+
*
|
|
84
|
+
* @returns {boolean} True if any storage target should be used, false otherwise
|
|
85
|
+
*/
|
|
86
|
+
shouldUse() {
|
|
87
|
+
return this.localService.shouldUse()
|
|
88
|
+
|| this.externalService.shouldUse();
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
exports.LogStorageService = LogStorageService;
|
|
92
|
+
//# sourceMappingURL=log.storage.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log.storage.service.js","sourceRoot":"","sources":["../../src/services/log.storage.service.ts"],"names":[],"mappings":";;;AAAA,2EAAqE;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