How Can I print a message to Knime Console from Java Snippet?

I would like to print a message from a Snippet to the console. How is it possible to achieve this?

Thank you

http://tech.knime.org/forum/knime-general/nodelogger-in-jsnippet

Thank you  very much ;-)

that page doesn’t exist anymore, can you update the link please :grin:

I think there is a consoleLog method now. I don’t have access to knime atm but try typing console and then hitting ctrl and space to get the suggestions.

I also wanted to do this, and I just found out how. In a Java Snippet (not a Java Snippet (simple)):

import org.knime.core.node.NodeLogger;

NodeLogger nl = NodeLogger.getLogger(AbstractJSnippet.class);
if (ROWINDEX==0) nl.warn("Help I am stuck in a KNIME workflow");

I found the answer here: http://script-orgmedchem.blogspot.com/

3 Likes

Thanks Aswin,

Also found that “info” doesn’t show up in the console, you have to use “warn” or the other ones. There is another thread that said this can be changed in the knime settings but didn’t want to turn it on since “info” probably turns on a bunch of stuff I don’t want to see :laughing:

nl.info("your message");

You don’t need to import the node logger anymore. Simple use one of the following:

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

Hi

Is there a way to get the name and nodeID of the current node so that I can include it in the log message?

Thanks

David

My console says

WARN  Java Snippet         0:8403     This is my warn message

Isn’t the 8403 the nodeID?

Hi Aswin, thanks for the reply.

Do you know if it is possible to get name of the node, maybe from the nodeID?

My workflows have deep layers of wrapped metanodes. So when I get an error, currently it looks like this - 9:32:0:311:0:64:0:110:0:138:0:130:0:93

I would like a way to translate that to the names of the metanodes. I know the metanode names are no unique, as I can have template nodes that are repeated, for example, but it will be simpler to follow as the names are descriptive.

Do you know if how I can get such a mapping?

Thanks

David

What you want is basically this feature request :slightly_smiling_face: : https://forum.knime.com/t/search-a-node-in-a-knime-workflow-by-id-goto-focus-a-node-by-id/14495/2 by @andres_sommerh. I don’t think it has been implemented already, so we will have to wait until it appears in a future version of Knime. Until then, I think your best bet is to search the workflow directory tree from your OS’s file browser or shell window.

1 Like

Thanks for pointing that out. I did have a recursive nodes looking through the xml to do this to help with a generic log trace, but it took a rather long time. Would definitely nice to have something internal. Fingers crossed.

David

Hi David,

I have added +1 on this feature request.

Tnx for feedback and have a nice day,
Ivan

1 Like