Skip to content

Commit

Permalink
Merge branch 'console' into console-v0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
jagankumar-egov committed Dec 6, 2024
2 parents 61a6c7c + 91dfe7c commit 6e63e26
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions health-services/project-factory/src/server/utils/logger/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,17 @@ export { logger };

const DEFAULT_LOG_MESSAGE_COUNT = config.app.debugLogCharLimit;

export const getFormattedStringForDebug = (obj: any) => {
const convertedMessage=JSON.stringify(obj);
return convertedMessage?.slice(0, DEFAULT_LOG_MESSAGE_COUNT) +
(convertedMessage?.length > DEFAULT_LOG_MESSAGE_COUNT ? "\n ---more" : "");
}
export const getFormattedStringForDebug = (obj: any): string => {
try {
const convertedMessage = JSON.stringify(obj);
return convertedMessage.slice(0, DEFAULT_LOG_MESSAGE_COUNT) +
(convertedMessage.length > DEFAULT_LOG_MESSAGE_COUNT ? "\n ---more" : "");
} catch (error : any ) {
if (error instanceof RangeError && error.message.includes("Invalid string length")) {
logger.error("The object is too big to convert into a string.");
} else {
logger.error(`An unexpected error occurred while formatting the object into a string : ${error?.message}`);
}
return "Error: Unable to format object for debug.";
}
};

0 comments on commit 6e63e26

Please sign in to comment.