How can I enable logging or console printing when testing our plugins in "black box" knime.exe

#1

I have our build creating plugins with all the proper version and qualifier info for equinox.p2,
The plugins deploy from “dropins” in the black box knime and run.
And I have a script to launch knime and connect remote debugging to it and all debugger functions work on our plugins, breakpoints etc. For testing I used the sample NumberFormatter where I changed the package and symbolic names to another package.

It seems I have just one nut left in I have not been able to see where-how to configure the logger “NodeLogger” and/or log4j or get access to stdout for knime.exe

I put the line

-Dlog4j.configuration=C:/Program Files/KNIME/didiLog4j.properties

in the knime.ini file ( does the path need to be in another format or ? ) no startup errors were reported. I saw a post about doing this to direct it to a different log4j.properties.

didiLog4j.properties contains:

# $Id: log4j.properties 3842 2009-02-09 00:27:43Z peterk $
#
log4j.rootLogger=info, A1

# Appender A1 writes to stdout…
#
log4j.appender.A1=org.apache.log4j.ConsoleAppender

log4j.appender.A1.layout=org.apache.log4j.PatternLayout

# format for “clickable” log entries in the intellij debug console
# log4j.appender.A1.layout.ConversionPattern=at %c.%M(%F:%L), %m%n

log4j.appender.A1.layout.ConversionPattern=%-17c{2} (%13F:%L), %m%n

# log4j.appender.A1.layout.ConversionPattern=%d %-5p [%t] %-17c{2} (%13F:%L) %3x - %m%n

log4j.logger.com.artd=debug
log4j.logger.com.didi=debug

In my test plugin I have in the “NodeModel” class, the lines:

private static final NodeLogger LOGGER = NodeLogger.getLogger(NumberFormatterNodeModel.class);
private static final Logger log = Logger.getLogger(NumberFormatterNodeModel.class);

and this in the “execute” method.

LOGGER.info(“This is an example info.”);
log.debug(“a post to log4j in KNIME”);
System.out.println(“println from knime plugin”);

The plugin loads and ruins, and when executed hits a breakpoint I put in the execute method and I can step through the above calls.

When knime.exe is run from the command line nothing appears on the console that it is run from and nothing appears in any of the consoles in knime itself. ( this is all in windows 10-pro BTW )

I tried it with each type of print independently and then all at once, it doesn’t work in any case.

Basically I need to know how to enable logging either to the console or to a file which I can put a “tail” on.

PK

0 Likes

#2

Is your console in KAP configured in the preferences to log at INFO (by default it’s set to WARN)?

0 Likes

#3

Complete guess if @quaeler’s response doesn’t solve it:

do you need to add -consolelog to your run command for KNIME?

If I call

$ knime.exe -consolelog I get an additional window:

1 Like

#4

I will check - but as I’m calling a LOGGER.info(“message”) and it doesn’t show up that is not likely it.
PK

0 Likes

#5

I can not locate any “console preferences” menu entry or icon. either in the context of the console tab at the bottom or in the menus on the top. The “help” search for “logger” and “logging” find no entries. and “console” returns 19 unrelated entries.

0 Likes

#6

the -consolelog command line argument does enable the LOGGER.info, and the log.info message message, and shows the System.out.println, in the additional console the knime now opens.

But the properties file I specified in the

C:/Program Files/KNIME/didiLog4j.properties file does not override whatever defaults for “loglevel” are present, and “debug” messages do not show up.

I’m not sure if the file is read and not acted upon or if it does not override or add to the defaults if it is.
so I need to find the “console preferences” :slight_smile:

0 Likes

#7

Also: In the main menu “file”->“preferences”->“Run/Debug”->“console” panel there are no fields to set the log level, default or otherwise.

0 Likes

#8

Off the top of my head it’s File > preferences >, knime then in here somewhere. There’s an option for the log file and an option for the console to set the level.

I’ve never tried to change the logging config more than changing the output level though so probably can’t be much help

Cheers

Sam

0 Likes

#9

There is one clue maybe? on startup.

root (NodeLogger.java:328), Could not find ‘logfile’ appender

maybe I have to add a specific appender to my log4j.properties file ?
Is there a sample properties file I can use as a template ?

0 Likes

#10

i’d advise not messing with defining your own log4j properties and sticking with the NodeLogger.

0 Likes

#11

interesting behavior:

With the default KNIME GUI settings the level is INFO and all info messages go to the command line specified console window (stdout)

If I change it to DEBUG, messages DO NOT go to that window but to the console window in the UI in the console tabs, and it displays ALL the debug messages internal to knime as well as my plugin so it’s quite a spew, though I can probably turn off the checkboxes for what messages are displayed to cut it down.

But there is no way like in the .properties file to filter messages by package or class.

Anyway at least I can work with it. :slight_smile:

Thanks !

0 Likes

#12

Just for curiosity, why do you want logging dumped to a ~terminal window?

0 Likes

#13

The goal:

Have logging dumped to A WINDOW I can see realtime.
Either a terminal, or another text console window, I can cut from.
If to stdout can redirect to a file.
If to a file I can “tail” it to see in a window.
Files are good in I can look at a big one after the fact and search through it.

HIGHLY desirable is to be able to select which packages/classes I get messages from to reduce the spew of noise to what I want to look at. This is a feature available via a log4j configuration but it appears some special trick is needed for Knime. Sometimes it is desirable to set one of our library classes to DEBUG and ignore the rest.

I copied the log4j3.xml config file it actually reads on startup, which is installed in the knim- workspace ( I know it is the one used because if I trace through the logger initialization, and I can alter it to produce syntax errors.)

However knime uses a combination of reading this config file AND apparently programmatic setting of things. I have not figured out how to capture DEBUG level messages from our packages and only INFO level from the knime packages. The setting in the Knime GUI panel sets the log level globally FOR ALL PACKAGES for the knime console window, and knime.log. Though there are comments in the default config file indicating selective package/class filters can work, they seem out of date with the reality.

Logging is needed for development because we are in a communications based environment with parallelism and blocking with breakpoints will cause timeouts and other undesired latency artifacts.

0 Likes

#14

The existent log files at .metadata/.log and .metadata/knime/knime.log in your workspace don’t suffice?

0 Likes

#15

They do work, as do the consoles. This is now a solved issue at least with the setting of the log level in the KNIME-GUI panel.

But I did not see any effect from changing the package filter settings in the log4j3.xml file and the spew from knime internals when setting the level to DEBUG is pretty extreme, and since the default format does not put the package in the message I can’t put an after posting filter on a pipe from the output.

0 Likes

#16

Ok - have it sorted.

I had to declare (create) another appender in the log4j3.xml config. I use it for my packages ONLY and declare loggers with the level I want for my packages and filters referencing that appender.

I must LEAVE the GUI setting at INFO otherwise it will override the config.xml settings for the other appenders and give me the massive knime internal debug spew!!!

My appender can’t be directed to the knimeConsole or other knime declared appenders as their log level appears to be managed by the GUI and not configurable in the config file.

AND I have to set the root logger level to “debug” in the config file as well to enable my appender’s log level.

Now it is doing what I need and I can direct it to stdout, stderr, or a file !!!

2 Likes