{"record":{"id":"713384a49388804f","repo":"pentaho/pentaho-kettle","slug":"the-function-call-writetolog-requires-1-or-2-arguments-713384","errorCode":null,"errorMessage":"The function call writeToLog requires 1 or 2 arguments.","messagePattern":"The function call writeToLog requires 1 or 2 arguments\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java","lineNumber":338,"sourceCode":"              scm.logBasic( strMessage );\n            } else if ( strType.equals( \"d\" ) ) {\n              scm.logDebug( strMessage );\n            } else if ( strType.equals( \"l\" ) ) {\n              scm.logDetailed( strMessage );\n            } else if ( strType.equals( \"e\" ) ) {\n              scm.logError( strMessage );\n            } else if ( strType.equals( \"m\" ) ) {\n              scm.logMinimal( strMessage );\n            } else if ( strType.equals( \"r\" ) ) {\n              scm.logRowlevel( strMessage );\n            }\n          }\n        } catch ( Exception e ) {\n          // Ignore errors\n        }\n        break;\n      default:\n        throw Context.reportRuntimeError( \"The function call writeToLog requires 1 or 2 arguments.\" );\n    }\n  }\n\n  private static boolean isUndefined( Object ArgList ) {\n    return isUndefined( new Object[] { ArgList }, new int[] { 0 } );\n  }\n\n  private static boolean isUndefined( Object[] ArgList, int[] iArrToCheck ) {\n    for ( int i = 0; i < iArrToCheck.length; i++ ) {\n      if ( ArgList[iArrToCheck[i]].equals( Context.getUndefinedValue() ) ) {\n        return true;\n      }\n    }\n    return false;\n  }\n\n  private static boolean isNull( Object ArgList ) {\n    return isNull( new Object[] { ArgList }, new int[] { 0 } );","sourceCodeStart":320,"sourceCodeEnd":356,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/scriptvalues_mod/ScriptValuesAddedFunctions.java#L320-L356","documentation":"writeToLog writes a message to the transformation log, optionally with a log level as the first argument, so it accepts exactly 1 or 2 arguments; any other argument count (including zero, or three) hits the default branch of its switch and throws this error.","triggerScenarios":"writeToLog() with no arguments, or writeToLog(a, b, c) with three arguments, in a Modified Java Script Value step.","commonSituations":"Adding a message parameter to an existing 2-arg call (level, message) producing 3 args; calling it to test without arguments; passing the level and message in the wrong slots then appending extras.","solutions":["Call with 1 or 2 arguments: writeToLog('message') or writeToLog('logRowlevel', 'message').","Use a valid log level constant string ('Basic','Detailed','Error','Debug','Rowlevel') as first argument when using two.","Remove extra parameters; concatenate them into the message instead."],"exampleFix":"// before\nwriteToLog('Debug', 'value=', val, 'id=', id);\n// after\nwriteToLog('Debug', 'value=' + val + ' id=' + id);","handlingStrategy":"validation","validationCode":"function safeLog(level, msg) {\n  if (arguments.length < 1) return;\n  if (arguments.length === 1) writeToLog(String(arguments[0]));\n  else writeToLog(String(level), String(msg));\n}\nsafeLog('Debug', 'value=' + val);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass 1 (message) or 2 (level, message) arguments, never more.","Concatenate multiple values into a single message string.","Use standard level strings: Basic, Detailed, Error, Debug, Rowlevel."],"tags":["javascript","argument-count","logging","pdi-kettle"],"backgroundTag":"missing-required-argument","analyzedSha":"f3058517a153da500bf4551f46d79b91bf8ec552","analyzedAt":"2026-09-13T14:04:16.340Z","contentChangedAt":"2026-09-13T14:04:16.340Z","schemaVersion":2},"datasetVersion":"2026-09-20T23:17:15.980Z"}