@@ -96,6 +96,7 @@ nconf.file('default', resolveEnvFile('default'));
96
96
const appLogLevel = nconf . get ( 'app:app_logs:logs_level' ) ;
97
97
const appLogFileTransport = booleanConf ( 'app:app_logs:logs_files' , true ) ;
98
98
const appLogConsoleTransport = booleanConf ( 'app:app_logs:logs_console' , true ) ;
99
+ export const appLogLevelMaxDepthSize = nconf . get ( 'app:app_logs:max_depth_size' ) ?? 5 ;
99
100
export const appLogLevelMaxArraySize = nconf . get ( 'app:app_logs:max_array_size' ) ?? 50 ;
100
101
export const appLogLevelMaxStringSize = nconf . get ( 'app:app_logs:max_string_size' ) ?? 5000 ;
101
102
export const appLogExtendedErrors = booleanConf ( 'app:app_logs:extended_error_message' , false ) ;
@@ -105,29 +106,31 @@ export const extendedErrors = (metaExtension) => {
105
106
}
106
107
return { } ;
107
108
} ;
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 ;
116
120
}
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 ;
129
133
}
130
- return limitedObject ;
131
134
}
132
135
return obj ;
133
136
} ;
@@ -253,8 +256,8 @@ export const logApp = {
253
256
if ( appLogTransports . length > 0 && appLogger . isLevelEnabled ( level ) ) {
254
257
const data = addBasicMetaInformation ( LOG_APP , error , { ...meta , source : 'backend' } ) ;
255
258
// 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 ) ;
258
261
}
259
262
} ,
260
263
_logWithError : ( level , messageOrError , meta = { } ) => {
0 commit comments