From 89786163485bd9518ae398abf1c0bb677cc5ed47 Mon Sep 17 00:00:00 2001 From: Filip Bostik Date: Wed, 13 Mar 2024 11:45:50 +0100 Subject: [PATCH 1/4] bugfix to Login, Error pages keys in Installer, settable message field length in Installer and Logger, Text Appender for Logger --- .gitignore | 6 ++++++ core/lib_logger.ssjs | 44 +++++++++++++++++++++++++++++++++++++++++--- setup/setup.ssjs | 17 +++++++++++------ 3 files changed, 58 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index d650656..2ecc203 100644 --- a/.gitignore +++ b/.gitignore @@ -36,6 +36,12 @@ ehthumbs.db Thumbs.db +# Custom # +###################### *.conf *lib_le.js *lib_luxapi.js + +.vscode/ +tests.ssjs +*ssjs-vsc.json \ No newline at end of file diff --git a/core/lib_logger.ssjs b/core/lib_logger.ssjs index f239b28..65a30db 100644 --- a/core/lib_logger.ssjs +++ b/core/lib_logger.ssjs @@ -2,7 +2,7 @@ * @copyright {@link https://www.email360.io/|email360} * @author {@link https://www.linkedin.com/in/sascha-huwald/|Sascha Huwald} * @since 2020 - * @version 1.0.0 + * @version 1.0.1 * @license {@link https://github.com/email360/ssjs-lib/blob/master/LICENSE|MIT} * * This is a mini log4ssjs version based on log4j @@ -109,6 +109,29 @@ function logger(category) { return arr.join(" "); } + /** + * @private + * @param {string} message A message to cut. + * @param {number} maximumLength The maximum length of the message + * @return {string} The shortened message + */ + function shortenText(message, maximumLength) { + if (typeof message !== 'string') { + message = Stringify(message); + } + if (typeof maximumLength !== 'number') { + maximumLength = 3; + } + if (Math.ceil(maximumLength) !== maximumLength) { + maximumLength = Math.ceil(maximumLength); + } + + maximumLength = maximumLength > 3 ? maximumLength : 3; + + return message.length <= maximumLength ? message : message.substring(0, maximumLength - 3) + '...'; + } + + // init console as errors from here can not be thrown var console = new console(); @@ -149,6 +172,9 @@ function logger(category) { case "console": this.consoleAppender(); break; + case "text": + this.textAppender(); + break; case "json": this.jsonAppender(); break; @@ -227,20 +253,22 @@ function logger(category) { var settings = new lib_settings(), subscriberKey = subscriberKey || "N/A", dataExtensionName = dataExtensionName || settings.de.logger.Name, + maxMessageLength = settings.de.messageLength || 500, name = [], value = [], fn = this; // only add INFO or above messages to the DE for processing reason if (this.levels[this.message.level].value >= this.levels["INFO"].value) { - + var msg = convert(strip(fn.message.args)); + msg = shortenText(msg, maxMessageLength); // @todo - split message in 4k and iterate with 1/2 2/2 append to front of message var data = { date: Platform.Function.SystemDateToLocalDate(Now()), timestamp: fn.setLogTime(true), id: fn.logId, level: fn.message.level, - message: convert(strip(fn.message.args)), + message: msg, category: fn.category, subscriberKey: subscriberKey }; @@ -303,6 +331,16 @@ function logger(category) { Platform.Response.Write("