|
525
|
1 |
<!DOCTYPE html> |
|
|
2 |
<html lang="en"> |
|
|
3 |
<head> |
|
|
4 |
<meta charset="utf-8"> |
|
|
5 |
<title>Example: YUI Configuration to Filter Log Messages</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 |
|
|
|
24 |
<h1>Example: YUI Configuration to Filter Log Messages</h1> |
|
|
25 |
<div class="yui3-g"> |
|
|
26 |
<div class="yui3-u-3-4"> |
|
|
27 |
<div id="main"> |
|
|
28 |
<div class="content"><style scoped> |
|
|
29 |
#console { |
|
|
30 |
float: left; |
|
|
31 |
} |
|
|
32 |
#demo .yui3-console .yui3-console-title { |
|
|
33 |
border: 0 none; |
|
|
34 |
color: #000; |
|
|
35 |
font-size: 13px; |
|
|
36 |
font-weight: bold; |
|
|
37 |
margin: 0; |
|
|
38 |
text-transform: none; |
|
|
39 |
} |
|
|
40 |
|
|
|
41 |
#demo .yui3-console .yui3-console-entry-meta { |
|
|
42 |
margin: 0; |
|
|
43 |
} |
|
|
44 |
|
|
|
45 |
.filter-controls p label { |
|
|
46 |
display: block; |
|
|
47 |
margin: .25em 0; |
|
|
48 |
} |
|
|
49 |
#demo input { |
|
|
50 |
vertical-align: middle; |
|
|
51 |
} |
|
|
52 |
|
|
|
53 |
.form { |
|
|
54 |
clear: left; |
|
|
55 |
padding: 1em 0; |
|
|
56 |
} |
|
|
57 |
|
|
|
58 |
.form span { |
|
|
59 |
padding-left: 3em; |
|
|
60 |
} |
|
|
61 |
|
|
|
62 |
#msg { |
|
|
63 |
width: 50%; |
|
|
64 |
} |
|
|
65 |
|
|
|
66 |
.filter-controls { |
|
|
67 |
width: 180px; |
|
|
68 |
margin-left: 1em; |
|
|
69 |
float: left; |
|
|
70 |
} |
|
|
71 |
|
|
|
72 |
#preview { |
|
|
73 |
background: #eee; |
|
|
74 |
border: 1px solid #999; |
|
|
75 |
margin: 1em 0; |
|
|
76 |
overflow: auto; |
|
|
77 |
padding: 1em; |
|
|
78 |
width: 480px; |
|
|
79 |
} |
|
|
80 |
</style> |
|
|
81 |
|
|
|
82 |
|
|
|
83 |
<div class="intro"> |
|
|
84 |
<p>This example illustrates how to configure your YUI instance to ignore certain log messages to aid in reducing the signal-to-noise ratio when debugging.</p> |
|
|
85 |
|
|
|
86 |
<p>Log messages filtered out from the YUI config are permanently ignored. If you want to be able to temporarily hide and reshow messages, use the <a href="../console-filters/">ConsoleFilters plugin</a>. It is not uncommon to set up <code>logInclude</code> or <code>logExclude</code> in the YUI configuration and use the ConsoleFilters plugin.</p> |
|
|
87 |
|
|
|
88 |
<p>Log messages can be ignored based on the source (e.g. <code>event</code> or <code>attribute</code>) or based on their log level (info, warn, error).</p> |
|
|
89 |
|
|
|
90 |
</div> |
|
|
91 |
|
|
|
92 |
<div class="example yui3-skin-sam"> |
|
|
93 |
<form> |
|
|
94 |
<div id="demo" class="yui3-skin-sam"> |
|
|
95 |
<div id="console"></div> |
|
|
96 |
|
|
|
97 |
<div class="filter-controls"> |
|
|
98 |
<h4>Source filter</h4> |
|
|
99 |
<p> |
|
|
100 |
<select id="incexc"> |
|
|
101 |
<option value="logExclude" selected="selected">Exclude</option> |
|
|
102 |
<option value="logInclude">Include</option> |
|
|
103 |
</select> |
|
|
104 |
<label for="filter_a"><input type="checkbox" name="src_filter" value="sourceA" id="filter_a"> <code>sourceA</code></label> |
|
|
105 |
<label for="filter_b"><input type="checkbox" name="src_filter" value="sourceB" id="filter_b"> <code>sourceB</code></label> |
|
|
106 |
<label for="filter_c"><input type="checkbox" name="src_filter" value="sourceC" id="filter_c" checked="checked"> <code>sourceC</code></label> |
|
|
107 |
</p> |
|
|
108 |
</div> |
|
|
109 |
|
|
|
110 |
<div class="filter-controls"> |
|
|
111 |
<h4>Log level</h4> |
|
|
112 |
<p> |
|
|
113 |
<label for="lvl_info"> |
|
|
114 |
<input type="radio" name="log_level" id="lvl_info" value="info" checked="checked"> |
|
|
115 |
info |
|
|
116 |
</label> |
|
|
117 |
<label for="lvl_warn"> |
|
|
118 |
<input type="radio" name="log_level" id="lvl_warn" value="warn"> |
|
|
119 |
warn |
|
|
120 |
</label> |
|
|
121 |
<label for="lvl_error"> |
|
|
122 |
<input type="radio" name="log_level" id="lvl_error" value="error"> |
|
|
123 |
error |
|
|
124 |
</label> |
|
|
125 |
</p> |
|
|
126 |
</div> |
|
|
127 |
|
|
|
128 |
<div class="form"> |
|
|
129 |
<h4>Log a message</h4> |
|
|
130 |
<div> |
|
|
131 |
<input type="text" id="msg" value="This is a log message!"> |
|
|
132 |
<input type="submit" id="log">log message</button> |
|
|
133 |
|
|
|
134 |
<p> |
|
|
135 |
Source: |
|
|
136 |
<label for="msg_src_a"> |
|
|
137 |
<input type="radio" name="msg_src" id="msg_src_a" value="sourceA" checked="checked"> |
|
|
138 |
A |
|
|
139 |
</label> |
|
|
140 |
<label for="msg_src_b"> |
|
|
141 |
<input type="radio" name="msg_src" id="msg_src_b" value="sourceB"> |
|
|
142 |
B |
|
|
143 |
</label> |
|
|
144 |
<label for="msg_src_c"> |
|
|
145 |
<input type="radio" name="msg_src" id="msg_src_c" value="sourceC"> |
|
|
146 |
C |
|
|
147 |
</label> |
|
|
148 |
|
|
|
149 |
<span>Category:</span> |
|
|
150 |
<label for="msg_info"> |
|
|
151 |
<input type="radio" name="msg_cat" id="msg_info" value="info" checked="checked"> |
|
|
152 |
info |
|
|
153 |
</label> |
|
|
154 |
<label for="msg_warn"> |
|
|
155 |
<input type="radio" name="msg_cat" id="msg_warn" value="warn"> |
|
|
156 |
warn |
|
|
157 |
</label> |
|
|
158 |
<label for="msg_error"> |
|
|
159 |
<input type="radio" name="msg_cat" id="msg_error" value="error"> |
|
|
160 |
error |
|
|
161 |
</label> |
|
|
162 |
</p> |
|
|
163 |
</div> |
|
|
164 |
|
|
|
165 |
<h4>Code preview</h4> |
|
|
166 |
<pre id="preview">// YUI instance configuration |
|
|
167 |
var Y = YUI({ |
|
|
168 |
"logLevel": "info", |
|
|
169 |
"logExclude": { |
|
|
170 |
"sourceC": true |
|
|
171 |
} |
|
|
172 |
}); |
|
|
173 |
|
|
|
174 |
// Log statement |
|
|
175 |
Y.log("This is a log message!", "info", "sourceA");</pre> |
|
|
176 |
</div> |
|
|
177 |
</div> |
|
|
178 |
</form> |
|
|
179 |
<script type="text/javascript"> |
|
|
180 |
YUI().use("console", "selector-css3", "json-stringify", function (Y) { |
|
|
181 |
|
|
|
182 |
// Add the default filtering of sourceC messages |
|
|
183 |
Y.config.logExclude = { |
|
|
184 |
sourceC : true |
|
|
185 |
}; |
|
|
186 |
|
|
|
187 |
// Create and render the Console |
|
|
188 |
var yconsole = new Y.Console({ |
|
|
189 |
boundingBox: "#console", |
|
|
190 |
style: "block" |
|
|
191 |
}).render(); |
|
|
192 |
|
|
|
193 |
|
|
|
194 |
// Set up event listeners |
|
|
195 |
// Source include or exclude select |
|
|
196 |
Y.on("change", function () { |
|
|
197 |
if (this.get("value") === "logInclude") { |
|
|
198 |
Y.config.logInclude = Y.config.logExclude; |
|
|
199 |
delete Y.config.logExclude; |
|
|
200 |
} else { |
|
|
201 |
Y.config.logExclude = Y.config.logInclude; |
|
|
202 |
delete Y.config.logInclude; |
|
|
203 |
} |
|
|
204 |
updatePreview(); |
|
|
205 |
}, "#incexc"); |
|
|
206 |
|
|
|
207 |
// delegate all checkbox and radio group clicks via a single event subscriber |
|
|
208 |
// routing to the appropriate function based on the input name |
|
|
209 |
var clickHandlers = { |
|
|
210 |
src_filter : updateSourceFilters, |
|
|
211 |
log_level : updateLogLevel, |
|
|
212 |
msg_src : updatePreview, |
|
|
213 |
msg_cat : updatePreview |
|
|
214 |
}; |
|
|
215 |
|
|
|
216 |
Y.delegate("click", function (e) { |
|
|
217 |
var input = e.currentTarget, |
|
|
218 |
handler = clickHandlers[ input.get("name") ]; |
|
|
219 |
|
|
|
220 |
if (handler) { |
|
|
221 |
handler(input.get("value"), input.get("checked")); |
|
|
222 |
} |
|
|
223 |
|
|
|
224 |
}, "#demo", "input[name]"); |
|
|
225 |
|
|
|
226 |
// Log message input and radio groups |
|
|
227 |
Y.on("keyup", updatePreview, "#msg"); |
|
|
228 |
|
|
|
229 |
// Log message button |
|
|
230 |
Y.on("click", function (e) { |
|
|
231 |
var msg = Y.one("#msg").get("value"), |
|
|
232 |
cat = Y.one("#demo input[name=msg_cat]:checked").get("value"), |
|
|
233 |
src = Y.one("#demo input[name=msg_src]:checked").get("value"); |
|
|
234 |
|
|
|
235 |
Y.log(msg,cat,src); |
|
|
236 |
e.preventDefault(); // Don't submit the form |
|
|
237 |
}, "#log"); |
|
|
238 |
|
|
|
239 |
// Support functions |
|
|
240 |
function updateSourceFilters(source, checked) { |
|
|
241 |
var disposition = Y.one("#incexc").get("value"), |
|
|
242 |
cfg = Y.config[disposition]; // Y.config.logInclude or logExclude |
|
|
243 |
|
|
|
244 |
if (checked) { |
|
|
245 |
if (!cfg) { |
|
|
246 |
cfg = Y.config[disposition] = {}; |
|
|
247 |
} |
|
|
248 |
cfg[source] = true; |
|
|
249 |
} else { |
|
|
250 |
delete cfg[source]; |
|
|
251 |
if (!Y.Object.size(cfg)) { |
|
|
252 |
delete Y.config[disposition]; |
|
|
253 |
} |
|
|
254 |
} |
|
|
255 |
|
|
|
256 |
updatePreview(); |
|
|
257 |
} |
|
|
258 |
|
|
|
259 |
function updateLogLevel(level, checked) { |
|
|
260 |
if (checked) { |
|
|
261 |
Y.config.logLevel = level; |
|
|
262 |
yconsole.set("logLevel", level); |
|
|
263 |
updatePreview(); |
|
|
264 |
} |
|
|
265 |
} |
|
|
266 |
|
|
|
267 |
function updatePreview() { |
|
|
268 |
var filters = Y.all("#demo input[name=src_filter]:checked"), |
|
|
269 |
cfg = { |
|
|
270 |
logLevel: Y.one("#demo input[name=log_level]:checked").get("value") |
|
|
271 |
}; |
|
|
272 |
|
|
|
273 |
if (filters.size()) { |
|
|
274 |
cfg[Y.one("#incexc").get("value")] = Y.Array.hash(filters.get("value")); |
|
|
275 |
} |
|
|
276 |
|
|
|
277 |
Y.one("#preview").set("text",Y.Lang.sub( |
|
|
278 |
"// YUI instance configuration\n" + |
|
|
279 |
"var Y = YUI({cfg});\n\n" + |
|
|
280 |
"// Log statement\n" + |
|
|
281 |
'Y.log("{msg}", "{lvl}", "{src}");', |
|
|
282 |
{ |
|
|
283 |
cfg: Y.JSON.stringify(cfg, null, 4), |
|
|
284 |
msg: Y.one("#msg").get("value"), |
|
|
285 |
lvl: Y.one("#demo input[name=msg_cat]:checked").get("value"), |
|
|
286 |
src: Y.one("#demo input[name=msg_src]:checked").get("value") |
|
|
287 |
})); |
|
|
288 |
} |
|
|
289 |
|
|
|
290 |
}); |
|
|
291 |
</script> |
|
|
292 |
|
|
|
293 |
</div> |
|
|
294 |
|
|
|
295 |
<h3>Setting up filters in the YUI configuration</h3> |
|
|
296 |
<p>The configuration object passed to the YUI constructor supports a few settings that can help manage Console output while debugging. These configuration options are <code>logExclude</code>, <code>logInclude</code>, <code>logLevel</code>, <code>filter</code>, and <code>filters</code>.</p> |
|
|
297 |
|
|
|
298 |
<p>This example will show the use of the <code>logInclude</code>, <code>logExclude</code>, and <code>logLevel</code> configurations.</p> |
|
|
299 |
|
|
|
300 |
<p>An example configuration might look like this:</p> |
|
|
301 |
|
|
|
302 |
<pre class="code prettyprint">YUI({ |
|
|
303 |
filter : 'debug', // request -debug versions of modules for log statements |
|
|
304 |
logExclude : { |
|
|
305 |
event : true, // Don't broadcast log messages from the event module |
|
|
306 |
attribute : true, // or the attribute module |
|
|
307 |
widget : true // or the widget module |
|
|
308 |
}, |
|
|
309 |
logLevel : 'error', // Show only errors in the Console |
|
|
310 |
useBrowserConsole : false // Don't use the browser's native console |
|
|
311 |
}).use('overlay','anim','console', function (Y) { |
|
|
312 |
|
|
|
313 |
/* Console instances will default to logLevel = "info" */ |
|
|
314 |
|
|
|
315 |
});</pre> |
|
|
316 |
|
|
|
317 |
|
|
|
318 |
<p><code>logExclude</code> and <code>logInclude</code> prevent the logging subsystem from broadcasting filtered log messages. <code>logLevel</code>, on the other hand is used by Console instances to filter messages received from the subsystem.</p> |
|
|
319 |
|
|
|
320 |
<p>Updating <code>Y.config.logExclude</code> or <code>Y.config.logInclude</code> at runtime will immediately change the subsystem filtering, but will not recover messages previously sent from that source.</p> |
|
|
321 |
|
|
|
322 |
<pre class="code prettyprint">YUI({ |
|
|
323 |
logExclude : { |
|
|
324 |
event : true |
|
|
325 |
} |
|
|
326 |
}).use('console', function (Y) { |
|
|
327 |
|
|
|
328 |
/* In here, Y.config refers to the config object passed to the constructor */ |
|
|
329 |
|
|
|
330 |
// Stop broadcasting log messages from the attribute module |
|
|
331 |
Y.config.logExclude.attribute = true; |
|
|
332 |
|
|
|
333 |
// Start broadcasting log messages from the event module again |
|
|
334 |
delete Y.config.logExclude.event; |
|
|
335 |
|
|
|
336 |
});</pre> |
|
|
337 |
|
|
|
338 |
|
|
|
339 |
<p>When a Console is instantiated, barring explicit <code>logLevel</code> attribute configuration, the <code>logLevel</code> will be adopted from the YUI instance's configured <code>logLevel</code>, or <code>Y.Console.LOG_LEVEL_INFO</code> ("info") as a fallback. Unlike <code>logExclude</code>, changing the value in the YUI configuration will only affect instantiated Consoles from that point on. Additionally, you can manually override the <code>logLevel</code> a Console instance will display by updating its <code>logLevel</code> attribute.</p> |
|
|
340 |
|
|
|
341 |
<pre class="code prettyprint">YUI({ logLevel : "warn" }).use('console', function (Y) { |
|
|
342 |
|
|
|
343 |
var yconsole_1 = new Y.Console(); // logLevel == "warn" |
|
|
344 |
|
|
|
345 |
var yconsole_2 = new Y.Console({ |
|
|
346 |
logLevel : "info" // override at construction |
|
|
347 |
}); |
|
|
348 |
|
|
|
349 |
// This will not affect yconsole_1 or yconsole_2 |
|
|
350 |
Y.config.logLevel = "error"; |
|
|
351 |
|
|
|
352 |
var yconsole_3 = new Y.Console(); // logLevel == "error" |
|
|
353 |
|
|
|
354 |
yconsole_1.set("logLevel", "info"); // update this instance |
|
|
355 |
|
|
|
356 |
});</pre> |
|
|
357 |
|
|
|
358 |
|
|
|
359 |
<p>The interactive portion of this example illustrates the effect of various filter settings against logged messages. In a real application, it is most likely that the logging configuration won't be changed at runtime but set once in the YUI configuration at construction.</p> |
|
|
360 |
|
|
|
361 |
<p>The most relevant portion of the <a href="#full_code_listing">code for the demo above</a> is the updating of the YUI config and Console attribute.</p> |
|
|
362 |
|
|
|
363 |
<pre class="code prettyprint">// Create and render the Console |
|
|
364 |
var yconsole = new Y.Console({ |
|
|
365 |
boundingBox: '#console', // anchored to the page for the demo |
|
|
366 |
style: "block" |
|
|
367 |
}).render(); |
|
|
368 |
|
|
|
369 |
... |
|
|
370 |
|
|
|
371 |
// Source include or exclude select |
|
|
372 |
Y.on("change", function () { |
|
|
373 |
if (this.get("value") === "logInclude") { |
|
|
374 |
Y.config.logInclude = Y.config.logExclude; |
|
|
375 |
delete Y.config.logExclude; |
|
|
376 |
} else { |
|
|
377 |
Y.config.logExclude = Y.config.logInclude; |
|
|
378 |
delete Y.config.logInclude; |
|
|
379 |
} |
|
|
380 |
updatePreview(); |
|
|
381 |
}, "#incexc"); |
|
|
382 |
|
|
|
383 |
// These functions are called from a delegated event handler. |
|
|
384 |
// See the Full Code Listing for how they are called. |
|
|
385 |
function updateSourceFilters(source, checked) { |
|
|
386 |
var disposition = Y.one("#incexc").get("value"), |
|
|
387 |
cfg = Y.config[disposition]; // Y.config.logInclude or logExclude |
|
|
388 |
|
|
|
389 |
if (checked) { |
|
|
390 |
if (!cfg) { |
|
|
391 |
cfg = Y.config[disposition] = {}; |
|
|
392 |
} |
|
|
393 |
cfg[source] = true; // e.g. Y.config.logInclude.sourceA = true; |
|
|
394 |
} else { |
|
|
395 |
delete cfg[source]; |
|
|
396 |
|
|
|
397 |
if (!Y.Object.size(cfg)) { |
|
|
398 |
delete Y.config[disposition]; |
|
|
399 |
} |
|
|
400 |
} |
|
|
401 |
|
|
|
402 |
updatePreview(); |
|
|
403 |
} |
|
|
404 |
|
|
|
405 |
function updateLogLevel(level, checked) { |
|
|
406 |
if (checked) { |
|
|
407 |
Y.config.logLevel = level; |
|
|
408 |
yconsole.set("logLevel", level); |
|
|
409 |
updatePreview(); |
|
|
410 |
} |
|
|
411 |
}</pre> |
|
|
412 |
|
|
|
413 |
|
|
|
414 |
<h3 id="full_code_listing">Full Code Listing</h3> |
|
|
415 |
|
|
|
416 |
<h4>Markup</h4> |
|
|
417 |
|
|
|
418 |
<pre class="code prettyprint"><form> |
|
|
419 |
<div id="demo" class="yui3-skin-sam"> |
|
|
420 |
<div id="console"></div> |
|
|
421 |
|
|
|
422 |
<div class="filter-controls"> |
|
|
423 |
<h4>Source filter</h4> |
|
|
424 |
<p> |
|
|
425 |
<select id="incexc"> |
|
|
426 |
<option value="logExclude" selected="selected">Exclude</option> |
|
|
427 |
<option value="logInclude">Include</option> |
|
|
428 |
</select> |
|
|
429 |
<label for="filter_a"><input type="checkbox" name="src_filter" value="sourceA" id="filter_a"> <code>sourceA</code></label> |
|
|
430 |
<label for="filter_b"><input type="checkbox" name="src_filter" value="sourceB" id="filter_b"> <code>sourceB</code></label> |
|
|
431 |
<label for="filter_c"><input type="checkbox" name="src_filter" value="sourceC" id="filter_c" checked="checked"> <code>sourceC</code></label> |
|
|
432 |
</p> |
|
|
433 |
</div> |
|
|
434 |
|
|
|
435 |
<div class="filter-controls"> |
|
|
436 |
<h4>Log level</h4> |
|
|
437 |
<p> |
|
|
438 |
<label for="lvl_info"> |
|
|
439 |
<input type="radio" name="log_level" id="lvl_info" value="info" checked="checked"> |
|
|
440 |
info |
|
|
441 |
</label> |
|
|
442 |
<label for="lvl_warn"> |
|
|
443 |
<input type="radio" name="log_level" id="lvl_warn" value="warn"> |
|
|
444 |
warn |
|
|
445 |
</label> |
|
|
446 |
<label for="lvl_error"> |
|
|
447 |
<input type="radio" name="log_level" id="lvl_error" value="error"> |
|
|
448 |
error |
|
|
449 |
</label> |
|
|
450 |
</p> |
|
|
451 |
</div> |
|
|
452 |
|
|
|
453 |
<div class="form"> |
|
|
454 |
<h4>Log a message</h4> |
|
|
455 |
<div> |
|
|
456 |
<input type="text" id="msg" value="This is a log message!"> |
|
|
457 |
<input type="submit" id="log">log message</button> |
|
|
458 |
|
|
|
459 |
<p> |
|
|
460 |
Source: |
|
|
461 |
<label for="msg_src_a"> |
|
|
462 |
<input type="radio" name="msg_src" id="msg_src_a" value="sourceA" checked="checked"> |
|
|
463 |
A |
|
|
464 |
</label> |
|
|
465 |
<label for="msg_src_b"> |
|
|
466 |
<input type="radio" name="msg_src" id="msg_src_b" value="sourceB"> |
|
|
467 |
B |
|
|
468 |
</label> |
|
|
469 |
<label for="msg_src_c"> |
|
|
470 |
<input type="radio" name="msg_src" id="msg_src_c" value="sourceC"> |
|
|
471 |
C |
|
|
472 |
</label> |
|
|
473 |
|
|
|
474 |
<span>Category:</span> |
|
|
475 |
<label for="msg_info"> |
|
|
476 |
<input type="radio" name="msg_cat" id="msg_info" value="info" checked="checked"> |
|
|
477 |
info |
|
|
478 |
</label> |
|
|
479 |
<label for="msg_warn"> |
|
|
480 |
<input type="radio" name="msg_cat" id="msg_warn" value="warn"> |
|
|
481 |
warn |
|
|
482 |
</label> |
|
|
483 |
<label for="msg_error"> |
|
|
484 |
<input type="radio" name="msg_cat" id="msg_error" value="error"> |
|
|
485 |
error |
|
|
486 |
</label> |
|
|
487 |
</p> |
|
|
488 |
</div> |
|
|
489 |
|
|
|
490 |
<h4>Code preview</h4> |
|
|
491 |
<pre id="preview">// YUI instance configuration |
|
|
492 |
var Y = YUI({ |
|
|
493 |
"logLevel": "info", |
|
|
494 |
"logExclude": { |
|
|
495 |
"sourceC": true |
|
|
496 |
} |
|
|
497 |
}); |
|
|
498 |
|
|
|
499 |
// Log statement |
|
|
500 |
Y.log(&quot;This is a log message!&quot;, &quot;info&quot;, &quot;sourceA&quot;);</pre> |
|
|
501 |
</div> |
|
|
502 |
</div> |
|
|
503 |
</form></pre> |
|
|
504 |
|
|
|
505 |
|
|
|
506 |
<h4>JavaScript</h4> |
|
|
507 |
|
|
|
508 |
<pre class="code prettyprint"><script type="text/javascript"> |
|
|
509 |
YUI().use("console", "selector-css3", "json-stringify", function (Y) { |
|
|
510 |
|
|
|
511 |
// Add the default filtering of sourceC messages |
|
|
512 |
Y.config.logExclude = { |
|
|
513 |
sourceC : true |
|
|
514 |
}; |
|
|
515 |
|
|
|
516 |
// Create and render the Console |
|
|
517 |
var yconsole = new Y.Console({ |
|
|
518 |
boundingBox: "#console", |
|
|
519 |
style: "block" |
|
|
520 |
}).render(); |
|
|
521 |
|
|
|
522 |
|
|
|
523 |
// Set up event listeners |
|
|
524 |
// Source include or exclude select |
|
|
525 |
Y.on("change", function () { |
|
|
526 |
if (this.get("value") === "logInclude") { |
|
|
527 |
Y.config.logInclude = Y.config.logExclude; |
|
|
528 |
delete Y.config.logExclude; |
|
|
529 |
} else { |
|
|
530 |
Y.config.logExclude = Y.config.logInclude; |
|
|
531 |
delete Y.config.logInclude; |
|
|
532 |
} |
|
|
533 |
updatePreview(); |
|
|
534 |
}, "#incexc"); |
|
|
535 |
|
|
|
536 |
// delegate all checkbox and radio group clicks via a single event subscriber |
|
|
537 |
// routing to the appropriate function based on the input name |
|
|
538 |
var clickHandlers = { |
|
|
539 |
src_filter : updateSourceFilters, |
|
|
540 |
log_level : updateLogLevel, |
|
|
541 |
msg_src : updatePreview, |
|
|
542 |
msg_cat : updatePreview |
|
|
543 |
}; |
|
|
544 |
|
|
|
545 |
Y.delegate("click", function (e) { |
|
|
546 |
var input = e.currentTarget, |
|
|
547 |
handler = clickHandlers[ input.get("name") ]; |
|
|
548 |
|
|
|
549 |
if (handler) { |
|
|
550 |
handler(input.get("value"), input.get("checked")); |
|
|
551 |
} |
|
|
552 |
|
|
|
553 |
}, "#demo", "input[name]"); |
|
|
554 |
|
|
|
555 |
// Log message input and radio groups |
|
|
556 |
Y.on("keyup", updatePreview, "#msg"); |
|
|
557 |
|
|
|
558 |
// Log message button |
|
|
559 |
Y.on("click", function (e) { |
|
|
560 |
var msg = Y.one("#msg").get("value"), |
|
|
561 |
cat = Y.one("#demo input[name=msg_cat]:checked").get("value"), |
|
|
562 |
src = Y.one("#demo input[name=msg_src]:checked").get("value"); |
|
|
563 |
|
|
|
564 |
Y.log(msg,cat,src); |
|
|
565 |
e.preventDefault(); // Don't submit the form |
|
|
566 |
}, "#log"); |
|
|
567 |
|
|
|
568 |
// Support functions |
|
|
569 |
function updateSourceFilters(source, checked) { |
|
|
570 |
var disposition = Y.one("#incexc").get("value"), |
|
|
571 |
cfg = Y.config[disposition]; // Y.config.logInclude or logExclude |
|
|
572 |
|
|
|
573 |
if (checked) { |
|
|
574 |
if (!cfg) { |
|
|
575 |
cfg = Y.config[disposition] = {}; |
|
|
576 |
} |
|
|
577 |
cfg[source] = true; |
|
|
578 |
} else { |
|
|
579 |
delete cfg[source]; |
|
|
580 |
if (!Y.Object.size(cfg)) { |
|
|
581 |
delete Y.config[disposition]; |
|
|
582 |
} |
|
|
583 |
} |
|
|
584 |
|
|
|
585 |
updatePreview(); |
|
|
586 |
} |
|
|
587 |
|
|
|
588 |
function updateLogLevel(level, checked) { |
|
|
589 |
if (checked) { |
|
|
590 |
Y.config.logLevel = level; |
|
|
591 |
yconsole.set("logLevel", level); |
|
|
592 |
updatePreview(); |
|
|
593 |
} |
|
|
594 |
} |
|
|
595 |
|
|
|
596 |
function updatePreview() { |
|
|
597 |
var filters = Y.all("#demo input[name=src_filter]:checked"), |
|
|
598 |
cfg = { |
|
|
599 |
logLevel: Y.one("#demo input[name=log_level]:checked").get("value") |
|
|
600 |
}; |
|
|
601 |
|
|
|
602 |
if (filters.size()) { |
|
|
603 |
cfg[Y.one("#incexc").get("value")] = Y.Array.hash(filters.get("value")); |
|
|
604 |
} |
|
|
605 |
|
|
|
606 |
Y.one("#preview").set("text",Y.Lang.sub( |
|
|
607 |
"// YUI instance configuration\n" + |
|
|
608 |
"var Y = YUI({cfg});\n\n" + |
|
|
609 |
"// Log statement\n" + |
|
|
610 |
'Y.log("{msg}", "{lvl}", "{src}");', |
|
|
611 |
{ |
|
|
612 |
cfg: Y.JSON.stringify(cfg, null, 4), |
|
|
613 |
msg: Y.one("#msg").get("value"), |
|
|
614 |
lvl: Y.one("#demo input[name=msg_cat]:checked").get("value"), |
|
|
615 |
src: Y.one("#demo input[name=msg_src]:checked").get("value") |
|
|
616 |
})); |
|
|
617 |
} |
|
|
618 |
|
|
|
619 |
}); |
|
|
620 |
</script></pre> |
|
|
621 |
|
|
|
622 |
|
|
|
623 |
<h4>CSS</h4> |
|
|
624 |
|
|
|
625 |
<pre class="code prettyprint"><style scoped> |
|
|
626 |
#console { |
|
|
627 |
float: left; |
|
|
628 |
} |
|
|
629 |
#demo .yui3-console .yui3-console-title { |
|
|
630 |
border: 0 none; |
|
|
631 |
color: #000; |
|
|
632 |
font-size: 13px; |
|
|
633 |
font-weight: bold; |
|
|
634 |
margin: 0; |
|
|
635 |
text-transform: none; |
|
|
636 |
} |
|
|
637 |
|
|
|
638 |
#demo .yui3-console .yui3-console-entry-meta { |
|
|
639 |
margin: 0; |
|
|
640 |
} |
|
|
641 |
|
|
|
642 |
.filter-controls p label { |
|
|
643 |
display: block; |
|
|
644 |
margin: .25em 0; |
|
|
645 |
} |
|
|
646 |
#demo input { |
|
|
647 |
vertical-align: middle; |
|
|
648 |
} |
|
|
649 |
|
|
|
650 |
.form { |
|
|
651 |
clear: left; |
|
|
652 |
padding: 1em 0; |
|
|
653 |
} |
|
|
654 |
|
|
|
655 |
.form span { |
|
|
656 |
padding-left: 3em; |
|
|
657 |
} |
|
|
658 |
|
|
|
659 |
#msg { |
|
|
660 |
width: 50%; |
|
|
661 |
} |
|
|
662 |
|
|
|
663 |
.filter-controls { |
|
|
664 |
width: 180px; |
|
|
665 |
margin-left: 1em; |
|
|
666 |
float: left; |
|
|
667 |
} |
|
|
668 |
|
|
|
669 |
#preview { |
|
|
670 |
background: #eee; |
|
|
671 |
border: 1px solid #999; |
|
|
672 |
margin: 1em 0; |
|
|
673 |
overflow: auto; |
|
|
674 |
padding: 1em; |
|
|
675 |
width: 480px; |
|
|
676 |
} |
|
|
677 |
</style></pre> |
|
|
678 |
|
|
|
679 |
|
|
|
680 |
|
|
|
681 |
</div> |
|
|
682 |
</div> |
|
|
683 |
</div> |
|
|
684 |
|
|
|
685 |
<div class="yui3-u-1-4"> |
|
|
686 |
<div class="sidebar"> |
|
|
687 |
|
|
|
688 |
|
|
|
689 |
|
|
|
690 |
<div class="sidebox"> |
|
|
691 |
<div class="hd"> |
|
|
692 |
<h2 class="no-toc">Examples</h2> |
|
|
693 |
</div> |
|
|
694 |
|
|
|
695 |
<div class="bd"> |
|
|
696 |
<ul class="examples"> |
|
|
697 |
|
|
|
698 |
|
|
|
699 |
<li data-description="The basics of setting up a Console"> |
|
|
700 |
<a href="console-basic.html">Creating a Console for Debugging</a> |
|
|
701 |
</li> |
|
|
702 |
|
|
|
703 |
|
|
|
704 |
|
|
|
705 |
<li data-description="Using your YUI instance configuration to filter which messages are reported in the Console"> |
|
|
706 |
<a href="console-yui-config.html">YUI Configuration to Filter Log Messages</a> |
|
|
707 |
</li> |
|
|
708 |
|
|
|
709 |
|
|
|
710 |
|
|
|
711 |
<li data-description="Using the Console's logSource attribute to consolidate log messages from multiple YUI instances into one Console"> |
|
|
712 |
<a href="console-global.html">Creating a Universal Console</a> |
|
|
713 |
</li> |
|
|
714 |
|
|
|
715 |
|
|
|
716 |
|
|
|
717 |
|
|
|
718 |
</ul> |
|
|
719 |
</div> |
|
|
720 |
</div> |
|
|
721 |
|
|
|
722 |
|
|
|
723 |
|
|
|
724 |
<div class="sidebox"> |
|
|
725 |
<div class="hd"> |
|
|
726 |
<h2 class="no-toc">Examples That Use This Component</h2> |
|
|
727 |
</div> |
|
|
728 |
|
|
|
729 |
<div class="bd"> |
|
|
730 |
<ul class="examples"> |
|
|
731 |
|
|
|
732 |
|
|
|
733 |
|
|
|
734 |
|
|
|
735 |
|
|
|
736 |
|
|
|
737 |
|
|
|
738 |
|
|
|
739 |
<li data-description="Adding the ConsoleFilters plugin to a Console instance for more granular run time log message filtering"> |
|
|
740 |
<a href="../console-filters/console-filters-intro.html">Using the ConsoleFilters Plugin</a> |
|
|
741 |
</li> |
|
|
742 |
|
|
|
743 |
|
|
|
744 |
</ul> |
|
|
745 |
</div> |
|
|
746 |
</div> |
|
|
747 |
|
|
|
748 |
</div> |
|
|
749 |
</div> |
|
|
750 |
</div> |
|
|
751 |
</div> |
|
|
752 |
|
|
|
753 |
<script src="../assets/vendor/prettify/prettify-min.js"></script> |
|
|
754 |
<script>prettyPrint();</script> |
|
|
755 |
|
|
|
756 |
<script> |
|
|
757 |
YUI.Env.Tests = { |
|
|
758 |
examples: [], |
|
|
759 |
project: '../assets', |
|
|
760 |
assets: '../assets/console', |
|
|
761 |
name: 'console-yui-config', |
|
|
762 |
title: 'YUI Configuration to Filter Log Messages', |
|
|
763 |
newWindow: '', |
|
|
764 |
auto: false |
|
|
765 |
}; |
|
|
766 |
YUI.Env.Tests.examples.push('console-basic'); |
|
|
767 |
YUI.Env.Tests.examples.push('console-yui-config'); |
|
|
768 |
YUI.Env.Tests.examples.push('console-global'); |
|
|
769 |
YUI.Env.Tests.examples.push('console-filters-intro'); |
|
|
770 |
|
|
|
771 |
</script> |
|
|
772 |
<script src="../assets/yui/test-runner.js"></script> |
|
|
773 |
|
|
|
774 |
|
|
|
775 |
|
|
|
776 |
</body> |
|
|
777 |
</html> |