Add ability to disable log message sanitization
Some checks failed
build-and-test / test (push) Failing after 1m19s
build-and-test / generate-javadoc (push) Failing after 1m21s
build-and-test / build (push) Failing after 1m23s

This commit is contained in:
JeremyStar™ 2024-12-04 22:22:40 +01:00
parent a392e8eb48
commit f76878f067
Signed by: JeremyStarTM
GPG key ID: E366BAEF67E4704D
2 changed files with 57 additions and 6 deletions

View file

@ -61,6 +61,49 @@ public final class Logger {
@Setter
private static @NotNull LoggingAdapter loggingAdapter = new PlainLoggingAdapter();
/**
* Contains if messages shall be
* sanitized during processing.
* <p>
* Enabling this flag will prevent
* tag usage and with that formatting.
* <p>
* Recommended to leave enabled. Only
* disable if you are developing a
* command line application.
*
* @since v1-alpha0
* -- GETTER --
* Returns if messages shall be
* sanitized during processing.
* <p>
* Enabling this flag will prevent
* tag usage and with that formatting.
* <p>
* Recommended to leave enabled. Only
* disable if you are developing a
* command line application.
*
* @return sanitize messages?
* @since v1-alpha0
* -- SETTER --
* Sets if messages shall be
* sanitized during processing.
* <p>
* Enabling this flag will prevent
* tag usage and with that formatting.
* <p>
* Recommended to leave enabled. Only
* disable if you are developing a
* command line application.
*
* @param sanitizeMessages sanitize messages?
* @since v1-alpha0
*/
@Getter
@Setter
private static boolean sanitizeMessages = true;
/**
* Creates and initializes an instance of this class
*

View file

@ -125,7 +125,7 @@ public final class Processor {
if (isFeatureEnabled("level") && isFeatureEnabled("origin"))
output.append(" ");
if (isFeatureEnabled("origin")) {
issuerClass(output, level, issuer);
issuerClass(output, issuer);
issuerModule(output, level, issuer);
methodName(output, level, issuer);
lineNumber(output, level, issuer);
@ -270,11 +270,10 @@ public final class Processor {
* Adds the {@code issuer class} component.
*
* @param builder {@link StringBuilder} instance to append to
* @param level level of the log call
* @param issuer {@link StackTraceElement} of the issuer
* @since v1-alpha8
*/
private static void issuerClass(@NotNull StringBuilder builder, @NotNull LogLevel level, @NotNull StackTraceElement issuer) {
private static void issuerClass(@NotNull StringBuilder builder, @NotNull StackTraceElement issuer) {
format(builder, "bold");
if (isFeatureEnabled("shortIssuerClass")) {
@ -351,12 +350,21 @@ public final class Processor {
* @since v1-alpha8
*/
private static void message(@NotNull StringBuilder builder, @NotNull String message) {
builder.append(sanitizeFormat(handlePlaceholders(
String finalizedMessage = handlePlaceholders(
message.replace(
"\n",
"\n" + " ".repeat(new EmptyShortcodeParser(builder.toString(), true).getClean().length())
"\n" + " ".repeat(
new EmptyShortcodeParser(builder.toString(), true)
.getClean()
.length()
)
)
)));
);
if (Logger.isSanitizeMessages())
finalizedMessage = sanitizeFormat(finalizedMessage);
builder.append(finalizedMessage);
}
// -----> Utility methods