1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
<!DOCTYPE html>
<html>
<!--
Copyright 2007 The Closure Library Authors. All Rights Reserved.
Use of this source code is governed by the Apache License, Version 2.0.
See the COPYING file for details.
-->
<head>
<title>Debug</title>
<script type="text/javascript" src="../base.js"></script>
<script type="text/javascript">
goog.require('goog.debug');
goog.require('goog.debug.FancyWindow');
goog.require('goog.debug.Logger');
/**
* Person - a sample person object.
* @param {string} name The name
* @param {number} age The age
*/
var Person = function(name, age) {
this.name_ = name;
this.age_ = age;
this.address_ = null;
this.kids_ = [];
/**
* Set the address.
* @param {string} address The address to set
*/
this.setAddress = function(address) {
this.address_ = address;
}
/**
* Add a child.
* @param {Object} child The child to add
*/
this.addChild = function(child) {
this.kids_.push(child);
}
/**
* Create a string representation of the object.
* @return {string} The object as a string
*/
this.toString = function() {
return 'Person name: ' + this.name_ + ' Age: ' + this.age_;
}
}
/**
* Demonstrate the debug options.
*/
var demoDebug = function() {
// Create the debug window.
var debugWindow = new goog.debug.FancyWindow('main');
debugWindow.setEnabled(true);
debugWindow.init();
// Create a logger.
var theLogger = goog.debug.Logger.getLogger('demo');
theLogger.info('Logging examples');
// Create a simple object.
var someone = {'name': 'joe',
'age': 33,
'gender': 'm',
'kids': ['jen', 'sam', 'oliver'],
'address': '233 Great Road, Axtonhammer, MD'};
// Show the object, note that it will output '[object Object]'.
theLogger.info(someone);
// Use expose to walk through the object and show all data.
theLogger.info('Person: '+ goog.debug.expose(someone));
// Now create a Person object to demonstrate expose w/functions.
var pObj = new Person('fred', 2);
// Add a child, and an address.
pObj.addChild(someone);
pObj.setAddress('1 broadway, ny, ny');
// The toString will be called.
theLogger.info('toString: '+ pObj);
// Does not show the functions by default.
theLogger.info('expose (no functions): ' + goog.debug.expose(pObj));
// You can specify false if you really want to.
theLogger.info('expose (no functions): ' + goog.debug.expose(pObj, false));
// Shows the functions as well.
theLogger.info('expose (w/functions): ' + goog.debug.expose(pObj, true));
// Show deepExpose, which walks recursively through data.
theLogger.info('deepExpose (no functions): '+ goog.debug.deepExpose(pObj));
// You can specify false if you really want to.
theLogger.info('deepExpose (no functions): '+
goog.debug.deepExpose(pObj, false));
theLogger.info('deepExpose (w/functions): '+
goog.debug.deepExpose(pObj, true));
theLogger.shout('shout');
theLogger.severe('severe');
theLogger.warning('warning');
theLogger.info('info');
theLogger.fine('fine');
}
</script>
<body>
Look in the log window for debugging examples.
</body>
<script>
// Call the demo method.
demoDebug();
</script>
</html>
|