Skip to content

Commit

Permalink
Add improvements to JsLogger to support Graal
Browse files Browse the repository at this point in the history
  • Loading branch information
dewniMW committed Jun 25, 2024
1 parent 7f16bb6 commit b3e294d
Showing 1 changed file with 69 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import org.wso2.carbon.identity.central.log.mgt.utils.LoggerUtils;
import org.wso2.carbon.utils.DiagnosticLog;

import java.util.Arrays;

/**
* Logger For javascript engine.
* Supports Log.log, Log.warn, Log.error and Log.info
Expand Down Expand Up @@ -94,6 +96,24 @@ public void debug(String value) {
}
}

@HostAccess.Export
public void debug(Object... values) {

if (values != null) {
String resultMessage = "";
if (values.length == 0) {
logger.debug("");
} else if (values.length == 1) {
resultMessage = String.valueOf(values[0]);
logger.debug(resultMessage);
} else {
resultMessage = String.join(",", Arrays.stream(values).map(String::valueOf).toArray(String[]::new));
logger.debug(resultMessage);
}
logDiagnosticEvent("Debug: " + resultMessage, DiagnosticLog.ResultStatus.SUCCESS);
}
}

@HostAccess.Export
public void info(String value) {

Expand All @@ -108,6 +128,24 @@ public void info(String value) {
}
}

@HostAccess.Export
public void info(Object... values) {

if (values != null) {
String resultMessage = "";
if (values.length == 0) {
logger.info("");
} else if (values.length == 1) {
resultMessage = String.valueOf(values[0]);
logger.info(resultMessage);
} else {
resultMessage = String.join(",", Arrays.stream(values).map(String::valueOf).toArray(String[]::new));
logger.info(resultMessage);
}
logDiagnosticEvent("Info: " + resultMessage, DiagnosticLog.ResultStatus.SUCCESS);
}
}

@HostAccess.Export
public void error(String value) {

Expand All @@ -122,8 +160,39 @@ public void error(String value) {
}
}

@HostAccess.Export
public void error(Object... values) {

if (values != null) {
String resultMessage = "";
if (values.length == 0) {
logger.error("");
} else if (values.length == 1) {
resultMessage = String.valueOf(values[0]);
logger.error(resultMessage);
} else {
resultMessage = String.join(",", Arrays.stream(values).map(String::valueOf).toArray(String[]::new));
logger.error(resultMessage);
}
logDiagnosticEvent("Error: " + resultMessage, DiagnosticLog.ResultStatus.FAILED);

}
}

@HostAccess.Export
public void log(String message, Object... values) {

}

private void logDiagnosticEvent(String resultMessage, DiagnosticLog.ResultStatus resultStatus) {

if (LoggerUtils.isDiagnosticLogsEnabled()) {
LoggerUtils.triggerDiagnosticLogEvent(new DiagnosticLog.DiagnosticLogBuilder(
FrameworkConstants.LogConstants.AUTHENTICATION_FRAMEWORK,
FrameworkConstants.LogConstants.AUTH_SCRIPT_LOGGING)
.resultMessage(resultMessage)
.logDetailLevel(DiagnosticLog.LogDetailLevel.APPLICATION)
.resultStatus(resultStatus));
}
}
}

0 comments on commit b3e294d

Please sign in to comment.