console.log() doesn't seem to work in Generic JavaScript View node

Hi,

i’m trying to debug codes, but i have a hard time finding errors because console.log doesn’t create any output. I tried with a completely new node which only contains console.log("Hello");, but even this doesn’t show up in the console.

I set LogLevel to debug. I also tried to define an output flow variable, but the cell which should contain “Hello” is empty. I get no error message at all.

Thanks for helping

Hi @gonzo0815 ,

Have you tried taking a look at the knime.log file located : /Users///.metadata/knime/knime.log?

Thanks,
Zack

Are you talking about Java Snippets? If you want to print to the console, you can use these print commands, one for each debug level:

logInfo("This is my info message");
logError("This is my error message");
logDebug("This is my debug message");
logWarn("This is my warn message");

Source:

Well, turns out the question is about JavaScript, I guess I just can’t read :sweat_smile:

Sorry my post was not useful. I was looking for a way to write to the console but didn’t find anything.
logError(“Hello”); obviously doesn’t work.
neither does console.log(“there!”);

If you switch over to the Column Expressions node you’ll even get a nice error message telling you those functions don’t exist:
No function 'logError' with 1 argument(s) defined.

Kind of whacky, but can you try to write your debug messages to the html of the JavaScript view?

2022-04-11 10:14:29,677 : INFO : main : : KNIMECorePlugin : : : Setting console view log level to DEBUG
2022-04-11 10:14:37,034 : DEBUG : main : : NodeContainerEditPart : : : Generic JavaScript View 5:6 (EXECUTED)
2022-04-11 10:14:37,063 : DEBUG : main : : NodeContainerEditPart : : : Generic JavaScript View 5:25 (CONFIGURED)
2022-04-11 10:14:43,769 : DEBUG : main : : ExecuteAction : : : Creating execution job for 1 node(s)…
2022-04-11 10:14:43,794 : DEBUG : main : : NodeContainer : : : Setting dirty flag on Generic JavaScript View 5:25
2022-04-11 10:14:43,817 : DEBUG : main : : NodeContainer : : : Generic JavaScript View 5:25 has new state: CONFIGURED_MARKEDFOREXEC
2022-04-11 10:14:43,840 : DEBUG : main : : NodeContainer : : : Generic JavaScript View 5:25 has new state: CONFIGURED_QUEUED
2022-04-11 10:14:43,864 : DEBUG : main : : NodeContainer : : : Simple_line_Chart 5 has new state: EXECUTING
2022-04-11 10:14:43,889 : DEBUG : KNIME-Worker-98-Generic JavaScript View 5:25 : : WorkflowManager : Generic JavaScript View : 5:25 : Generic JavaScript View 5:25 doBeforePreExecution
2022-04-11 10:14:43,911 : DEBUG : KNIME-Worker-98-Generic JavaScript View 5:25 : : NodeContainer : Generic JavaScript View : 5:25 : Generic JavaScript View 5:25 has new state: PREEXECUTE
2022-04-11 10:14:43,935 : DEBUG : KNIME-Worker-98-Generic JavaScript View 5:25 : : WorkflowDataRepository : Generic JavaScript View : 5:25 : Adding handler d539d9c9-6956-4f73-9785-711921e97c99 (Generic JavaScript View 5:25: ) - 2 in total
2022-04-11 10:14:43,959 : DEBUG : KNIME-Worker-98-Generic JavaScript View 5:25 : : WorkflowManager : Generic JavaScript View : 5:25 : Generic JavaScript View 5:25 doBeforeExecution
2022-04-11 10:14:43,981 : DEBUG : KNIME-Worker-98-Generic JavaScript View 5:25 : : NodeContainer : Generic JavaScript View : 5:25 : Generic JavaScript View 5:25 has new state: EXECUTING
2022-04-11 10:14:44,006 : DEBUG : KNIME-Worker-98-Generic JavaScript View 5:25 : : LocalNodeExecutionJob : Generic JavaScript View : 5:25 : Generic JavaScript View 5:25 Start execute
2022-04-11 10:14:44,097 : DEBUG : KNIME-Worker-98-Generic JavaScript View 5:25 : : Buffer : Generic JavaScript View : 5:25 : Closing input stream on “…\AppData\Local\Temp\knime_Simple_line_Cha97162\knime_container_20220411_9734903582624468403.tmp”, 0 remaining
2022-04-11 10:14:44,120 : INFO : KNIME-Worker-98-Generic JavaScript View 5:25 : : LocalNodeExecutionJob : Generic JavaScript View : 5:25 : Generic JavaScript View 5:25 End execute (0 secs)
2022-04-11 10:14:44,142 : DEBUG : KNIME-Worker-98-Generic JavaScript View 5:25 : : WorkflowManager : Generic JavaScript View : 5:25 : Generic JavaScript View 5:25 doBeforePostExecution
2022-04-11 10:14:44,165 : DEBUG : KNIME-Worker-98-Generic JavaScript View 5:25 : : NodeContainer : Generic JavaScript View : 5:25 : Generic JavaScript View 5:25 has new state: POSTEXECUTE
2022-04-11 10:14:44,189 : DEBUG : KNIME-Worker-98-Generic JavaScript View 5:25 : : WorkflowManager : Generic JavaScript View : 5:25 : Generic JavaScript View 5:25 doAfterExecute - success
2022-04-11 10:14:44,213 : DEBUG : KNIME-Worker-98-Generic JavaScript View 5:25 : : NodeContainer : Generic JavaScript View : 5:25 : Generic JavaScript View 5:25 has new state: EXECUTED
2022-04-11 10:14:44,260 : DEBUG : KNIME-Worker-98-Generic JavaScript View 5:25 : : Node : Variable to Table Row : 5:26 : Configure succeeded. (Variable to Table Row)
2022-04-11 10:14:44,283 : DEBUG : KNIME-Worker-98-Generic JavaScript View 5:25 : : NodeContainer : Generic JavaScript View : 5:25 : Simple_line_Chart 5 has new state: CONFIGURED

I don’t know how to do that, but maybe the knime.log i already posted is sufficient? Like i said, i can’t see anything related to console.log in there. The code only consist of
out=console.log('Hello'); out;

Edit: to be a little more clear about what i’m trying to do. I’m trying to recreate the following tutorial to get into JavaScript/D3 programming: Creating Simple Line Charts Using D3.js - Part 01 | Welcome to Vizartpandey
I obviously need to change some things in the code suggested. Instead of reading a csv i just put the data into a table creator. But i’m struggling with understanding how the dataset is written into variables in the Generic JavaScript view. It seems easier to me to adress the single columns in the dataset with the given commands then to transform it into a JSON-format like the outdated KNIME-Tutorial suggests. But i need to see what the variables actually consist of to continue because the error messages suggest that the variables are not filled with data in a correct way (‘Cannot read property ‘length’ of null’ etc. → seems, that the way i read the column doesn’t create an array but an empty variable)
The tutorial suggests to write ‘console.log(xAccessor)’ to understand what is happening at this point. But as long as this doesn’t generate any output i won’t be able to understand the rest of the code completely.

Sorry for putting this into an additional post, but i can’t edit my other posts anymore.

I found a workaround with the ‘prompt’ command.

I feel that console.log() isn’t supposed to write anything into KNIME-console but is used for interactive consoles like when i open the resulting html-file in a browser. I also can’t get it to run there, but using ‘prompt’ inside Knime will do for now. I’ll still be happy if someone could explain how to write something into KNIME-console because that would still make stuff much easier.