# Debug logs in the editor

**URL:** <https://discourse.nodered.org/t/debug-logs-in-the-editor/75474>\
**Category:** Developing Nodes\
**Created:** [20 February 2023 15:14 UTC](https://discourse.nodered.org/t/debug-logs-in-the-editor/75474 "2023-02-20T15:14:56Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ptweety](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ptweety/32/68053_2.png) [@ptweety](https://discourse.nodered.org/u/ptweety)\
**Post date:** [20 February 2023 15:14 UTC](https://discourse.nodered.org/t/debug-logs-in-the-editor/75474/1 "2023-02-20T15:14:56Z")

</div>

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:

```auto
$.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');
    });

```

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [20 February 2023 18:32 UTC](https://discourse.nodered.org/t/debug-logs-in-the-editor/75474/2 "2023-02-20T18:32:51Z")

</div>

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`.

---

<div class="post-metadata">

**Author:** ![ptweety](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ptweety/32/68053_2.png) [@ptweety](https://discourse.nodered.org/u/ptweety)\
**Post date:** [20 February 2023 20:24 UTC](https://discourse.nodered.org/t/debug-logs-in-the-editor/75474/3 "2023-02-20T20:24:45Z")

</div>

Hi @TotallyInformation

thanks for looking into this topic.

> [@TotallyInformation](#):
>
> 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?

Correct. I'm talking about the `editor`.

> [@TotallyInformation](#):
>
> 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?

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.

> [@TotallyInformation](#):
>
> But if you want logs into the browser console on the editor window, simply use `console`.

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](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/6/e633ba3fc23572591974245f28a5486779de891d.png)

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [20 February 2023 21:05 UTC](https://discourse.nodered.org/t/debug-logs-in-the-editor/75474/4 "2023-02-20T21:05:29Z")

</div>

> [@ptweety](#):
>
> RED.\_debug({topic: "something", payload: "fancy"})

That's one that I didn't know 🙂

> [@ptweety](#):
>
> 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.

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.

> <https://github.com/TotallyInformation/node-red-contrib-uibuilder/blob/main/src/front-end-module/uibuilder.module.js#L72-L217>

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [21 April 2023 21:05 UTC](https://discourse.nodered.org/t/debug-logs-in-the-editor/75474/5 "2023-04-21T21:05:42Z")

</div>

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