|
525
|
1 |
<!DOCTYPE html> |
|
|
2 |
<html lang="en"> |
|
|
3 |
<head> |
|
|
4 |
<meta charset="utf-8"> |
|
|
5 |
<title>Console</title> |
|
|
6 |
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=PT+Sans:400,700,400italic,700italic"> |
|
|
7 |
<link rel="stylesheet" href="../../build/cssgrids/cssgrids-min.css"> |
|
|
8 |
<link rel="stylesheet" href="../assets/css/main.css"> |
|
|
9 |
<link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css"> |
|
|
10 |
<link rel="shortcut icon" type="image/png" href="../assets/favicon.png"> |
|
|
11 |
<script src="../../build/yui/yui-min.js"></script> |
|
|
12 |
|
|
|
13 |
</head> |
|
|
14 |
<body> |
|
|
15 |
<!-- |
|
|
16 |
<a href="https://github.com/yui/yui3"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" alt="Fork me on GitHub"></a> |
|
|
17 |
--> |
|
|
18 |
<div id="doc"> |
|
|
19 |
<div id="hd"> |
|
|
20 |
<h1><img src="http://yuilibrary.com/img/yui-logo.png"></h1> |
|
|
21 |
</div> |
|
|
22 |
|
|
|
23 |
<a href="#toc" class="jump">Jump to Table of Contents</a> |
|
|
24 |
|
|
|
25 |
|
|
|
26 |
<h1>Console</h1> |
|
|
27 |
<div class="yui3-g"> |
|
|
28 |
<div class="yui3-u-3-4"> |
|
|
29 |
<div id="main"> |
|
|
30 |
<div class="content"><div class="intro component" style="overflow: hidden;"> |
|
|
31 |
<p> |
|
|
32 |
<img alt="Screen capture of the Console UI" |
|
|
33 |
src="../assets/console/images/small.png" |
|
|
34 |
height="203" width="200" style="border: 0 none; float: right; margin-left: 2em;"> |
|
|
35 |
|
|
|
36 |
The Console tool provides a display to read log messages emitted by the |
|
|
37 |
YUI logging subsytem. With this tool, you can tap into the rich |
|
|
38 |
event-driven messages included with the YUI Library's debug files. |
|
|
39 |
This messaging allows you to get a fuller picture of the inner workings |
|
|
40 |
of any YUI Library component. |
|
|
41 |
</p> |
|
|
42 |
|
|
|
43 |
<p> |
|
|
44 |
Additionally, when building your own Widgets, utilities or |
|
|
45 |
applications, you can include your own log statements and use the |
|
|
46 |
Console to aid in development and debugging. As a simple message |
|
|
47 |
display mechanism, you can also repurpose Console through extention or |
|
|
48 |
configuration to listen to a different input source and display |
|
|
49 |
messages differently. |
|
|
50 |
</p> |
|
|
51 |
</div> |
|
|
52 |
|
|
|
53 |
<h2 id="getting-started">Getting Started</h2> |
|
|
54 |
|
|
|
55 |
<p> |
|
|
56 |
To include the source files for Console and its dependencies, first load |
|
|
57 |
the YUI seed file if you haven't already loaded it. |
|
|
58 |
</p> |
|
|
59 |
|
|
|
60 |
<pre class="code prettyprint"><script src="http://yui.yahooapis.com/3.10.3/build/yui/yui-min.js"></script></pre> |
|
|
61 |
|
|
|
62 |
|
|
|
63 |
<p> |
|
|
64 |
Next, create a new YUI instance for your application and populate it with the |
|
|
65 |
modules you need by specifying them as arguments to the <code>YUI().use()</code> method. |
|
|
66 |
YUI will automatically load any dependencies required by the modules you |
|
|
67 |
specify. |
|
|
68 |
</p> |
|
|
69 |
|
|
|
70 |
<pre class="code prettyprint"><script> |
|
|
71 |
// Create a new YUI instance and populate it with the required modules. |
|
|
72 |
YUI().use('console', function (Y) { |
|
|
73 |
// Console is available and ready for use. Add implementation |
|
|
74 |
// code here. |
|
|
75 |
}); |
|
|
76 |
</script></pre> |
|
|
77 |
|
|
|
78 |
|
|
|
79 |
<p> |
|
|
80 |
For more information on creating YUI instances and on the |
|
|
81 |
<a href="http://yuilibrary.com/yui/docs/api/classes/YUI.html#method_use"><code>use()</code> method</a>, see the |
|
|
82 |
documentation for the <a href="../yui/index.html">YUI Global Object</a>. |
|
|
83 |
</p> |
|
|
84 |
|
|
|
85 |
|
|
|
86 |
<h3 id="sam">Trigger the CSS skin</h3> |
|
|
87 |
|
|
|
88 |
<p> |
|
|
89 |
For the default "Sam" skin to apply to the Console UI, you'll |
|
|
90 |
need to apply the <code>yui3-skin-sam</code> class name to an element that |
|
|
91 |
is a parent of the element in which the Console lives. You can usually |
|
|
92 |
accomplish this simply by putting the class on the |
|
|
93 |
<code><body></code> tag: |
|
|
94 |
</p> |
|
|
95 |
|
|
|
96 |
<pre class="code prettyprint"><body class="yui3-skin-sam"></pre> |
|
|
97 |
|
|
|
98 |
|
|
|
99 |
<p> |
|
|
100 |
For more information on skinning YUI components and making use of default |
|
|
101 |
skins, see our |
|
|
102 |
<a href="http://yuilibrary.com/yui/docs/tutorials/skins/">Understanding |
|
|
103 |
YUI Skins</a> tutorial. |
|
|
104 |
</p> |
|
|
105 |
|
|
|
106 |
<h2 id="logging">The YUI logging subsystem</h2> |
|
|
107 |
|
|
|
108 |
<p> |
|
|
109 |
The entry point to YUI's logging subsystem is the YUI instance's <code>log(..)</code> method. |
|
|
110 |
</p> |
|
|
111 |
|
|
|
112 |
<pre class="code prettyprint">// message category source |
|
|
113 |
Y.log("Hello world!", "info", "myapp");</pre> |
|
|
114 |
|
|
|
115 |
|
|
|
116 |
<p> |
|
|
117 |
If the YUI instance is configured with <code>debug</code> set to |
|
|
118 |
<code>true</code> (the default), any calls to <code>Y.log(..)</code> will |
|
|
119 |
be printed to the browser's native <code>console</code> if it has one, and |
|
|
120 |
broadcast through the <code>yui:log</code> event. |
|
|
121 |
</p> |
|
|
122 |
|
|
|
123 |
<p> |
|
|
124 |
When a Console is instantiated, the native console reporting of YUI log |
|
|
125 |
messages is disabled in favor of reporting in the Console UI. If you wish |
|
|
126 |
to preserve native console reporting, set the |
|
|
127 |
<code>useBrowserConsole</code> configuration attribute to <code>true</code> |
|
|
128 |
during Console construction. |
|
|
129 |
</p> |
|
|
130 |
|
|
|
131 |
<h2 id="using">Using the Console Widget</h2> |
|
|
132 |
|
|
|
133 |
<h3 id="setup">Instantiating and configuring a Console</h3> |
|
|
134 |
|
|
|
135 |
<h4 id="instantiation">Instantiation</h4> |
|
|
136 |
|
|
|
137 |
<p> |
|
|
138 |
Creating an instance of Console is very easy; there are no required |
|
|
139 |
configuration attributes, and it is typically rendered without reference to |
|
|
140 |
an existing DOM element. |
|
|
141 |
</p> |
|
|
142 |
|
|
|
143 |
<pre class="code prettyprint">YUI({..}).use('console', function (Y) { |
|
|
144 |
|
|
|
145 |
// Console has no required configuration |
|
|
146 |
var yconsole = new Y.Console(); |
|
|
147 |
|
|
|
148 |
yconsole.render(); |
|
|
149 |
|
|
|
150 |
// In fact, you often don't even need to store the instance |
|
|
151 |
new Y.Console().render(); |
|
|
152 |
|
|
|
153 |
/* YOUR CODE HERE */ |
|
|
154 |
});</pre> |
|
|
155 |
|
|
|
156 |
|
|
|
157 |
<p> |
|
|
158 |
By default, Console instances are positioned absolutely in the top right |
|
|
159 |
corner of the page. As seen below and in the examples, this is configurable by |
|
|
160 |
setting the <code>style</code> attribute. |
|
|
161 |
</p> |
|
|
162 |
|
|
|
163 |
<h4 id="config">Common configuration attributes</h4> |
|
|
164 |
|
|
|
165 |
<p> |
|
|
166 |
Below are some common configuration attributes. Refer to the API docs for |
|
|
167 |
a complete list of configuration options. |
|
|
168 |
</p> |
|
|
169 |
|
|
|
170 |
<table> |
|
|
171 |
<thead> |
|
|
172 |
<tr> |
|
|
173 |
<th>Attribute</th> |
|
|
174 |
<th>Description</th> |
|
|
175 |
<th>Default</th> |
|
|
176 |
</tr> |
|
|
177 |
</thead> |
|
|
178 |
<tbody> |
|
|
179 |
<tr> |
|
|
180 |
<td><code>logLevel</code></td> |
|
|
181 |
<td>Set to "warn" or "error" to omit messages of lesser severity</td> |
|
|
182 |
<td>"info"</td> |
|
|
183 |
</tr> |
|
|
184 |
<tr> |
|
|
185 |
<td><code>newestOnTop</code></td> |
|
|
186 |
<td>Set to false to place new messages <em>below</em> prior messages</td> |
|
|
187 |
<td>true</td> |
|
|
188 |
</tr> |
|
|
189 |
<tr> |
|
|
190 |
<td><code>consoleLimit</code></td> |
|
|
191 |
<td>Limit the number of messages displayed in the UI</td> |
|
|
192 |
<td>300</td> |
|
|
193 |
</tr> |
|
|
194 |
<tr> |
|
|
195 |
<td><code>height</code></td> |
|
|
196 |
<td>Specify the height of the Console. Useful for displaying more messages</td> |
|
|
197 |
<td>"300px"</td> |
|
|
198 |
</tr> |
|
|
199 |
<tr> |
|
|
200 |
<td><code>style</code></td> |
|
|
201 |
<td>Relationship of the Console to the page content. Supported values are "inline", "block", and "separate"</td> |
|
|
202 |
<td>"separate" (absolute positioned in the top right corner)</td> |
|
|
203 |
</tr> |
|
|
204 |
</tbody> |
|
|
205 |
</table> |
|
|
206 |
|
|
|
207 |
<h4 id="buffer">The print loop</h4> |
|
|
208 |
|
|
|
209 |
<p> |
|
|
210 |
Incoming log messages are buffered and printed in a scheduled batch cycle |
|
|
211 |
to lessen the impact to the normal operation of the page. The print loop |
|
|
212 |
renders a fixed number of buffered messages at a time. |
|
|
213 |
</p> |
|
|
214 |
|
|
|
215 |
<p> |
|
|
216 |
The print loop behavior can be configured with the |
|
|
217 |
<code>printTimeout</code> and <code>printLimit</code> configuration |
|
|
218 |
attributes. The former controls the millisecond timeout between iterations |
|
|
219 |
of the print loop. The latter limits the number of entries to add to the |
|
|
220 |
Console in each iteration of the print loop. By default their respective |
|
|
221 |
values are 100 and 50. |
|
|
222 |
</p> |
|
|
223 |
|
|
|
224 |
<h4 id="universal">Share a Console between YUI instances</h4> |
|
|
225 |
|
|
|
226 |
<p> |
|
|
227 |
Console behaves like any other YUI module and remains sandboxed inside the |
|
|
228 |
particular YUI instance that spawned it. However, it is possible to create |
|
|
229 |
a universal Console to report the activity in the logging subsystems of |
|
|
230 |
every YUI instance on the page. |
|
|
231 |
</p> |
|
|
232 |
|
|
|
233 |
<p> |
|
|
234 |
To support cross YUI instance communication, a shared global EventTarget |
|
|
235 |
named <code>Y.Global</code> is exposed on every YUI instance, and |
|
|
236 |
<code>yui:log</code> events are configured to bubble to this |
|
|
237 |
EventTarget. |
|
|
238 |
</p> |
|
|
239 |
|
|
|
240 |
<p> |
|
|
241 |
Console has attributes <code>logSource</code> and <code>logEvent</code> |
|
|
242 |
that can be used to link the Console instance up to an entirely different |
|
|
243 |
messaging subsystem. By setting the Console's <code>logSource</code> to |
|
|
244 |
<code>Y.Global</code> and leaving the <code>logEvent</code> alone, the |
|
|
245 |
single Console instance will receive log messages from every YUI instance |
|
|
246 |
on the page. |
|
|
247 |
</p> |
|
|
248 |
|
|
|
249 |
<pre class="code prettyprint">YUI().use('console','overlay', function (Y) { |
|
|
250 |
|
|
|
251 |
// Create a universal Console |
|
|
252 |
new Y.Console({ logSource: Y.Global }).render(); |
|
|
253 |
|
|
|
254 |
/* YOUR CODE HERE */ |
|
|
255 |
|
|
|
256 |
}); |
|
|
257 |
|
|
|
258 |
YUI().use('dd', function (Y) { |
|
|
259 |
|
|
|
260 |
// Y.log statements here will be reported in the Console generated in the |
|
|
261 |
// other YUI instance. |
|
|
262 |
|
|
|
263 |
});</pre> |
|
|
264 |
|
|
|
265 |
|
|
|
266 |
<p> |
|
|
267 |
Look at the <a href="console-global.html">Creating a |
|
|
268 |
universal Console</a> example for reference. |
|
|
269 |
</p> |
|
|
270 |
|
|
|
271 |
<h3 id="display">Console display</h3> |
|
|
272 |
|
|
|
273 |
<h4 id="anatomy-of-the-console">Anatomy of the Console</h4> |
|
|
274 |
|
|
|
275 |
<p> |
|
|
276 |
The Console has a very simple display, split into a header, body, and |
|
|
277 |
footer. |
|
|
278 |
</p> |
|
|
279 |
|
|
|
280 |
<img src="../assets/console/images/console_anatomy.png" alt="visual demarcation of Console's header, body, and footer"> |
|
|
281 |
|
|
|
282 |
<p> |
|
|
283 |
The default placement of a Console is absolutely positioned in the top |
|
|
284 |
right corner of the page. This can be configured with the |
|
|
285 |
<code>style</code> attribute. The <a |
|
|
286 |
href="console-basic.html">Creating a Console for |
|
|
287 |
debugging</a> example illustrates how to accomplish this. |
|
|
288 |
</p> |
|
|
289 |
|
|
|
290 |
<h4 id="anatomy">Anatomy of a message</h4> |
|
|
291 |
|
|
|
292 |
<p> |
|
|
293 |
Incoming log messages are normalized to objects with the following |
|
|
294 |
properties: |
|
|
295 |
</p> |
|
|
296 |
|
|
|
297 |
<table> |
|
|
298 |
<thead> |
|
|
299 |
<tr> |
|
|
300 |
<th>Property</th> |
|
|
301 |
<th>Description</th> |
|
|
302 |
</tr> |
|
|
303 |
</thead> |
|
|
304 |
<tbody> |
|
|
305 |
<tr> |
|
|
306 |
<td><code>message</code></td> |
|
|
307 |
<td>The message text</td> |
|
|
308 |
</tr> |
|
|
309 |
<tr> |
|
|
310 |
<td><code>category</code></td> |
|
|
311 |
<td>The category or log level of the message (e.g. "info", "warn", or "note")</td> |
|
|
312 |
</tr> |
|
|
313 |
<tr> |
|
|
314 |
<td><code>source</code></td> |
|
|
315 |
<td>The name of the source module</td> |
|
|
316 |
</tr> |
|
|
317 |
<tr> |
|
|
318 |
<td><code>localTime</code></td> |
|
|
319 |
<td>The time the message was received</td> |
|
|
320 |
</tr> |
|
|
321 |
<tr> |
|
|
322 |
<td><code>elapsedTime</code></td> |
|
|
323 |
<td>The time elapsed since the last message was received</td> |
|
|
324 |
</tr> |
|
|
325 |
<tr> |
|
|
326 |
<td><code>totalTime</code></td> |
|
|
327 |
<td>The time elapsed since the Console was instantiated</td> |
|
|
328 |
</tr> |
|
|
329 |
</tbody> |
|
|
330 |
</table> |
|
|
331 |
|
|
|
332 |
<p> |
|
|
333 |
These message objects are eventually rendered into the Console body like |
|
|
334 |
this: |
|
|
335 |
</p> |
|
|
336 |
|
|
|
337 |
<img src="../assets/console/images/message_anatomy.png" alt="visual demarcation of the various parts of a Console entry"> |
|
|
338 |
|
|
|
339 |
<p> |
|
|
340 |
Log messages from the standard <code>logLevel</code> categories |
|
|
341 |
"info", "warn", and "error" get special |
|
|
342 |
visual treatment. Specifically, the category is omitted from the message |
|
|
343 |
meta and "warn" and "error" messages include an icon |
|
|
344 |
and specific coloring. |
|
|
345 |
</p> |
|
|
346 |
|
|
|
347 |
<img src="../assets/console/images/info_warn_error.png" alt="One of each info, warn, and error type messages"> |
|
|
348 |
|
|
|
349 |
<h3 id="controls">Console interaction</h3> |
|
|
350 |
|
|
|
351 |
<h4 id="collapse">Collapsing, expanding, hiding and showing</h4> |
|
|
352 |
|
|
|
353 |
<p> |
|
|
354 |
Collapse and expand the Console with the Collapse/Expand button in the |
|
|
355 |
header or by setting the <code>collapsed</code> attribute to |
|
|
356 |
<code>true</code> or calling the instance's <code>collapse()</code> and |
|
|
357 |
<code>expand()</code> methods. |
|
|
358 |
</p> |
|
|
359 |
|
|
|
360 |
<img src="../assets/console/images/collapsed.png" alt="A collapsed Console"> |
|
|
361 |
|
|
|
362 |
<p> |
|
|
363 |
Calling the instance's <code>hide()</code> method will entirely remove the |
|
|
364 |
UI from the page. <code>show()</code> will cause it to reappear. |
|
|
365 |
</p> |
|
|
366 |
|
|
|
367 |
<h4 id="pause">Pausing</h4> |
|
|
368 |
|
|
|
369 |
<p> |
|
|
370 |
Pause the Console with either the checkbox in the Console footer or by |
|
|
371 |
setting the <code>paused</code> attribute. |
|
|
372 |
</p> |
|
|
373 |
|
|
|
374 |
<p> |
|
|
375 |
When paused, messages will accumulate in the buffer, but will not be |
|
|
376 |
displayed until the Console is unpaused. |
|
|
377 |
</p> |
|
|
378 |
|
|
|
379 |
<h4 id="clear">Clearing and resetting</h4> |
|
|
380 |
|
|
|
381 |
<p> |
|
|
382 |
Flush the body of messages by clicking the Clear button in the Console |
|
|
383 |
footer or calling the instance's <code>clearConsole()</code> method. |
|
|
384 |
</p> |
|
|
385 |
|
|
|
386 |
<p> |
|
|
387 |
Clearing the Console will also flush the buffered messages not yet |
|
|
388 |
printed. |
|
|
389 |
</p> |
|
|
390 |
|
|
|
391 |
<p> |
|
|
392 |
Calling the instance's <code>reset()</code> method will clear the Console, |
|
|
393 |
flush the buffer, unpause, and reseed the Console's |
|
|
394 |
<code>startTime</code>. |
|
|
395 |
</p> |
|
|
396 |
|
|
|
397 |
<h3 id="filter">Filtering Console messages</h3> |
|
|
398 |
|
|
|
399 |
<p> |
|
|
400 |
Log messages can typically be filtered in two ways: by category (or |
|
|
401 |
<code>logLevel</code>) and by source. Category filtering is only available |
|
|
402 |
at the Console level, but source filtering can be accomplished at the YUI |
|
|
403 |
config level or the Console level (via the <a |
|
|
404 |
href="../console-filters/index.html">ConsoleFilters plugin</a>). Each approach below |
|
|
405 |
has a varying degree of impact to your page's performance. |
|
|
406 |
</p> |
|
|
407 |
|
|
|
408 |
<h4 id="debug_files">Using debug files</h4> |
|
|
409 |
|
|
|
410 |
<p> |
|
|
411 |
All YUI module files come in three flavors: |
|
|
412 |
</p> |
|
|
413 |
|
|
|
414 |
<ul> |
|
|
415 |
<li><code><em>module</em>-min.js</code> (min version)</li> |
|
|
416 |
<li><code><em>module</em>.js</code> (raw version)</li> |
|
|
417 |
<li><code><em>module</em>-debug.js</code> (debug version)</li> |
|
|
418 |
</ul> |
|
|
419 |
|
|
|
420 |
<p> |
|
|
421 |
Of these, only the debug version includes <code>Y.log(..)</code> |
|
|
422 |
statements. Explicitly including <code><script></code> tags in your |
|
|
423 |
source pointing to either the raw or min version of a module will |
|
|
424 |
effectively filter out messages from that module. The combo service |
|
|
425 |
supports combining any mixture of min, raw, and debug files as well. |
|
|
426 |
</p> |
|
|
427 |
|
|
|
428 |
<pre class="code prettyprint"><script src="http://yui.yahooapis.com/3.10.3/build/yui/yui-min.js"></script> |
|
|
429 |
<!-- Include debug messages from the node module --> |
|
|
430 |
<script src="http://yui.yahooapis.com/3.10.3/build/node/node-debug.js"></script> |
|
|
431 |
<script> |
|
|
432 |
YUI().use('overlay', function (Y) { |
|
|
433 |
// Overlay requires Node. Any other missing dependencies are automatically |
|
|
434 |
// loaded, excluding node-min.js since the node module is already provided |
|
|
435 |
// by the inline script tag. |
|
|
436 |
}); |
|
|
437 |
</script></pre> |
|
|
438 |
|
|
|
439 |
|
|
|
440 |
<p>Th |
|
|
441 |
is has the least impact on page performance. |
|
|
442 |
</p> |
|
|
443 |
|
|
|
444 |
<h4 id="yui_config">Choose which modules log</h4> |
|
|
445 |
|
|
|
446 |
<p> |
|
|
447 |
There are five YUI instance configurations that affect the logging |
|
|
448 |
subsystem behavior: |
|
|
449 |
</p> |
|
|
450 |
|
|
|
451 |
<table> |
|
|
452 |
<thead> |
|
|
453 |
<tr> |
|
|
454 |
<th>Property</th> |
|
|
455 |
<th>Example</th> |
|
|
456 |
<th>Role</th> |
|
|
457 |
</tr> |
|
|
458 |
</thead> |
|
|
459 |
<tbody> |
|
|
460 |
<tr> |
|
|
461 |
<td><code>debug</code></td> |
|
|
462 |
<td><code>Y.config.debug = false;</code></td> |
|
|
463 |
<td>If <code>false</code>, calls to <code>Y.log(..)</code> do nothing</td> |
|
|
464 |
</tr> |
|
|
465 |
<tr> |
|
|
466 |
<td><code>filter</code></td> |
|
|
467 |
<td><code>Y.config.filter = 'raw';</code></td> |
|
|
468 |
<td>Set to "raw" or "debug" to specify a default version of all included modules. Default value is "min"</td> |
|
|
469 |
</tr> |
|
|
470 |
<tr> |
|
|
471 |
<td><code>filters</code></td> |
|
|
472 |
<td><pre><code>Y.config.filters = { |
|
|
473 |
event: 'debug', |
|
|
474 |
node: 'raw' |
|
|
475 |
};</code></pre></td> |
|
|
476 |
<td>Like <code>filter</code> but can be used to specify file version on a per-module basis.</td> |
|
|
477 |
</tr> |
|
|
478 |
<tr> |
|
|
479 |
<td><code>logInclude</code></td> |
|
|
480 |
<td><pre><code>Y.config.logInclude = { |
|
|
481 |
node: true |
|
|
482 |
};</code></pre></td> |
|
|
483 |
<td>Allow only log messages assigned to the specified sources to propagate. Note a single module may use multiple sources.</td> |
|
|
484 |
</tr> |
|
|
485 |
<tr> |
|
|
486 |
<td><code>logExclude</code></td> |
|
|
487 |
<td><pre><code>Y.config.logExclude = { |
|
|
488 |
attribute: true |
|
|
489 |
};</code></pre></td> |
|
|
490 |
<td>Prevent log messages from the specified sources from propagating. Typically either <code>logInclude</code> or <code>logExclude</code> is configured, not both.</td> |
|
|
491 |
</tr> |
|
|
492 |
</tbody> |
|
|
493 |
</table> |
|
|
494 |
|
|
|
495 |
<pre class="code prettyprint">// Setting debug to true is unnecessary, but is included for illustration. |
|
|
496 |
// Setting filter to 'raw' facilitates stepping through module code during |
|
|
497 |
// debugging. Specifying 'debug' filters for slider and dd will result in all |
|
|
498 |
// log statements from those modules being included. |
|
|
499 |
YUI({ |
|
|
500 |
debug: true, |
|
|
501 |
useBrowserConsole: false, |
|
|
502 |
filter: 'raw', |
|
|
503 |
filters: { |
|
|
504 |
slider: 'debug', |
|
|
505 |
dd: 'debug' |
|
|
506 |
} |
|
|
507 |
}).use('slider', 'console', function (Y) { |
|
|
508 |
... |
|
|
509 |
}); |
|
|
510 |
|
|
|
511 |
// Request the debug version of all loaded files, but only allow log statements |
|
|
512 |
// from the sources 'node' and 'dom-screen'. |
|
|
513 |
YUI({ |
|
|
514 |
useBrowserConsole: false, |
|
|
515 |
filter: 'debug', |
|
|
516 |
logInclude: { |
|
|
517 |
node: true, |
|
|
518 |
"dom-screen": true |
|
|
519 |
} |
|
|
520 |
}).use('slider', 'console', function (Y) { |
|
|
521 |
... |
|
|
522 |
});</pre> |
|
|
523 |
|
|
|
524 |
|
|
|
525 |
<p> |
|
|
526 |
Specifying the <code>filters</code> config to include only debug versions |
|
|
527 |
of the modules you want log messages from is effectively the same as the |
|
|
528 |
prior option, and has the same effect on page performance. Specifying a |
|
|
529 |
"debug" filter and filtering sources via <code>logInclude</code> |
|
|
530 |
or <code>logExclude</code> has a greater impact because the calls to |
|
|
531 |
<code>Y.log(..)</code> are still present in all modules, even though they |
|
|
532 |
will be ignored. |
|
|
533 |
</p> |
|
|
534 |
|
|
|
535 |
<p> |
|
|
536 |
Look at the <a href="console-yui-config.html">YUI |
|
|
537 |
configuration to filter log messages</a> example for reference. |
|
|
538 |
</p> |
|
|
539 |
|
|
|
540 |
<h4 id="log_level"><code>logLevel</code></h4> |
|
|
541 |
|
|
|
542 |
<p> |
|
|
543 |
Most log statements in YUI 3 modules are "info" messages. |
|
|
544 |
Changing the <code>logLevel</code> configuration for your Console instance |
|
|
545 |
will limit the messages that display in the Console. Obviously, the debug |
|
|
546 |
files must be used for this as well. |
|
|
547 |
</p> |
|
|
548 |
|
|
|
549 |
<pre class="code prettyprint">YUI({ |
|
|
550 |
useBrowserConsole: false, |
|
|
551 |
filter: 'debug' // use all debug files |
|
|
552 |
}).use('overlay', 'console', function (Y) { |
|
|
553 |
|
|
|
554 |
// Only allow 'warn' or 'error' messages to display |
|
|
555 |
new Y.Console({ logLevel: 'warn' }).render(); |
|
|
556 |
|
|
|
557 |
});</pre> |
|
|
558 |
|
|
|
559 |
|
|
|
560 |
<p> |
|
|
561 |
Console will actually default its <code>logLevel</code> attribute from the |
|
|
562 |
so named YUI configuration property if it is specified. Note that unlike |
|
|
563 |
the attributes listed in the previous option, setting the |
|
|
564 |
<code>logLevel</code> in the YUI config will not alter the behavior of the |
|
|
565 |
logging subsystem. The configuration is simply used as a default value for |
|
|
566 |
instantiated Consoles. |
|
|
567 |
</p> |
|
|
568 |
|
|
|
569 |
<pre class="code prettyprint">// Include debug version of the dom module, but only broadcast log messages |
|
|
570 |
// from the 'dom-screen' source that are warnings or errors. |
|
|
571 |
YUI({ |
|
|
572 |
useBrowserConsole: false, |
|
|
573 |
filters: { dom: 'debug' }, |
|
|
574 |
logInclude: { 'dom-screen': true }, |
|
|
575 |
logLevel: 'warn' // this has no affect on Y.log statements |
|
|
576 |
}).use('dd','console', function (Y) { |
|
|
577 |
|
|
|
578 |
// With the YUI config above, these are now equivalent |
|
|
579 |
var consoleA = new Y.Console(); |
|
|
580 |
var consoleB = new Y.Console({ logLevel: 'warn' }); |
|
|
581 |
|
|
|
582 |
});</pre> |
|
|
583 |
|
|
|
584 |
|
|
|
585 |
<p> |
|
|
586 |
<code>logLevel</code> filtering, as with any filtering occurring at the |
|
|
587 |
Console, has a greater impact on page performance, since all messages, |
|
|
588 |
regardless of their category, are being broadcast from the logging |
|
|
589 |
subsystem to the Console before any preventative action is taken. |
|
|
590 |
</p> |
|
|
591 |
|
|
|
592 |
<h4 id="entry">Preventing the Console's <code>entry</code> event</h4> |
|
|
593 |
|
|
|
594 |
<p> |
|
|
595 |
Within Console, messages are transfered to the print loop buffer via an |
|
|
596 |
<code>entry</code> event. For fine grained control over which messages |
|
|
597 |
reach the Console body, implementers can subscribe to the event and prevent |
|
|
598 |
messages from being displayed by calling <code>preventDefault()</code> on |
|
|
599 |
the event. |
|
|
600 |
</p> |
|
|
601 |
|
|
|
602 |
<pre class="code prettyprint">var yconsole = new Y.Console(); |
|
|
603 |
yconsole.on('entry', function (e) { |
|
|
604 |
|
|
|
605 |
// the normalized message object is stored on the event in the 'message' |
|
|
606 |
// property. |
|
|
607 |
if (/Frank/.test(e.message.message)) { |
|
|
608 |
e.preventDefault(); // we don't talk about Frank here. |
|
|
609 |
} |
|
|
610 |
|
|
|
611 |
});</pre> |
|
|
612 |
|
|
|
613 |
|
|
|
614 |
<p> |
|
|
615 |
The signature of the normalized message is <a href="#anatomy">noted |
|
|
616 |
above</a>. |
|
|
617 |
</p> |
|
|
618 |
|
|
|
619 |
<p> |
|
|
620 |
This approach affords the most flexibility, as you can filter by |
|
|
621 |
arbitrarily complex criteria, and is the only option here not limited to |
|
|
622 |
comparing the category or source. |
|
|
623 |
</p> |
|
|
624 |
|
|
|
625 |
<p> |
|
|
626 |
This flexibility comes at a cost, though. Because the subscriber code is |
|
|
627 |
necessarily executed for every log message received, there is a greater |
|
|
628 |
impact on page performance . |
|
|
629 |
</p> |
|
|
630 |
|
|
|
631 |
<h4 id="console-filters">ConsoleFilters plugin</h4> |
|
|
632 |
|
|
|
633 |
<p> |
|
|
634 |
<img src="../assets/console/images/console_filters.png" alt="Console with the ConsoleFilters UI added" style="float: right; margin-left: 2em;"> |
|
|
635 |
|
|
|
636 |
For runtime display filtering by both category and source, the <a |
|
|
637 |
href="../console-filters/index.html">ConsoleFilters plugin</a> can be added to the |
|
|
638 |
Console. |
|
|
639 |
</p> |
|
|
640 |
|
|
|
641 |
<pre class="code prettyprint">YUI({..}).use('console-filters', function (Y) { |
|
|
642 |
new Y.Console({ |
|
|
643 |
newestOnTop: false, |
|
|
644 |
plugins: [ Y.Plugin.ConsoleFilters ] |
|
|
645 |
}).render(); |
|
|
646 |
|
|
|
647 |
// OR |
|
|
648 |
|
|
|
649 |
var yconsole = new Y.Console({..}); |
|
|
650 |
yconsole.plug(Y.Plugin.ConsoleFilters); |
|
|
651 |
|
|
|
652 |
yconsole.render(); |
|
|
653 |
});</pre> |
|
|
654 |
|
|
|
655 |
|
|
|
656 |
<p style="clear: right;"> |
|
|
657 |
The ConsoleFilters plugin adds a set of checkboxes to the Console footer, |
|
|
658 |
one for each category and source currently reported. Only those messages |
|
|
659 |
that match one of the checked categories and sources will be displayed. |
|
|
660 |
</p> |
|
|
661 |
|
|
|
662 |
<p> |
|
|
663 |
Unlike any of the prior options, messages filtered from the display by the |
|
|
664 |
ConsoleFilters plugin can be redisplayed by rechecking the corresponding |
|
|
665 |
category or source checkbox. |
|
|
666 |
</p> |
|
|
667 |
|
|
|
668 |
<p> |
|
|
669 |
This approach has the greatest affect on page performance because in order |
|
|
670 |
to support reassembling the Console contents in real time, all Console |
|
|
671 |
messages are stored in memory and more conditional logic is inserted into |
|
|
672 |
the path from log statement to Console display. |
|
|
673 |
</p> |
|
|
674 |
|
|
|
675 |
<p> |
|
|
676 |
Look at the <a href="../console-filters/console-filters-intro.html">ConsoleFilters |
|
|
677 |
plugin</a> example. |
|
|
678 |
</p> |
|
|
679 |
|
|
|
680 |
<h3 id="events">Console events</h3> |
|
|
681 |
|
|
|
682 |
<p> |
|
|
683 |
In addition to the standard <code><em>attribute</em>Change</code> events |
|
|
684 |
and others common to all Widgets, Console broadcasts the following |
|
|
685 |
events: |
|
|
686 |
</p> |
|
|
687 |
|
|
|
688 |
<table> |
|
|
689 |
<thead> |
|
|
690 |
<tr> |
|
|
691 |
<th>Event</th> |
|
|
692 |
<th>When</th> |
|
|
693 |
<th>Payload</th> |
|
|
694 |
</tr> |
|
|
695 |
</thead> |
|
|
696 |
<tbody> |
|
|
697 |
<tr> |
|
|
698 |
<td><code>reset</code></td> |
|
|
699 |
<td>In response to calls to an instance's <code>reset()</code> method. The default function for the event performs the reset detailed above.</td> |
|
|
700 |
<td>none</td> |
|
|
701 |
</tr> |
|
|
702 |
<tr> |
|
|
703 |
<td><code>entry</code></td> |
|
|
704 |
<td>In response to messages being received from the <code>yui:log</code>. The default function for the event sends the normalized message object to the print loop buffer.</td> |
|
|
705 |
<td>{ message : (<a href="#anatomy">normalized message object</a>) }</td> |
|
|
706 |
</tr> |
|
|
707 |
</tbody> |
|
|
708 |
</table> |
|
|
709 |
|
|
|
710 |
<p> |
|
|
711 |
This is not an exhaustive list. See the <a href="http://yuilibrary.com/yui/docs/api/module_console.html">API docs</a> for a complete listing. |
|
|
712 |
</p> |
|
|
713 |
</div> |
|
|
714 |
</div> |
|
|
715 |
</div> |
|
|
716 |
|
|
|
717 |
<div class="yui3-u-1-4"> |
|
|
718 |
<div class="sidebar"> |
|
|
719 |
|
|
|
720 |
<div id="toc" class="sidebox"> |
|
|
721 |
<div class="hd"> |
|
|
722 |
<h2 class="no-toc">Table of Contents</h2> |
|
|
723 |
</div> |
|
|
724 |
|
|
|
725 |
<div class="bd"> |
|
|
726 |
<ul class="toc"> |
|
|
727 |
<li> |
|
|
728 |
<a href="#getting-started">Getting Started</a> |
|
|
729 |
<ul class="toc"> |
|
|
730 |
<li> |
|
|
731 |
<a href="#sam">Trigger the CSS skin</a> |
|
|
732 |
</li> |
|
|
733 |
</ul> |
|
|
734 |
</li> |
|
|
735 |
<li> |
|
|
736 |
<a href="#logging">The YUI logging subsystem</a> |
|
|
737 |
</li> |
|
|
738 |
<li> |
|
|
739 |
<a href="#using">Using the Console Widget</a> |
|
|
740 |
<ul class="toc"> |
|
|
741 |
<li> |
|
|
742 |
<a href="#setup">Instantiating and configuring a Console</a> |
|
|
743 |
<ul class="toc"> |
|
|
744 |
<li> |
|
|
745 |
<a href="#instantiation">Instantiation</a> |
|
|
746 |
</li> |
|
|
747 |
<li> |
|
|
748 |
<a href="#config">Common configuration attributes</a> |
|
|
749 |
</li> |
|
|
750 |
<li> |
|
|
751 |
<a href="#buffer">The print loop</a> |
|
|
752 |
</li> |
|
|
753 |
<li> |
|
|
754 |
<a href="#universal">Share a Console between YUI instances</a> |
|
|
755 |
</li> |
|
|
756 |
</ul> |
|
|
757 |
</li> |
|
|
758 |
<li> |
|
|
759 |
<a href="#display">Console display</a> |
|
|
760 |
<ul class="toc"> |
|
|
761 |
<li> |
|
|
762 |
<a href="#anatomy-of-the-console">Anatomy of the Console</a> |
|
|
763 |
</li> |
|
|
764 |
<li> |
|
|
765 |
<a href="#anatomy">Anatomy of a message</a> |
|
|
766 |
</li> |
|
|
767 |
</ul> |
|
|
768 |
</li> |
|
|
769 |
<li> |
|
|
770 |
<a href="#controls">Console interaction</a> |
|
|
771 |
<ul class="toc"> |
|
|
772 |
<li> |
|
|
773 |
<a href="#collapse">Collapsing, expanding, hiding and showing</a> |
|
|
774 |
</li> |
|
|
775 |
<li> |
|
|
776 |
<a href="#pause">Pausing</a> |
|
|
777 |
</li> |
|
|
778 |
<li> |
|
|
779 |
<a href="#clear">Clearing and resetting</a> |
|
|
780 |
</li> |
|
|
781 |
</ul> |
|
|
782 |
</li> |
|
|
783 |
<li> |
|
|
784 |
<a href="#filter">Filtering Console messages</a> |
|
|
785 |
<ul class="toc"> |
|
|
786 |
<li> |
|
|
787 |
<a href="#debug_files">Using debug files</a> |
|
|
788 |
</li> |
|
|
789 |
<li> |
|
|
790 |
<a href="#yui_config">Choose which modules log</a> |
|
|
791 |
</li> |
|
|
792 |
<li> |
|
|
793 |
<a href="#log_level"><code>logLevel</code></a> |
|
|
794 |
</li> |
|
|
795 |
<li> |
|
|
796 |
<a href="#entry">Preventing the Console's <code>entry</code> event</a> |
|
|
797 |
</li> |
|
|
798 |
<li> |
|
|
799 |
<a href="#console-filters">ConsoleFilters plugin</a> |
|
|
800 |
</li> |
|
|
801 |
</ul> |
|
|
802 |
</li> |
|
|
803 |
<li> |
|
|
804 |
<a href="#events">Console events</a> |
|
|
805 |
</li> |
|
|
806 |
</ul> |
|
|
807 |
</li> |
|
|
808 |
</ul> |
|
|
809 |
</div> |
|
|
810 |
</div> |
|
|
811 |
|
|
|
812 |
|
|
|
813 |
|
|
|
814 |
<div class="sidebox"> |
|
|
815 |
<div class="hd"> |
|
|
816 |
<h2 class="no-toc">Examples</h2> |
|
|
817 |
</div> |
|
|
818 |
|
|
|
819 |
<div class="bd"> |
|
|
820 |
<ul class="examples"> |
|
|
821 |
|
|
|
822 |
|
|
|
823 |
<li data-description="The basics of setting up a Console"> |
|
|
824 |
<a href="console-basic.html">Creating a Console for Debugging</a> |
|
|
825 |
</li> |
|
|
826 |
|
|
|
827 |
|
|
|
828 |
|
|
|
829 |
<li data-description="Using your YUI instance configuration to filter which messages are reported in the Console"> |
|
|
830 |
<a href="console-yui-config.html">YUI Configuration to Filter Log Messages</a> |
|
|
831 |
</li> |
|
|
832 |
|
|
|
833 |
|
|
|
834 |
|
|
|
835 |
<li data-description="Using the Console's logSource attribute to consolidate log messages from multiple YUI instances into one Console"> |
|
|
836 |
<a href="console-global.html">Creating a Universal Console</a> |
|
|
837 |
</li> |
|
|
838 |
|
|
|
839 |
|
|
|
840 |
|
|
|
841 |
|
|
|
842 |
</ul> |
|
|
843 |
</div> |
|
|
844 |
</div> |
|
|
845 |
|
|
|
846 |
|
|
|
847 |
|
|
|
848 |
<div class="sidebox"> |
|
|
849 |
<div class="hd"> |
|
|
850 |
<h2 class="no-toc">Examples That Use This Component</h2> |
|
|
851 |
</div> |
|
|
852 |
|
|
|
853 |
<div class="bd"> |
|
|
854 |
<ul class="examples"> |
|
|
855 |
|
|
|
856 |
|
|
|
857 |
|
|
|
858 |
|
|
|
859 |
|
|
|
860 |
|
|
|
861 |
|
|
|
862 |
|
|
|
863 |
<li data-description="Adding the ConsoleFilters plugin to a Console instance for more granular run time log message filtering"> |
|
|
864 |
<a href="../console-filters/console-filters-intro.html">Using the ConsoleFilters Plugin</a> |
|
|
865 |
</li> |
|
|
866 |
|
|
|
867 |
|
|
|
868 |
</ul> |
|
|
869 |
</div> |
|
|
870 |
</div> |
|
|
871 |
|
|
|
872 |
</div> |
|
|
873 |
</div> |
|
|
874 |
</div> |
|
|
875 |
</div> |
|
|
876 |
|
|
|
877 |
<script src="../assets/vendor/prettify/prettify-min.js"></script> |
|
|
878 |
<script>prettyPrint();</script> |
|
|
879 |
|
|
|
880 |
<script> |
|
|
881 |
YUI.Env.Tests = { |
|
|
882 |
examples: [], |
|
|
883 |
project: '../assets', |
|
|
884 |
assets: '../assets/console', |
|
|
885 |
name: 'console', |
|
|
886 |
title: 'Console', |
|
|
887 |
newWindow: '', |
|
|
888 |
auto: false |
|
|
889 |
}; |
|
|
890 |
YUI.Env.Tests.examples.push('console-basic'); |
|
|
891 |
YUI.Env.Tests.examples.push('console-yui-config'); |
|
|
892 |
YUI.Env.Tests.examples.push('console-global'); |
|
|
893 |
YUI.Env.Tests.examples.push('console-filters-intro'); |
|
|
894 |
|
|
|
895 |
</script> |
|
|
896 |
<script src="../assets/yui/test-runner.js"></script> |
|
|
897 |
|
|
|
898 |
|
|
|
899 |
|
|
|
900 |
</body> |
|
|
901 |
</html> |