NodeLogger in JSnippet

Hi,

I would like to use NodeLogger class inside a JSnippet, just to log events in the same way that I do in other nodes I have developed. I have added the knime-core.jar as an external library of the JSnippet and I have written this very simple java content:

// system imports
import org.knime.base.node.jsnippet.expression.AbstractJSnippet;
import org.knime.base.node.jsnippet.expression.Abort;
import org.knime.base.node.jsnippet.expression.Cell;
import org.knime.base.node.jsnippet.expression.ColumnException;
import org.knime.base.node.jsnippet.expression.TypeException;
import static org.knime.base.node.jsnippet.expression.Type.*;
import java.util.Date;
import java.util.Calendar;
import org.w3c.dom.Document;

// Your custom imports:
import org.knime.core.node.NodeLogger;
// system variables
public class JSnippet extends AbstractJSnippet {


// Your custom variables:
private static final NodeLogger logger = NodeLogger.getLogger(JSnippet.class);

// expression start
  public void snippet() throws TypeException, ColumnException, Abort {
// Enter your code here:
logger.error("EXAMPLE ERROR MESSAGE");

// expression end
    }
}


But the node gives the message "Compile with Errors".

Honestly, I am not sure if this is a good approach to log events in a JSnippet, what is typically done in this situations ?

I would appreciate some hint / help to solve this problem.

Thanks in advance

Oscar

Hi, I am facing this same challenge.  And I'm very new to Java, so this is difficult for me to figure out.  Did you find a resolution to do what you needed to do?

Many thanks

Bill Nowlin

There is no need to add the jar as an external library, you just need the import!

I have attached an example workflow on how to do this.

I didn't know what the JSnippet class was so I just went with the AbstractJSnippet.class in the config. 

Cheers

Sam

2 Likes

Wow, Sam, I am feeling the awesomeness!  Maybe I can return the favor sometime.  Thanks very much!

Bill

I am having an issue with the output from the logger. I am trying to implement some feedback to the user in my own node. I thought I can try this with the logger. So I do something like:

logger.info("message")

But the message never shows up in the KNIME console. When I set the log level to info like this:

logger.setLevel(LEVEL.INFO)

The output is at least displayed on the SDK console, but not on the KNIME console. Other logger levels work fine.

How can I get the info output on the KNIME console? Is there a way for an output without the logger?

Are you sure, you are using a NodeLogger? I have no problems writing messages to the KNIME console using that. (Though the setLevel seems to be deprecated, so I think it is better to let the user adjust the logging level there.)

The logger:

	private static final NodeLogger logger = NodeLogger
			.getLogger(MyNodeModel.class);

its just the standard logger, the SDK delivers with the template.

My intention is to deliver information about the node's progress in textual form to the user. I am thankful for any advices on that.

You may have to change the log level in the KNIME preferences. By default only warnings and errors are logged to the KNIME Console.

I have the similar question. Can I print a message on Knime Console from RSnippet? I used "message". It doesn't work.