Skip to content

Commit

Permalink
Fix transform WriteToLog NPE #4145
Browse files Browse the repository at this point in the history
  • Loading branch information
nadment committed Aug 1, 2024
1 parent 072ba12 commit 441555b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 58 deletions.
38 changes: 14 additions & 24 deletions core/src/main/java/org/apache/hop/core/logging/LogLevel.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,22 @@
import org.apache.hop.metadata.api.IEnumHasCodeAndDescription;

public enum LogLevel implements IEnumHasCodeAndDescription {
NOTHING(0, "Nothing"),
ERROR(1, "Error"),
MINIMAL(2, "Minimal"),
BASIC(3, "Basic"),
DETAILED(4, "Detailed"),
DEBUG(5, "Debug"),
ROWLEVEL(6, "Rowlevel");

private static final Class<?> PKG = LogLevel.class;

public static final String[] logLevelDescriptions = {
BaseMessages.getString(PKG, "LogWriter.Level.Nothing.LongDesc"),
BaseMessages.getString(PKG, "LogWriter.Level.Error.LongDesc"),
BaseMessages.getString(PKG, "LogWriter.Level.Minimal.LongDesc"),
BaseMessages.getString(PKG, "LogWriter.Level.Basic.LongDesc"),
BaseMessages.getString(PKG, "LogWriter.Level.Detailed.LongDesc"),
BaseMessages.getString(PKG, "LogWriter.Level.Debug.LongDesc"),
BaseMessages.getString(PKG, "LogWriter.Level.Rowlevel.LongDesc"),
};
NOTHING(0, "Nothing", "LogWriter.Level.Nothing.LongDesc"),
ERROR(1, "Error", "LogWriter.Level.Error.LongDesc"),
MINIMAL(2, "Minimal", "LogWriter.Level.Minimal.LongDesc"),
BASIC(3, "Basic", "LogWriter.Level.Basic.LongDesc"),
DETAILED(4, "Detailed", "LogWriter.Level.Detailed.LongDesc"),
DEBUG(5, "Debug", "LogWriter.Level.Debug.LongDesc"),
ROWLEVEL(6, "Rowlevel", "LogWriter.Level.Rowlevel.LongDesc");

private final int level;
private final String code;
private final String description;

private LogLevel(int level, String code) {
private LogLevel(int level, String code, String description) {
this.level = level;
this.code = code;
this.description = BaseMessages.getString(LogLevel.class, description);
}

public int getLevel() {
Expand All @@ -61,7 +51,7 @@ public String getCode() {

@Override
public String getDescription() {
return logLevelDescriptions[level];
return description;
}

/**
Expand All @@ -70,8 +60,8 @@ public String getDescription() {
* @return the log level or BASIC if nothing matches.
*/
@Deprecated(since = "2.10")
public static LogLevel getLogLevelForCode(String code) {
return IEnumHasCode.lookupCode(LogLevel.class, code, LogLevel.BASIC);
public static LogLevel getLogLevelForCode(final String code) {
return lookupCode(code);
}

/**
Expand Down Expand Up @@ -164,7 +154,7 @@ public static String[] getLogLevelDescriptions() {
/**
* @return An array of log level codes, sorted by level (0==Nothing, 6=Row Level)
*/
public static String[] logLogLevelCodes() {
public static String[] getLogLevelCodes() {
return IEnumHasCode.getCodes(LogLevel.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public boolean processRow() throws HopException {
}
}
data.fieldnr = data.fieldnrs.length;
data.logLevel = meta.getLogLevel();
data.logLevel = (meta.getLogLevel() == null) ? LogLevel.BASIC : meta.getLogLevel();
data.logMessage = Const.NVL(this.resolve(meta.getLogMessage()), "");
if (!Utils.isEmpty(data.logMessage)) {
data.logMessage += Const.CR + Const.CR;
Expand Down Expand Up @@ -128,35 +128,13 @@ public boolean processRow() throws HopException {
/** Output message to log */
private void setLog(final LogLevel loglevel, final StringBuilder msg) {
switch (loglevel) {
case ERROR:
// Log level = ERREUR
logError(msg.toString());
break;
case MINIMAL:
// Log level = MINIMAL
logMinimal(msg.toString());
break;
case BASIC:
// Log level = BASIC
logBasic(msg.toString());
break;
case DETAILED:
// Log level = DETAILED
logDetailed(msg.toString());
break;
case DEBUG:
// Log level = DEBUG
logDebug(msg.toString());
break;
case ROWLEVEL:
// Log level = ROW LEVEL
logRowlevel(msg.toString());
break;
case NOTHING:
// Log level = NOTHING
break;
default:
break;
case BASIC -> logBasic(msg.toString());
case ERROR -> logError(msg.toString());
case MINIMAL -> logMinimal(msg.toString());
case DETAILED -> logDetailed(msg.toString());
case DEBUG -> logDebug(msg.toString());
case ROWLEVEL -> logRowlevel(msg.toString());
case NOTHING -> {}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,9 +328,11 @@ public void getData() {
wLimitRows.setSelection(input.isLimitRows());
wLimitRowsNumber.setText("" + input.getLimitRowsNumber());

if (input.getLogLevel() != null) {
wLoglevel.select(input.getLogLevel().getLevel());
LogLevel logLevel = input.getLogLevel();
if (logLevel == null) {
logLevel = LogLevel.BASIC;
}
wLoglevel.select(logLevel.getLevel());

if (input.getLogMessage() != null) {
wLogMessage.setText(input.getLogMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public void check(
if (prev == null || prev.size() == 0) {
cr =
new CheckResult(
CheckResult.TYPE_RESULT_WARNING,
ICheckResult.TYPE_RESULT_WARNING,
BaseMessages.getString(PKG, "WriteToLogMeta.CheckResult.NotReceivingFields"),
transformMeta);
remarks.add(cr);
Expand Down Expand Up @@ -209,7 +209,7 @@ public void check(
if (logFields.isEmpty()) {
cr =
new CheckResult(
CheckResult.TYPE_RESULT_WARNING,
ICheckResult.TYPE_RESULT_WARNING,
BaseMessages.getString(PKG, "WriteToLogMeta.CheckResult.NoFieldsEntered"),
transformMeta);

Expand Down

0 comments on commit 441555b

Please sign in to comment.