2 Copyright 2013 IBM Corp.
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
8 http://www.apache.org/licenses/LICENSE-2.0
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
17 <script type="text/x-red" data-template-name="debug">
18 <div class="form-row">
19 <label for="node-input-complete"><i class="fa fa-list"></i> Output</label>
20 <select type="text" id="node-input-complete" style="display: inline-block; width: 250px; vertical-align: top;">
21 <option value="false">payload only</option>
22 <option value="true">complete msg object</option>
25 <div class="form-row">
26 <label for="node-input-console"><i class="fa fa-random"></i> to</label>
27 <select type="text" id="node-input-console" style="display: inline-block; width: 250px; vertical-align: top;">
28 <option value="false">debug tab</option>
29 <option value="true">debug tab and console</option>
32 <div class="form-row">
33 <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
34 <input type="text" id="node-input-name" placeholder="Name">
38 <script type="text/x-red" data-help-name="debug">
39 <p>The Debug node can be connected to the output of any node. It will display the timestamp, <b>msg.topic</b> and <b>msg.payload</b> fields of any messages it receives in the debug tab of the sidebar.
40 <br/>The sidebar can be accessed under the options drop-down in the top right corner.</p>
41 <p>The button to the right of the node will toggle it's output on and off so you can de-clutter the debug window.</p>
42 <p>If the payload is an object it will be stringified first for display and indicate that by saying "(Object) ".</p>
43 <p>If the payload is a buffer it will be stringified first for display and indicate that by saying "(Buffer) ".</p>
44 <p>Selecting any particular message will highlight (in red) the debug node that reported it. This is useful if you wire up multiple debug nodes.</p>
45 <p>Optionally can show the complete msg object - but the screen can get messy.</p>
46 <p>In addition any calls to node.warn or node.error will appear here.</p>
49 <script type="text/javascript">
50 RED.nodes.registerType('debug',{
55 console: {value:"false"},
56 complete: {value:"false"}
59 return this.name||"debug";
61 labelStyle: function() {
62 return this.name?"node_label_italic":"";
72 var label = this.name||"debug";
73 d3.xhr("debug/"+this.id+"/"+(this.active?"enable":"disable")).post(function(err,resp) {
75 if (err.status == 404) {
76 RED.notify("<strong>Error</strong>: debug node not deployed","error");
77 } else if (err.status == 0) {
78 RED.notify("<strong>Error</strong>: no response from server","error");
80 RED.notify("<strong>Error</strong>: unexpected error: ("+err.status+")"+err.response,"error");
82 } else if (resp.status == 200) {
83 RED.notify("Successfully activated: "+label,"success");
84 } else if (resp.status == 201) {
85 RED.notify("Successfully deactivated: "+label,"success");
87 RED.notify("<strong>Error</strong>: unexpected response: ("+resp.status+") "+resp.response,"error");
92 onpaletteadd: function() {
93 var content = document.createElement("div");
94 content.id = "tab-debug";
96 var toolbar = document.createElement("div");
97 toolbar.id = "debug-toolbar";
98 content.appendChild(toolbar);
100 toolbar.innerHTML = '<div class="btn-group pull-right"><a id="debug-tab-clear" title="clear log" class="btn btn-mini" href="#"><i class="fa fa-trash"></i></a></div> ';
102 var messages = document.createElement("div");
103 messages.id = "debug-content";
104 content.appendChild(messages);
106 RED.sidebar.addTab("debug",content);
108 function getTimestamp() {
110 return d.toLocaleString();
113 var sbc = document.getElementById("debug-content");
115 var messageCount = 0;
117 RED._debug = function(msg) {
118 that.handleDebugMessage("",{
124 this.handleDebugMessage = function(t,o) {
125 var msg = document.createElement("div");
126 msg.onmouseover = function() {
127 msg.style.borderRightColor = "#999";
128 var n = RED.nodes.node(o.id);
130 n.highlighted = true;
135 msg.onmouseout = function() {
136 msg.style.borderRightColor = "";
137 var n = RED.nodes.node(o.id);
139 n.highlighted = false;
144 msg.onclick = function() {
145 var node = RED.nodes.node(o.id);
147 RED.view.showWorkspace(node.z);
151 var name = (o.name?o.name:o.id).toString().replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">");
152 var topic = (o.topic||"").toString().replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">");
153 var payload = (o.msg||"").toString().replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">");
154 msg.className = 'debug-message'+(o.level?(' debug-message-level-'+o.level):'');
155 msg.innerHTML = '<span class="debug-message-date">'+getTimestamp()+'</span>'+
156 '<span class="debug-message-name">['+name+']</span>'+
157 (o.topic?'<span class="debug-message-topic">'+topic+'</span>':'')+
158 '<span class="debug-message-payload">'+payload+'</span>';
159 var atBottom = (sbc.scrollHeight-messages.offsetHeight-sbc.scrollTop) < 5;
161 $(messages).append(msg);
163 if (messageCount > 200) {
164 $("#debug-content .debug-message:first").remove();
168 $(sbc).scrollTop(sbc.scrollHeight);
171 RED.comms.subscribe("debug",this.handleDebugMessage);
173 $("#debug-tab-clear").click(function() {
174 $(".debug-message").remove();
176 RED.nodes.eachNode(function(node) {
177 node.highlighted = false;
183 onpaletteremove: function() {
184 RED.comms.unsubscribe("debug",this.handleDebugMessage);
185 RED.sidebar.removeTab("debug");
207 border-bottom: 1px solid #eee;
208 border-left: 8px solid #eee;
209 border-right: 8px solid #eee;
212 .debug-message-date {
216 padding: 1px 5px 1px 1px;
218 .debug-message-topic {
225 .debug-message-name {
231 .debug-message-payload {
236 .debug-message-level-log {
237 border-left-color: #eee;
238 border-right-color: #eee;
240 .debug-message-level-warn {
241 border-left-color: #ffdf9d;
242 border-right-color: #ffdf9d;
244 .debug-message-level-error {
245 border-left-color: #f99;
246 border-right-color: #f99;