5
<title>Example: Using the ConsoleFilters Plugin</title>
6
<link rel="stylesheet" href="http://yui.yahooapis.com/3.4.0pr3/build/cssgrids/grids-min.css">
7
<link rel="stylesheet" href="../assets/css/main.css">
8
<link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css">
9
<script src="../../build/yui/yui-min.js"></script>
14
<h1>Example: Using the ConsoleFilters Plugin</h1>
19
<div id="main" class="yui3-u">
20
<div class="content"><style scoped>
25
#demo .yui3-console .yui3-console-title {
33
#demo .yui3-console .yui3-console-entry-meta {
40
<p>This example illustrates how to use and configure the ConsoleFilters plugin for Console. The debug versions of YUI module files are used, so standard YUI debugging messages are broadcast to the Console.</p>
42
<p>Use the checkboxes in the Console footer to control which messages are displayed or hidden. Click the "Log a message" button to call <code>Y.log</code> using a custom category and source.</p>
44
<p>Note how new filter checkboxes are added when a new category or source are received by the Console, for example when clicking on the "Log a message" button.</p>
47
<div class="example yui3-skin-sam">
48
<div id="demo" class="yui3-skin-sam">
49
<div id="yconsole"></div>
50
<button id="log" type="button">Log a message</button>
51
<button id="toggle_info" type="button">Hide info messages</button>
54
<script type="text/javascript">
55
// Create a YUI instance and request the console module and its dependencies
56
YUI({ filter: 'debug' }).use("console-filters", function (Y) {
58
// create the console instance
59
var yconsole = new Y.Console({
60
boundingBox: '#yconsole',
65
plugins: [ Y.Plugin.ConsoleFilters ]
68
// unknown categories and sources are allowed.
69
yconsole.filter.hideCategory('error');
71
// hide and show methods support N arguments.
72
yconsole.filter.hideSource('attribute','widget');
75
var yconsole = new Y.Console({
76
boundingBox: '#console',
81
}).plug(Y.Plugin.ConsoleFilters, {
92
// Broadcast a log message from a button that uses a custom category and source
93
Y.on('click', function () {
94
Y.log('Logging a message to the Console','my_stuff','MyApp');
97
// It is also possible to set the filter's subattributes directly
98
Y.on('click', function () {
99
var current = yconsole.filter.get('category.info');
101
yconsole.filter.set('category.info', !current);
103
this.set('text', (current ? 'Show' : 'Hide') + ' info messages');
111
<h3 class="first">Configure the YUI instance for debug mode</h3>
112
<p>Only the <code><em>module</em>-debug.js</code> versions of module files include log statements, so we'll set up our YUI instance's <code>filter</code> property to "debug". We'll also reduce the noise somewhat by specifying a <code>logInclude</code> list.</p>
114
<pre class="code prettyprint">YUI({filter: 'debug',
121
MyApp: true // This must be included for the custom source message
124
}).use("console-filters", function (Y) { ... });</pre>
127
<h3>Create the Console and plug in ConsoleFilters</h3>
128
<p>All that's left to do now is plugin in the ConsoleFilters plugin. This can be done in one of a few ways.</p>
129
<pre class="code prettyprint">// create the console instance
130
var yconsole = new Y.Console({
131
boundingBox: '#console',
132
height: '400px',
133
width: '450px',
135
plugins: [ Y.Plugin.ConsoleFilters ]
138
// unknown categories and sources are allowed.
139
yconsole.filter.hideCategory('error');
141
// hide and show methods support N arguments.
142
yconsole.filter.hideSource('attribute','widget');</pre>
145
<p>Alternatively, you can attach the ConsoleFilters plugin after instantiation. This version also shows how to apply initial category and source filter states.</p>
146
<pre class="code prettyprint">var yconsole = new Y.Console({
147
boundingBox: '#console',
148
height: '400px',
149
width: '450px',
151
}).plug(Y.Plugin.ConsoleFilters, {
160
</script></pre>
163
<h3>Full Code Listing</h3>
166
<pre class="code prettyprint"><div id="demo" class="yui3-skin-sam">
167
<div id="yconsole"></div>
168
<button id="log" type="button">Log a message</button>
169
<button id="toggle_info" type="button">Hide info messages</button>
170
</div></pre>
174
<pre class="code prettyprint"><script type="text/javascript">
175
// Create a YUI instance and request the console module and its dependencies
176
YUI({ filter: 'debug' }).use("console-filters", function (Y) {
178
// create the console instance
179
var yconsole = new Y.Console({
180
boundingBox: '#yconsole',
181
height: '400px',
182
width: '450px',
184
style: 'block',
185
plugins: [ Y.Plugin.ConsoleFilters ]
188
// unknown categories and sources are allowed.
189
yconsole.filter.hideCategory('error');
191
// hide and show methods support N arguments.
192
yconsole.filter.hideSource('attribute','widget');
195
var yconsole = new Y.Console({
196
boundingBox: '#console',
197
height: '400px',
198
width: '450px',
199
style: 'block',
201
}).plug(Y.Plugin.ConsoleFilters, {
212
// Broadcast a log message from a button that uses a custom category and source
213
Y.on('click', function () {
214
Y.log('Logging a message to the Console','my_stuff','MyApp');
217
// It is also possible to set the filter's subattributes directly
218
Y.on('click', function () {
219
var current = yconsole.filter.get('category.info');
221
yconsole.filter.set('category.info', !current);
223
this.set('text', (current ? 'Show' : 'Hide') + ' info messages');
224
},'#toggle_info');
227
</script></pre>
231
<pre class="code prettyprint"><style scoped>
236
#demo .yui3-console .yui3-console-title {
242
text-transform: none;
244
#demo .yui3-console .yui3-console-entry-meta {
247
</style></pre>
253
<div id="sidebar" class="yui3-u">
257
<div class="sidebox">
259
<h2 class="no-toc">Examples</h2>
263
<ul class="examples">
266
<li data-description="Adding the ConsoleFilters plugin to a Console instance for more granular run time log message filtering">
267
<a href="console-filters-intro.html">Using the ConsoleFilters Plugin</a>
279
<div class="sidebox">
281
<h2 class="no-toc">Examples That Use This Component</h2>
285
<ul class="examples">
290
<li data-description="The basics of setting up a Console">
291
<a href="../console/console-basic.html">Creating a Console for Debugging</a>
303
<script src="../assets/vendor/prettify/prettify-min.js"></script>
304
<script>prettyPrint();</script>