Skip to content

Commit ff9e1c7

Browse files
[backend] Reactivate logging limit (#9554)
1 parent 1533e1a commit ff9e1c7

File tree

1 file changed

+26
-23
lines changed
  • opencti-platform/opencti-graphql/src/config

1 file changed

+26
-23
lines changed

opencti-platform/opencti-graphql/src/config/conf.js

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ nconf.file('default', resolveEnvFile('default'));
9696
const appLogLevel = nconf.get('app:app_logs:logs_level');
9797
const appLogFileTransport = booleanConf('app:app_logs:logs_files', true);
9898
const appLogConsoleTransport = booleanConf('app:app_logs:logs_console', true);
99+
export const appLogLevelMaxDepthSize = nconf.get('app:app_logs:max_depth_size') ?? 5;
99100
export const appLogLevelMaxArraySize = nconf.get('app:app_logs:max_array_size') ?? 50;
100101
export const appLogLevelMaxStringSize = nconf.get('app:app_logs:max_string_size') ?? 5000;
101102
export const appLogExtendedErrors = booleanConf('app:app_logs:extended_error_message', false);
@@ -105,29 +106,31 @@ export const extendedErrors = (metaExtension) => {
105106
}
106107
return {};
107108
};
108-
export const limitMetaErrorComplexity = (obj) => {
109-
if (Array.isArray(obj)) {
110-
// Create a new array with a limited size
111-
const limitedArray = obj.slice(0, appLogLevelMaxArraySize);
112-
// Recursively process each item in the truncated array
113-
const processedArray = [];
114-
for (let i = 0; i < limitedArray.length; i += 1) {
115-
processedArray[i] = limitMetaErrorComplexity(limitedArray[i]);
109+
export const limitMetaErrorComplexity = (obj, current_depth = 0) => {
110+
if (obj !== null && current_depth > appLogLevelMaxDepthSize && typeof obj !== 'function') {
111+
if (Array.isArray(obj)) {
112+
// Create a new array with a limited size
113+
const limitedArray = obj.slice(0, appLogLevelMaxArraySize);
114+
// Recursively process each item in the truncated array
115+
const processedArray = [];
116+
for (let i = 0; i < limitedArray.length; i += 1) {
117+
processedArray[i] = limitMetaErrorComplexity(limitedArray[i], current_depth + 1);
118+
}
119+
return processedArray;
116120
}
117-
return processedArray;
118-
}
119-
if (typeof obj === 'string' && obj.length > appLogLevelMaxStringSize) {
120-
return `${obj.substring(0, appLogLevelMaxStringSize - 3)}...`;
121-
}
122-
if (obj !== null && typeof obj === 'object') {
123-
// Create a new object to hold the processed properties
124-
const limitedObject = {};
125-
const keys = Object.keys(obj); // Get the keys of the object
126-
for (let i = 0; i < keys.length; i += 1) {
127-
const key = keys[i];
128-
limitedObject[key] = limitMetaErrorComplexity(obj[key]);
121+
if (typeof obj === 'string' && obj.length > appLogLevelMaxStringSize) {
122+
return `${obj.substring(0, appLogLevelMaxStringSize - 3)}...`;
123+
}
124+
if (typeof obj === 'object') {
125+
// Create a new object to hold the processed properties
126+
const limitedObject = {};
127+
const keys = Object.keys(obj); // Get the keys of the object
128+
for (let i = 0; i < keys.length; i += 1) {
129+
const key = keys[i];
130+
limitedObject[key] = limitMetaErrorComplexity(obj[key], current_depth + 1);
131+
}
132+
return limitedObject;
129133
}
130-
return limitedObject;
131134
}
132135
return obj;
133136
};
@@ -253,8 +256,8 @@ export const logApp = {
253256
if (appLogTransports.length > 0 && appLogger.isLevelEnabled(level)) {
254257
const data = addBasicMetaInformation(LOG_APP, error, { ...meta, source: 'backend' });
255258
// Prevent meta information to be too massive.
256-
// const limitedData = limitMetaErrorComplexity(data);
257-
appLogger.log(level, message, data);
259+
const limitedData = limitMetaErrorComplexity(data);
260+
appLogger.log(level, message, limitedData);
258261
}
259262
},
260263
_logWithError: (level, messageOrError, meta = {}) => {

0 commit comments

Comments
 (0)