@ti-engine/core 1.7.1 → 1.8.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/CHANGELOG.md +393 -377
- package/LICENSE.md +321 -321
- package/README.md +599 -597
- package/bin/localization/labels.json +122 -122
- package/bin/settings.json +41 -41
- package/bin/start-instance.js +164 -164
- package/components/auditing.js +191 -191
- package/components/connection-observer.js +72 -72
- package/components/definitions.types.js +248 -248
- package/components/exchange/default/default-message-exchange.js +136 -136
- package/components/exchange/default/default-message-receiver.js +101 -101
- package/components/exchange/default/default-message-sender.js +100 -100
- package/components/exchange/message-dispatcher.js +168 -168
- package/components/exchange/message-exchange.js +449 -449
- package/components/exchange/message-handler.js +235 -235
- package/components/exchange/message-memory-cache.js +190 -190
- package/components/exchange/message-observer.js +126 -126
- package/components/exchange/message-receiver.js +181 -181
- package/components/exchange/message-sender.js +143 -143
- package/components/exchange/message-tracer.js +212 -212
- package/components/service-caller.js +370 -370
- package/components/service-consumer.js +131 -131
- package/components/service-executor.js +278 -278
- package/components/service-instance.js +316 -316
- package/components/service-provider.js +251 -251
- package/integrations/redis-integration.js +591 -591
- package/package.json +89 -89
- package/utils/cache.js +772 -772
- package/utils/config.js +103 -103
- package/utils/exceptions.js +368 -368
- package/utils/localization.js +298 -298
- package/utils/logger.js +82 -82
- package/utils/tools.js +632 -632
package/utils/logger.js
CHANGED
|
@@ -1,83 +1,83 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* The ti-engine is an open source, free to use—both for personal and commercial projects—framework for the creation of microservice-based solutions using node.js.
|
|
3
|
-
* Copyright © 2021-2025 Boris Kostadinov <kostadinov.boris@gmail.com>
|
|
4
|
-
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
|
5
|
-
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
6
|
-
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
const _ = require( "lodash" );
|
|
10
|
-
const tools = require( "#tools" );
|
|
11
|
-
const exceptions = require( "#exceptions" );
|
|
12
|
-
const localization = require( "#localization" );
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Enum for specifying the log entry severity. This is based on the Google Stackdriver severity levels.
|
|
16
|
-
*
|
|
17
|
-
* @readonly
|
|
18
|
-
* @enum {number}
|
|
19
|
-
* @typedef {number} TiLogSeverity
|
|
20
|
-
*/
|
|
21
|
-
const logSeverityEnum = tools.enum( {
|
|
22
|
-
DEFAULT: [ 0, "default", "The log entry has no assigned severity level." ],
|
|
23
|
-
DEBUG: [ 100, "debug", "Debug or trace information." ],
|
|
24
|
-
INFO: [ 200, "info", "Routine information, such as ongoing status or performance." ],
|
|
25
|
-
NOTICE: [ 300, "notice", "Normal but significant events, such as start up, shut down, or a configuration change." ],
|
|
26
|
-
WARNING: [ 400, "warning", "Warning events might cause problems." ],
|
|
27
|
-
ERROR: [ 500, "error", "Error events are likely to cause problems." ],
|
|
28
|
-
CRITICAL: [ 600, "critical", "Critical events cause more severe problems or outages." ],
|
|
29
|
-
ALERT: [ 700, "alert", "A person must take an action immediately." ],
|
|
30
|
-
EMERGENCY: [ 800, "emergency", "One or more systems are unusable." ]
|
|
31
|
-
} );
|
|
32
|
-
module.exports.logSeverity = logSeverityEnum;
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Used to safely return the name of a severity code.
|
|
36
|
-
*
|
|
37
|
-
* @method
|
|
38
|
-
* @param {TiLogSeverity} severity
|
|
39
|
-
* @returns {string}
|
|
40
|
-
*/
|
|
41
|
-
module.exports.getSeverityName = ( severity ) => {
|
|
42
|
-
return logSeverityEnum.name( severity, "unknown" );
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Used to extract information from a {@link TiException} and convert it to a loggable data object.
|
|
47
|
-
*
|
|
48
|
-
* @method
|
|
49
|
-
* @param {TiException} exception
|
|
50
|
-
* @returns {{description, details: (*|undefined), exceptionID}}
|
|
51
|
-
* @private
|
|
52
|
-
*/
|
|
53
|
-
const exceptionToLog = ( exception ) => {
|
|
54
|
-
return {
|
|
55
|
-
exceptionID: exception.id,
|
|
56
|
-
description: localization.getLabel( exception.label ),
|
|
57
|
-
details: !_.isEmpty( exception.data ) ? exception.data : undefined
|
|
58
|
-
};
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Used to generate and store a new log entry via the active {@link Auditing} instance.
|
|
63
|
-
*
|
|
64
|
-
* @method
|
|
65
|
-
* @param {string} message The primary log message.
|
|
66
|
-
* @param {TiLogSeverity} [level=DEFAULT] The log severity level. If the current log filtering setting is higher than this, then the log entry will be ignored.
|
|
67
|
-
* @param {Object|Error|TiException} [data={}] Optional JSON data containing details of the log entry.
|
|
68
|
-
* @param {string} [thread='main'] The logging thread to which the log entry belongs.
|
|
69
|
-
* @public
|
|
70
|
-
*/
|
|
71
|
-
module.exports.log = ( message, level = logSeverityEnum.DEFAULT, data = {}, thread = "main" ) => {
|
|
72
|
-
const auditing = require( "#auditing" );
|
|
73
|
-
|
|
74
|
-
if ( data instanceof Error ) {
|
|
75
|
-
data = tools.errorToJSON( data );
|
|
76
|
-
} else if ( exceptions.isException( data ) ) {
|
|
77
|
-
data = exceptionToLog( data );
|
|
78
|
-
} else if ( data.exception !== undefined && exceptions.isException( data.exception ) ) {
|
|
79
|
-
data.exception = exceptionToLog( data.exception );
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
auditing.instance.log( message, level, thread, data );
|
|
1
|
+
/*
|
|
2
|
+
* The ti-engine is an open source, free to use—both for personal and commercial projects—framework for the creation of microservice-based solutions using node.js.
|
|
3
|
+
* Copyright © 2021-2025 Boris Kostadinov <kostadinov.boris@gmail.com>
|
|
4
|
+
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
|
5
|
+
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
6
|
+
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
const _ = require( "lodash" );
|
|
10
|
+
const tools = require( "#tools" );
|
|
11
|
+
const exceptions = require( "#exceptions" );
|
|
12
|
+
const localization = require( "#localization" );
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Enum for specifying the log entry severity. This is based on the Google Stackdriver severity levels.
|
|
16
|
+
*
|
|
17
|
+
* @readonly
|
|
18
|
+
* @enum {number}
|
|
19
|
+
* @typedef {number} TiLogSeverity
|
|
20
|
+
*/
|
|
21
|
+
const logSeverityEnum = tools.enum( {
|
|
22
|
+
DEFAULT: [ 0, "default", "The log entry has no assigned severity level." ],
|
|
23
|
+
DEBUG: [ 100, "debug", "Debug or trace information." ],
|
|
24
|
+
INFO: [ 200, "info", "Routine information, such as ongoing status or performance." ],
|
|
25
|
+
NOTICE: [ 300, "notice", "Normal but significant events, such as start up, shut down, or a configuration change." ],
|
|
26
|
+
WARNING: [ 400, "warning", "Warning events might cause problems." ],
|
|
27
|
+
ERROR: [ 500, "error", "Error events are likely to cause problems." ],
|
|
28
|
+
CRITICAL: [ 600, "critical", "Critical events cause more severe problems or outages." ],
|
|
29
|
+
ALERT: [ 700, "alert", "A person must take an action immediately." ],
|
|
30
|
+
EMERGENCY: [ 800, "emergency", "One or more systems are unusable." ]
|
|
31
|
+
} );
|
|
32
|
+
module.exports.logSeverity = logSeverityEnum;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Used to safely return the name of a severity code.
|
|
36
|
+
*
|
|
37
|
+
* @method
|
|
38
|
+
* @param {TiLogSeverity} severity
|
|
39
|
+
* @returns {string}
|
|
40
|
+
*/
|
|
41
|
+
module.exports.getSeverityName = ( severity ) => {
|
|
42
|
+
return logSeverityEnum.name( severity, "unknown" );
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Used to extract information from a {@link TiException} and convert it to a loggable data object.
|
|
47
|
+
*
|
|
48
|
+
* @method
|
|
49
|
+
* @param {TiException} exception
|
|
50
|
+
* @returns {{description, details: (*|undefined), exceptionID}}
|
|
51
|
+
* @private
|
|
52
|
+
*/
|
|
53
|
+
const exceptionToLog = ( exception ) => {
|
|
54
|
+
return {
|
|
55
|
+
exceptionID: exception.id,
|
|
56
|
+
description: localization.getLabel( exception.label ),
|
|
57
|
+
details: !_.isEmpty( exception.data ) ? exception.data : undefined
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Used to generate and store a new log entry via the active {@link Auditing} instance.
|
|
63
|
+
*
|
|
64
|
+
* @method
|
|
65
|
+
* @param {string} message The primary log message.
|
|
66
|
+
* @param {TiLogSeverity} [level=DEFAULT] The log severity level. If the current log filtering setting is higher than this, then the log entry will be ignored.
|
|
67
|
+
* @param {Object|Error|TiException} [data={}] Optional JSON data containing details of the log entry.
|
|
68
|
+
* @param {string} [thread='main'] The logging thread to which the log entry belongs.
|
|
69
|
+
* @public
|
|
70
|
+
*/
|
|
71
|
+
module.exports.log = ( message, level = logSeverityEnum.DEFAULT, data = {}, thread = "main" ) => {
|
|
72
|
+
const auditing = require( "#auditing" );
|
|
73
|
+
|
|
74
|
+
if ( data instanceof Error ) {
|
|
75
|
+
data = tools.errorToJSON( data );
|
|
76
|
+
} else if ( exceptions.isException( data ) ) {
|
|
77
|
+
data = exceptionToLog( data );
|
|
78
|
+
} else if ( data.exception !== undefined && exceptions.isException( data.exception ) ) {
|
|
79
|
+
data.exception = exceptionToLog( data.exception );
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
auditing.instance.log( message, level, thread, data );
|
|
83
83
|
};
|