Debug logs in the editor

Hi all,

I wonder how I can enable users of my custom node to have extended debug output in the editor. Basically I'm looking for an option how a user can enable certain log level in the browser console, so that my frontend code of the node can send more detailed debug messages to the console.

It's quite clear to me that the runtime has it's options in settings.js for the log level. But is there something similar if it comes to the editor and the browser console?

Any advice or best practice how to handle this is much appreciated.

EDIT: let me add an example. Maybe this helps in understanding my question:

$.getJSON(url)
  .done((responseJSON) => {
    // do something
    if (debugFlag) // <- this is what I'm looking for to be set by the user
      console.debug('some message')
    })
    .fail((jqXHR, textStatus, error) => {
      console.dir({ jqXHR, textStatus, error });
      RED.notify(`Request failed with: ${jqXHR.status} (${error})`, 'error');
    });

This is debug output from the workings of the custom node itself? That get is happening within the editor rather than the runtime I assume?

Hopefully someone knows a better way than this but RED.log isn't available in the editor so I don't know of an easy way. I think you might need to create an API in your runtime js code that outputs to debug. Then you can call that from code in your Editor html file.

The node-red core debug node should show you how to output to the debug panel if that's what you want. I think by default only node.warn and node.error (RED.log.warn, RED.log.error) appear in the debug sidebar?

But if you want logs into the browser console on the editor window, simply use console.

Hi @TotallyInformation

thanks for looking into this topic.

Correct. I'm talking about the editor.

I could post from the editor to the debug panel like this: RED._debug({topic: "something", payload: "fancy"}). But this is not what I'm after.

This is what I did. But if I log all my debug messages I will overwhelm the browser console with a bunch of messages. I just want to have a flag a user can set (in the console) to activate/deactivate these debug messages.

Unfortunately there is no such thing as a simple config setting for the browser console that I know of.

I tried to send DEBUG = true from the browser console and check from the editor if this variable exists and is true, but that doesn't seem right to me.

Bildschirm­foto 2023-02-20 um 21.23.39

That's one that I didn't know :slight_smile:

Right, well I've done something like this in the uibuilder client library so you could grab that and use it as a common fn in your editor code.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.