1 <!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
4 <title>API: logger Logger.js (YUI Library)
</title>
5 <link rel=
"stylesheet" type=
"text/css" href=
"assets/api.css">
9 <div id=
"doc3" class=
"yui-t2">
12 <h1>Yahoo! UI Library
</h1>
13 <h3>Logger Widget
<span class=
"subtitle">2.2.0</span></h3>
15 <a href=
"./index.html">Yahoo! UI Library
</a>
16 > <a href=
"./module_logger.html">logger
</a>
18 > Logger.js (source view)
27 <div class=
"highlight" ><pre> <span class=
"c">/**
</span>
28 <span class=
"c"> * The Logger widget provides a simple way to read or write log messages in
</span>
29 <span class=
"c"> * JavaScript code. Integration with the YUI Library
's debug builds allow
</span>
30 <span class=
"c"> * implementers to access under-the-hood events, errors, and debugging messages.
</span>
31 <span class=
"c"> * Output may be read through a LogReader console and/or output to a browser
</span>
32 <span class=
"c"> * console.
</span>
33 <span class=
"c"> *
</span>
34 <span class=
"c"> * @module logger
</span>
35 <span class=
"c"> * @requires yahoo, event, dom
</span>
36 <span class=
"c"> * @optional dragdrop
</span>
37 <span class=
"c"> * @namespace YAHOO.widget
</span>
38 <span class=
"c"> * @title Logger Widget
</span>
39 <span class=
"c"> */
</span>
41 <span class=
"c">/****************************************************************************/
</span>
42 <span class=
"c">/****************************************************************************/
</span>
43 <span class=
"c">/****************************************************************************/
</span>
45 <span class=
"c">/**
</span>
46 <span class=
"c"> * The singleton Logger class provides core log management functionality. Saves
</span>
47 <span class=
"c"> * logs written through the global YAHOO.log function or written by a LogWriter
</span>
48 <span class=
"c"> * instance. Provides access to logs for reading by a LogReader instance or
</span>
49 <span class=
"c"> * native browser console such as the Firebug extension to Firefox or Safari
's
</span>
50 <span class=
"c"> * JavaScript console through integration with the console.log() method.
</span>
51 <span class=
"c"> *
</span>
52 <span class=
"c"> * @class Logger
</span>
53 <span class=
"c"> * @static
</span>
54 <span class=
"c"> */
</span>
55 <span class=
"nx">YAHOO
</span><span class=
"o">.
</span><span class=
"nx">widget
</span><span class=
"o">.
</span><span class=
"nx">Logger
</span> <span class=
"o">=
</span> <span class=
"o">{
</span>
56 <span class=
"c">// Initialize members
</span>
57 <span class=
"c"></span> <span class=
"nx">loggerEnabled
</span><span class=
"o">:
</span> <span class=
"kc">true
</span><span class=
"o">,
</span>
58 <span class=
"nx">_browserConsoleEnabled
</span><span class=
"o">:
</span> <span class=
"kc">false
</span><span class=
"o">,
</span>
59 <span class=
"nx">categories
</span><span class=
"o">:
</span> <span class=
"o">[
</span><span class=
"s2">"info
"</span><span class=
"o">,
</span><span class=
"s2">"warn
"</span><span class=
"o">,
</span><span class=
"s2">"error
"</span><span class=
"o">,
</span><span class=
"s2">"time
"</span><span class=
"o">,
</span><span class=
"s2">"window
"</span><span class=
"o">],
</span>
60 <span class=
"nx">sources
</span><span class=
"o">:
</span> <span class=
"o">[
</span><span class=
"s2">"global
"</span><span class=
"o">],
</span>
61 <span class=
"nx">_stack
</span><span class=
"o">:
</span> <span class=
"o">[],
</span> <span class=
"c">// holds all log msgs
</span>
62 <span class=
"c"></span> <span class=
"nx">maxStackEntries
</span><span class=
"o">:
</span> <span class=
"m">2500</span><span class=
"o">,
</span>
63 <span class=
"nx">_startTime
</span><span class=
"o">:
</span> <span class=
"k">new
</span> <span class=
"nb">Date
</span><span class=
"o">().
</span><span class=
"nx">getTime
</span><span class=
"o">(),
</span> <span class=
"c">// static start timestamp
</span>
64 <span class=
"c"></span> <span class=
"nx">_lastTime
</span><span class=
"o">:
</span> <span class=
"kc">null
</span> <span class=
"c">// timestamp of last logged message
</span>
65 <span class=
"c"></span><span class=
"o">};
</span>
67 <span class=
"c">/////////////////////////////////////////////////////////////////////////////
</span>
68 <span class=
"c">//
</span>
69 <span class=
"c">// Public methods
</span>
70 <span class=
"c">//
</span>
71 <span class=
"c">/////////////////////////////////////////////////////////////////////////////
</span>
72 <span class=
"c">/**
</span>
73 <span class=
"c"> * Saves a log message to the stack and fires newLogEvent. If the log message is
</span>
74 <span class=
"c"> * assigned to an unknown category, creates a new category. If the log message is
</span>
75 <span class=
"c"> * from an unknown source, creates a new source. If browser console is enabled,
</span>
76 <span class=
"c"> * outputs the log message to browser console.
</span>
77 <span class=
"c"> *
</span>
78 <span class=
"c"> * @method log
</span>
79 <span class=
"c"> * @param sMsg {String} The log message.
</span>
80 <span class=
"c"> * @param sCategory {String} Category of log message, or null.
</span>
81 <span class=
"c"> * @param sSource {String} Source of LogWriter, or null if global.
</span>
82 <span class=
"c"> */
</span>
83 <span class=
"nx">YAHOO
</span><span class=
"o">.
</span><span class=
"nx">widget
</span><span class=
"o">.
</span><span class=
"nx">Logger
</span><span class=
"o">.
</span><span class=
"nx">log
</span> <span class=
"o">=
</span> <span class=
"k">function
</span><span class=
"o">(
</span><span class=
"nx">sMsg
</span><span class=
"o">,
</span> <span class=
"nx">sCategory
</span><span class=
"o">,
</span> <span class=
"nx">sSource
</span><span class=
"o">)
</span> <span class=
"o">{
</span>
84 <span class=
"k">if
</span><span class=
"o">(
</span><span class=
"k">this
</span><span class=
"o">.
</span><span class=
"nx">loggerEnabled
</span><span class=
"o">)
</span> <span class=
"o">{
</span>
85 <span class=
"k">if
</span><span class=
"o">(!
</span><span class=
"nx">sCategory
</span><span class=
"o">)
</span> <span class=
"o">{
</span>
86 <span class=
"nx">sCategory
</span> <span class=
"o">=
</span> <span class=
"s2">"info
"</span><span class=
"o">;
</span> <span class=
"c">// default category
</span>
87 <span class=
"c"></span> <span class=
"o">}
</span>
88 <span class=
"k">else
</span> <span class=
"o">{
</span>
89 <span class=
"nx">sCategory
</span> <span class=
"o">=
</span> <span class=
"nx">sCategory
</span><span class=
"o">.
</span><span class=
"nx">toLocaleLowerCase
</span><span class=
"o">();
</span>
90 <span class=
"k">if
</span><span class=
"o">(
</span><span class=
"k">this
</span><span class=
"o">.
</span><span class=
"nx">_isNewCategory
</span><span class=
"o">(
</span><span class=
"nx">sCategory
</span><span class=
"o">))
</span> <span class=
"o">{
</span>
91 <span class=
"k">this
</span><span class=
"o">.
</span><span class=
"nx">_createNewCategory
</span><span class=
"o">(
</span><span class=
"nx">sCategory
</span><span class=
"o">);
</span>
92 <span class=
"o">}
</span>
93 <span class=
"o">}
</span>
94 <span class=
"k">var
</span> <span class=
"nx">sClass
</span> <span class=
"o">=
</span> <span class=
"s2">"global
"</span><span class=
"o">;
</span> <span class=
"c">// default source
</span>
95 <span class=
"c"></span> <span class=
"k">var
</span> <span class=
"nx">sDetail
</span> <span class=
"o">=
</span> <span class=
"kc">null
</span><span class=
"o">;
</span>
96 <span class=
"k">if
</span><span class=
"o">(
</span><span class=
"nx">sSource
</span><span class=
"o">)
</span> <span class=
"o">{
</span>
97 <span class=
"k">var
</span> <span class=
"nx">spaceIndex
</span> <span class=
"o">=
</span> <span class=
"nx">sSource
</span><span class=
"o">.
</span><span class=
"nx">indexOf
</span><span class=
"o">(
</span><span class=
"s2">" "</span><span class=
"o">);
</span>
98 <span class=
"k">if
</span><span class=
"o">(
</span><span class=
"nx">spaceIndex
</span> <span class=
"o">></span> <span class=
"m">0</span><span class=
"o">)
</span> <span class=
"o">{
</span>
99 <span class=
"c">// Substring until first space
</span>
100 <span class=
"c"></span> <span class=
"nx">sClass
</span> <span class=
"o">=
</span> <span class=
"nx">sSource
</span><span class=
"o">.
</span><span class=
"nx">substring
</span><span class=
"o">(
</span><span class=
"m">0</span><span class=
"o">,
</span><span class=
"nx">spaceIndex
</span><span class=
"o">);
</span>
101 <span class=
"c">// The rest of the source
</span>
102 <span class=
"c"></span> <span class=
"nx">sDetail
</span> <span class=
"o">=
</span> <span class=
"nx">sSource
</span><span class=
"o">.
</span><span class=
"nx">substring
</span><span class=
"o">(
</span><span class=
"nx">spaceIndex
</span><span class=
"o">,
</span><span class=
"nx">sSource
</span><span class=
"o">.
</span><span class=
"nx">length
</span><span class=
"o">);
</span>
103 <span class=
"o">}
</span>
104 <span class=
"k">else
</span> <span class=
"o">{
</span>
105 <span class=
"nx">sClass
</span> <span class=
"o">=
</span> <span class=
"nx">sSource
</span><span class=
"o">;
</span>
106 <span class=
"o">}
</span>
107 <span class=
"k">if
</span><span class=
"o">(
</span><span class=
"k">this
</span><span class=
"o">.
</span><span class=
"nx">_isNewSource
</span><span class=
"o">(
</span><span class=
"nx">sClass
</span><span class=
"o">))
</span> <span class=
"o">{
</span>
108 <span class=
"k">this
</span><span class=
"o">.
</span><span class=
"nx">_createNewSource
</span><span class=
"o">(
</span><span class=
"nx">sClass
</span><span class=
"o">);
</span>
109 <span class=
"o">}
</span>
110 <span class=
"o">}
</span>
112 <span class=
"k">var
</span> <span class=
"nx">timestamp
</span> <span class=
"o">=
</span> <span class=
"k">new
</span> <span class=
"nb">Date
</span><span class=
"o">();
</span>
113 <span class=
"k">var
</span> <span class=
"nx">logEntry
</span> <span class=
"o">=
</span> <span class=
"k">new
</span> <span class=
"nx">YAHOO
</span><span class=
"o">.
</span><span class=
"nx">widget
</span><span class=
"o">.
</span><span class=
"nx">LogMsg
</span><span class=
"o">({
</span>
114 <span class=
"nx">msg
</span><span class=
"o">:
</span> <span class=
"nx">sMsg
</span><span class=
"o">,
</span>
115 <span class=
"nx">time
</span><span class=
"o">:
</span> <span class=
"nx">timestamp
</span><span class=
"o">,
</span>
116 <span class=
"nx">category
</span><span class=
"o">:
</span> <span class=
"nx">sCategory
</span><span class=
"o">,
</span>
117 <span class=
"nx">source
</span><span class=
"o">:
</span> <span class=
"nx">sClass
</span><span class=
"o">,
</span>
118 <span class=
"nx">sourceDetail
</span><span class=
"o">:
</span> <span class=
"nx">sDetail
</span>
119 <span class=
"o">});
</span>
121 <span class=
"k">var
</span> <span class=
"nx">stack
</span> <span class=
"o">=
</span> <span class=
"k">this
</span><span class=
"o">.
</span><span class=
"nx">_stack
</span><span class=
"o">;
</span>
122 <span class=
"k">var
</span> <span class=
"nx">maxStackEntries
</span> <span class=
"o">=
</span> <span class=
"k">this
</span><span class=
"o">.
</span><span class=
"nx">maxStackEntries
</span><span class=
"o">;
</span>
123 <span class=
"k">if
</span><span class=
"o">(
</span><span class=
"nx">maxStackEntries
</span> <span class=
"o">&&</span> <span class=
"o">!
</span><span class=
"nb">isNaN
</span><span class=
"o">(
</span><span class=
"nx">maxStackEntries
</span><span class=
"o">)
</span> <span class=
"o">&&</span>
124 <span class=
"o">(
</span><span class=
"nx">stack
</span><span class=
"o">.
</span><span class=
"nx">length
</span> <span class=
"o">>=
</span> <span class=
"nx">maxStackEntries
</span><span class=
"o">))
</span> <span class=
"o">{
</span>
125 <span class=
"nx">stack
</span><span class=
"o">.
</span><span class=
"nx">shift
</span><span class=
"o">();
</span>
126 <span class=
"o">}
</span>
127 <span class=
"nx">stack
</span><span class=
"o">.
</span><span class=
"nx">push
</span><span class=
"o">(
</span><span class=
"nx">logEntry
</span><span class=
"o">);
</span>
128 <span class=
"k">this
</span><span class=
"o">.
</span><span class=
"nx">newLogEvent
</span><span class=
"o">.
</span><span class=
"nx">fire
</span><span class=
"o">(
</span><span class=
"nx">logEntry
</span><span class=
"o">);
</span>
130 <span class=
"k">if
</span><span class=
"o">(
</span><span class=
"k">this
</span><span class=
"o">.
</span><span class=
"nx">_browserConsoleEnabled
</span><span class=
"o">)
</span> <span class=
"o">{
</span>
131 <span class=
"k">this
</span><span class=
"o">.
</span><span class=
"nx">_printToBrowserConsole
</span><span class=
"o">(
</span><span class=
"nx">logEntry
</span><span class=
"o">);
</span>
132 <span class=
"o">}
</span>
133 <span class=
"k">return
</span> <span class=
"kc">true
</span><span class=
"o">;
</span>
134 <span class=
"o">}
</span>
135 <span class=
"k">else
</span> <span class=
"o">{
</span>
136 <span class=
"k">return
</span> <span class=
"kc">false
</span><span class=
"o">;
</span>
137 <span class=
"o">}
</span>
138 <span class=
"o">};
</span>
140 <span class=
"c">/**
</span>
141 <span class=
"c"> * Resets internal stack and startTime, enables Logger, and fires logResetEvent.
</span>
142 <span class=
"c"> *
</span>
143 <span class=
"c"> * @method reset
</span>
144 <span class=
"c"> */
</span>
145 <span class=
"nx">YAHOO
</span><span class=
"o">.
</span><span class=
"nx">widget
</span><span class=
"o">.
</span><span class=
"nx">Logger
</span><span class=
"o">.
</span><span class=
"nx">reset
</span> <span class=
"o">=
</span> <span class=
"k">function
</span><span class=
"o">()
</span> <span class=
"o">{
</span>
146 <span class=
"k">this
</span><span class=
"o">.
</span><span class=
"nx">_stack
</span> <span class=
"o">=
</span> <span class=
"o">[];
</span>
147 <span class=
"k">this
</span><span class=
"o">.
</span><span class=
"nx">_startTime
</span> <span class=
"o">=
</span> <span class=
"k">new
</span> <span class=
"nb">Date
</span><span class=
"o">().
</span><span class=
"nx">getTime
</span><span class=
"o">();
</span>
148 <span class=
"k">this
</span><span class=
"o">.
</span><span class=
"nx">loggerEnabled
</span> <span class=
"o">=
</span> <span class=
"kc">true
</span><span class=
"o">;
</span>
149 <span class=
"k">this
</span><span class=
"o">.
</span><span class=
"nx">log
</span><span class=
"o">(
</span><span class=
"s2">"Logger reset
"</span><span class=
"o">);
</span>
150 <span class=
"k">this
</span><span class=
"o">.
</span><span class=
"nx">logResetEvent
</span><span class=
"o">.
</span><span class=
"nx">fire
</span><span class=
"o">();
</span>
151 <span class=
"o">};
</span>
153 <span class=
"c">/**
</span>
154 <span class=
"c"> * Public accessor to internal stack of log message objects.
</span>
155 <span class=
"c"> *
</span>
156 <span class=
"c"> * @method getStack
</span>
157 <span class=
"c"> * @return {Object[]} Array of log message objects.
</span>
158 <span class=
"c"> */
</span>
159 <span class=
"nx">YAHOO
</span><span class=
"o">.
</span><span class=
"nx">widget
</span><span class=
"o">.
</span><span class=
"nx">Logger
</span><span class=
"o">.
</span><span class=
"nx">getStack
</span> <span class=
"o">=
</span> <span class=
"k">function
</span><span class=
"o">()
</span> <span class=
"o">{
</span>
160 <span class=
"k">return
</span> <span class=
"k">this
</span><span class=
"o">.
</span><span class=
"nx">_stack
</span><span class=
"o">;
</span>
161 <span class=
"o">};
</span>
163 <span class=
"c">/**
</span>
164 <span class=
"c"> * Public accessor to internal start time.
</span>
165 <span class=
"c"> *
</span>
166 <span class=
"c"> * @method getStartTime
</span>
167 <span class=
"c"> * @return {Date} Internal date of when Logger singleton was initialized.
</span>
168 <span class=
"c"> */
</span>
169 <span class=
"nx">YAHOO
</span><span class=
"o">.
</span><span class=
"nx">widget
</span><span class=
"o">.
</span><span class=
"nx">Logger
</span><span class=
"o">.
</span><span class=
"nx">getStartTime
</span> <span class=
"o">=
</span> <span class=
"k">function
</span><span class=
"o">()
</span> <span class=
"o">{
</span>
170 <span class=
"k">return
</span> <span class=
"k">this
</span><span class=
"o">.
</span><span class=
"nx">_startTime
</span><span class=
"o">;
</span>
171 <span class=
"o">};
</span>
173 <span class=
"c">/**
</span>
174 <span class=
"c"> * Disables output to the browser
's global console.log() function, which is used
</span>
175 <span class=
"c"> * by the Firebug extension to Firefox as well as Safari.
</span>
176 <span class=
"c"> *
</span>
177 <span class=
"c"> * @method disableBrowserConsole
</span>
178 <span class=
"c"> */
</span>
179 <span class=
"nx">YAHOO
</span><span class=
"o">.
</span><span class=
"nx">widget
</span><span class=
"o">.
</span><span class=
"nx">Logger
</span><span class=
"o">.
</span><span class=
"nx">disableBrowserConsole
</span> <span class=
"o">=
</span> <span class=
"k">function
</span><span class=
"o">()
</span> <span class=
"o">{
</span>
180 <span class=
"nx">YAHOO
</span><span class=
"o">.
</span><span class=
"nx">log
</span><span class=
"o">(
</span><span class=
"s2">"Logger output to the function console.log() has been disabled.
"</span><span class=
"o">);
</span>
181 <span class=
"k">this
</span><span class=
"o">.
</span><span class=
"nx">_browserConsoleEnabled
</span> <span class=
"o">=
</span> <span class=
"kc">false
</span><span class=
"o">;
</span>
182 <span class=
"o">};
</span>
184 <span class=
"c">/**
</span>
185 <span class=
"c"> * Enables output to the browser
's global console.log() function, which is used
</span>
186 <span class=
"c"> * by the Firebug extension to Firefox as well as Safari.
</span>
187 <span class=
"c"> *
</span>
188 <span class=
"c"> * @method enableBrowserConsole
</span>
189 <span class=
"c"> */
</span>
190 <span class=
"nx">YAHOO
</span><span class=
"o">.
</span><span class=
"nx">widget
</span><span class=
"o">.
</span><span class=
"nx">Logger
</span><span class=
"o">.
</span><span class=
"nx">enableBrowserConsole
</span> <span class=
"o">=
</span> <span class=
"k">function
</span><span class=
"o">()
</span> <span class=
"o">{
</span>
191 <span class=
"k">this
</span><span class=
"o">.
</span><span class=
"nx">_browserConsoleEnabled
</span> <span class=
"o">=
</span> <span class=
"kc">true
</span><span class=
"o">;
</span>
192 <span class=
"nx">YAHOO
</span><span class=
"o">.
</span><span class=
"nx">log
</span><span class=
"o">(
</span><span class=
"s2">"Logger output to the function console.log() has been enabled.
"</span><span class=
"o">);
</span>
193 <span class=
"o">};
</span>
195 <span class=
"c">/////////////////////////////////////////////////////////////////////////////
</span>
196 <span class=
"c">//
</span>
197 <span class=
"c">// Public events
</span>
198 <span class=
"c">//
</span>
199 <span class=
"c">/////////////////////////////////////////////////////////////////////////////
</span>
200 <span class=
"c"></span>
201 <span class=
"c">/**
</span>
202 <span class=
"c"> * Fired when a new category has been created.
</span>
203 <span class=
"c"> *
</span>
204 <span class=
"c"> * @event categoryCreateEvent
</span>
205 <span class=
"c"> * @param sCategory {String} Category name.
</span>
206 <span class=
"c"> */
</span>
207 <span class=
"nx">YAHOO
</span><span class=
"o">.
</span><span class=
"nx">widget
</span><span class=
"o">.
</span><span class=
"nx">Logger
</span><span class=
"o">.
</span><span class=
"nx">categoryCreateEvent
</span> <span class=
"o">=
</span>
208 <span class=
"k">new
</span> <span class=
"nx">YAHOO
</span><span class=
"o">.
</span><span class=
"nx">util
</span><span class=
"o">.
</span><span class=
"nx">CustomEvent
</span><span class=
"o">(
</span><span class=
"s2">"categoryCreate
"</span><span class=
"o">,
</span> <span class=
"k">this
</span><span class=
"o">,
</span> <span class=
"kc">true
</span><span class=
"o">);
</span>
210 <span class=
"c">/**
</span>
211 <span class=
"c"> * Fired when a new source has been named.
</span>
212 <span class=
"c"> *
</span>
213 <span class=
"c"> * @event sourceCreateEvent
</span>
214 <span class=
"c"> * @param sSource {String} Source name.
</span>
215 <span class=
"c"> */
</span>
216 <span class=
"nx">YAHOO
</span><span class=
"o">.
</span><span class=
"nx">widget
</span><span class=
"o">.
</span><span class=
"nx">Logger
</span><span class=
"o">.
</span><span class=
"nx">sourceCreateEvent
</span> <span class=
"o">=
</span>
217 <span class=
"k">new
</span> <span class=
"nx">YAHOO
</span><span class=
"o">.
</span><span class=
"nx">util
</span><span class=
"o">.
</span><span class=
"nx">CustomEvent
</span><span class=
"o">(
</span><span class=
"s2">"sourceCreate
"</span><span class=
"o">,
</span> <span class=
"k">this
</span><span class=
"o">,
</span> <span class=
"kc">true
</span><span class=
"o">);
</span>
219 <span class=
"c">/**
</span>
220 <span class=
"c"> * Fired when a new log message has been created.
</span>
221 <span class=
"c"> *
</span>
222 <span class=
"c"> * @event newLogEvent
</span>
223 <span class=
"c"> * @param sMsg {String} Log message.
</span>
224 <span class=
"c"> */
</span>
225 <span class=
"nx">YAHOO
</span><span class=
"o">.
</span><span class=
"nx">widget
</span><span class=
"o">.
</span><span class=
"nx">Logger
</span><span class=
"o">.
</span><span class=
"nx">newLogEvent
</span> <span class=
"o">=
</span> <span class=
"k">new
</span> <span class=
"nx">YAHOO
</span><span class=
"o">.
</span><span class=
"nx">util
</span><span class=
"o">.
</span><span class=
"nx">CustomEvent
</span><span class=
"o">(
</span><span class=
"s2">"newLog
"</span><span class=
"o">,
</span> <span class=
"k">this
</span><span class=
"o">,
</span> <span class=
"kc">true
</span><span class=
"o">);
</span>
227 <span class=
"c">/**
</span>
228 <span class=
"c"> * Fired when the Logger has been reset has been created.
</span>
229 <span class=
"c"> *
</span>
230 <span class=
"c"> * @event logResetEvent
</span>
231 <span class=
"c"> */
</span>
232 <span class=
"nx">YAHOO
</span><span class=
"o">.
</span><span class=
"nx">widget
</span><span class=
"o">.
</span><span class=
"nx">Logger
</span><span class=
"o">.
</span><span class=
"nx">logResetEvent
</span> <span class=
"o">=
</span> <span class=
"k">new
</span> <span class=
"nx">YAHOO
</span><span class=
"o">.
</span><span class=
"nx">util
</span><span class=
"o">.
</span><span class=
"nx">CustomEvent
</span><span class=
"o">(
</span><span class=
"s2">"logReset
"</span><span class=
"o">,
</span> <span class=
"k">this
</span><span class=
"o">,
</span> <span class=
"kc">true
</span><span class=
"o">);
</span>
234 <span class=
"c">/////////////////////////////////////////////////////////////////////////////
</span>
235 <span class=
"c">//
</span>
236 <span class=
"c">// Private methods
</span>
237 <span class=
"c">//
</span>
238 <span class=
"c">/////////////////////////////////////////////////////////////////////////////
</span>
239 <span class=
"c"></span>
240 <span class=
"c">/**
</span>
241 <span class=
"c"> * Creates a new category of log messages and fires categoryCreateEvent.
</span>
242 <span class=
"c"> *
</span>
243 <span class=
"c"> * @method _createNewCategory
</span>
244 <span class=
"c"> * @param sCategory {String} Category name.
</span>
245 <span class=
"c"> * @private
</span>
246 <span class=
"c"> */
</span>
247 <span class=
"nx">YAHOO
</span><span class=
"o">.
</span><span class=
"nx">widget
</span><span class=
"o">.
</span><span class=
"nx">Logger
</span><span class=
"o">.
</span><span class=
"nx">_createNewCategory
</span> <span class=
"o">=
</span> <span class=
"k">function
</span><span class=
"o">(
</span><span class=
"nx">sCategory
</span><span class=
"o">)
</span> <span class=
"o">{
</span>
248 <span class=
"k">this
</span><span class=
"o">.
</span><span class=
"nx">categories
</span><span class=
"o">.
</span><span class=
"nx">push
</span><span class=
"o">(
</span><span class=
"nx">sCategory
</span><span class=
"o">);
</span>
249 <span class=
"k">this
</span><span class=
"o">.
</span><span class=
"nx">categoryCreateEvent
</span><span class=
"o">.
</span><span class=
"nx">fire
</span><span class=
"o">(
</span><span class=
"nx">sCategory
</span><span class=
"o">);
</span>
250 <span class=
"o">};
</span>
252 <span class=
"c">/**
</span>
253 <span class=
"c"> * Checks to see if a category has already been created.
</span>
254 <span class=
"c"> *
</span>
255 <span class=
"c"> * @method _isNewCategory
</span>
256 <span class=
"c"> * @param sCategory {String} Category name.
</span>
257 <span class=
"c"> * @return {Boolean} Returns true if category is unknown, else returns false.
</span>
258 <span class=
"c"> * @private
</span>
259 <span class=
"c"> */
</span>
260 <span class=
"nx">YAHOO
</span><span class=
"o">.
</span><span class=
"nx">widget
</span><span class=
"o">.
</span><span class=
"nx">Logger
</span><span class=
"o">.
</span><span class=
"nx">_isNewCategory
</span> <span class=
"o">=
</span> <span class=
"k">function
</span><span class=
"o">(
</span><span class=
"nx">sCategory
</span><span class=
"o">)
</span> <span class=
"o">{
</span>
261 <span class=
"k">for
</span><span class=
"o">(
</span><span class=
"k">var
</span> <span class=
"nx">i
</span><span class=
"o">=
</span><span class=
"m">0</span><span class=
"o">;
</span> <span class=
"nx">i
</span> <span class=
"o"><</span> <span class=
"k">this
</span><span class=
"o">.
</span><span class=
"nx">categories
</span><span class=
"o">.
</span><span class=
"nx">length
</span><span class=
"o">;
</span> <span class=
"nx">i
</span><span class=
"o">++)
</span> <span class=
"o">{
</span>
262 <span class=
"k">if
</span><span class=
"o">(
</span><span class=
"nx">sCategory
</span> <span class=
"o">==
</span> <span class=
"k">this
</span><span class=
"o">.
</span><span class=
"nx">categories
</span><span class=
"o">[
</span><span class=
"nx">i
</span><span class=
"o">])
</span> <span class=
"o">{
</span>
263 <span class=
"k">return
</span> <span class=
"kc">false
</span><span class=
"o">;
</span>
264 <span class=
"o">}
</span>
265 <span class=
"o">}
</span>
266 <span class=
"k">return
</span> <span class=
"kc">true
</span><span class=
"o">;
</span>
267 <span class=
"o">};
</span>
269 <span class=
"c">/**
</span>
270 <span class=
"c"> * Creates a new source of log messages and fires sourceCreateEvent.
</span>
271 <span class=
"c"> *
</span>
272 <span class=
"c"> * @method _createNewSource
</span>
273 <span class=
"c"> * @param sSource {String} Source name.
</span>
274 <span class=
"c"> * @private
</span>
275 <span class=
"c"> */
</span>
276 <span class=
"nx">YAHOO
</span><span class=
"o">.
</span><span class=
"nx">widget
</span><span class=
"o">.
</span><span class=
"nx">Logger
</span><span class=
"o">.
</span><span class=
"nx">_createNewSource
</span> <span class=
"o">=
</span> <span class=
"k">function
</span><span class=
"o">(
</span><span class=
"nx">sSource
</span><span class=
"o">)
</span> <span class=
"o">{
</span>
277 <span class=
"k">this
</span><span class=
"o">.
</span><span class=
"nx">sources
</span><span class=
"o">.
</span><span class=
"nx">push
</span><span class=
"o">(
</span><span class=
"nx">sSource
</span><span class=
"o">);
</span>
278 <span class=
"k">this
</span><span class=
"o">.
</span><span class=
"nx">sourceCreateEvent
</span><span class=
"o">.
</span><span class=
"nx">fire
</span><span class=
"o">(
</span><span class=
"nx">sSource
</span><span class=
"o">);
</span>
279 <span class=
"o">};
</span>
281 <span class=
"c">/**
</span>
282 <span class=
"c"> * Checks to see if a source already exists.
</span>
283 <span class=
"c"> *
</span>
284 <span class=
"c"> * @method _isNewSource
</span>
285 <span class=
"c"> * @param sSource {String} Source name.
</span>
286 <span class=
"c"> * @return {Boolean} Returns true if source is unknown, else returns false.
</span>
287 <span class=
"c"> * @private
</span>
288 <span class=
"c"> */
</span>
289 <span class=
"nx">YAHOO
</span><span class=
"o">.
</span><span class=
"nx">widget
</span><span class=
"o">.
</span><span class=
"nx">Logger
</span><span class=
"o">.
</span><span class=
"nx">_isNewSource
</span> <span class=
"o">=
</span> <span class=
"k">function
</span><span class=
"o">(
</span><span class=
"nx">sSource
</span><span class=
"o">)
</span> <span class=
"o">{
</span>
290 <span class=
"k">if
</span><span class=
"o">(
</span><span class=
"nx">sSource
</span><span class=
"o">)
</span> <span class=
"o">{
</span>
291 <span class=
"k">for
</span><span class=
"o">(
</span><span class=
"k">var
</span> <span class=
"nx">i
</span><span class=
"o">=
</span><span class=
"m">0</span><span class=
"o">;
</span> <span class=
"nx">i
</span> <span class=
"o"><</span> <span class=
"k">this
</span><span class=
"o">.
</span><span class=
"nx">sources
</span><span class=
"o">.
</span><span class=
"nx">length
</span><span class=
"o">;
</span> <span class=
"nx">i
</span><span class=
"o">++)
</span> <span class=
"o">{
</span>
292 <span class=
"k">if
</span><span class=
"o">(
</span><span class=
"nx">sSource
</span> <span class=
"o">==
</span> <span class=
"k">this
</span><span class=
"o">.
</span><span class=
"nx">sources
</span><span class=
"o">[
</span><span class=
"nx">i
</span><span class=
"o">])
</span> <span class=
"o">{
</span>
293 <span class=
"k">return
</span> <span class=
"kc">false
</span><span class=
"o">;
</span>
294 <span class=
"o">}
</span>
295 <span class=
"o">}
</span>
296 <span class=
"k">return
</span> <span class=
"kc">true
</span><span class=
"o">;
</span>
297 <span class=
"o">}
</span>
298 <span class=
"o">};
</span>
300 <span class=
"c">/**
</span>
301 <span class=
"c"> * Outputs a log message to global console.log() function.
</span>
302 <span class=
"c"> *
</span>
303 <span class=
"c"> * @method _printToBrowserConsole
</span>
304 <span class=
"c"> * @param oEntry {Object} Log entry object.
</span>
305 <span class=
"c"> * @private
</span>
306 <span class=
"c"> */
</span>
307 <span class=
"nx">YAHOO
</span><span class=
"o">.
</span><span class=
"nx">widget
</span><span class=
"o">.
</span><span class=
"nx">Logger
</span><span class=
"o">.
</span><span class=
"nx">_printToBrowserConsole
</span> <span class=
"o">=
</span> <span class=
"k">function
</span><span class=
"o">(
</span><span class=
"nx">oEntry
</span><span class=
"o">)
</span> <span class=
"o">{
</span>
308 <span class=
"k">if
</span><span class=
"o">(
</span><span class=
"nb">window
</span><span class=
"o">.
</span><span class=
"nx">console
</span> <span class=
"o">&&</span> <span class=
"nx">console
</span><span class=
"o">.
</span><span class=
"nx">log
</span><span class=
"o">)
</span> <span class=
"o">{
</span>
309 <span class=
"k">var
</span> <span class=
"nx">category
</span> <span class=
"o">=
</span> <span class=
"nx">oEntry
</span><span class=
"o">.
</span><span class=
"nx">category
</span><span class=
"o">;
</span>
310 <span class=
"k">var
</span> <span class=
"k">label
</span> <span class=
"o">=
</span> <span class=
"nx">oEntry
</span><span class=
"o">.
</span><span class=
"nx">category
</span><span class=
"o">.
</span><span class=
"nx">substring
</span><span class=
"o">(
</span><span class=
"m">0</span><span class=
"o">,
</span><span class=
"m">4</span><span class=
"o">).
</span><span class=
"nx">toUpperCase
</span><span class=
"o">();
</span>
312 <span class=
"k">var
</span> <span class=
"nx">time
</span> <span class=
"o">=
</span> <span class=
"nx">oEntry
</span><span class=
"o">.
</span><span class=
"nx">time
</span><span class=
"o">;
</span>
313 <span class=
"k">if
</span> <span class=
"o">(
</span><span class=
"nx">time
</span><span class=
"o">.
</span><span class=
"nx">toLocaleTimeString
</span><span class=
"o">)
</span> <span class=
"o">{
</span>
314 <span class=
"k">var
</span> <span class=
"nx">localTime
</span> <span class=
"o">=
</span> <span class=
"nx">time
</span><span class=
"o">.
</span><span class=
"nx">toLocaleTimeString
</span><span class=
"o">();
</span>
315 <span class=
"o">}
</span>
316 <span class=
"k">else
</span> <span class=
"o">{
</span>
317 <span class=
"nx">localTime
</span> <span class=
"o">=
</span> <span class=
"nx">time
</span><span class=
"o">.
</span><span class=
"nx">toString
</span><span class=
"o">();
</span>
318 <span class=
"o">}
</span>
320 <span class=
"k">var
</span> <span class=
"nx">msecs
</span> <span class=
"o">=
</span> <span class=
"nx">time
</span><span class=
"o">.
</span><span class=
"nx">getTime
</span><span class=
"o">();
</span>
321 <span class=
"k">var
</span> <span class=
"nx">elapsedTime
</span> <span class=
"o">=
</span> <span class=
"o">(
</span><span class=
"nx">YAHOO
</span><span class=
"o">.
</span><span class=
"nx">widget
</span><span class=
"o">.
</span><span class=
"nx">Logger
</span><span class=
"o">.
</span><span class=
"nx">_lastTime
</span><span class=
"o">)
</span> <span class=
"o">?
</span>
322 <span class=
"o">(
</span><span class=
"nx">msecs
</span> <span class=
"o">-
</span> <span class=
"nx">YAHOO
</span><span class=
"o">.
</span><span class=
"nx">widget
</span><span class=
"o">.
</span><span class=
"nx">Logger
</span><span class=
"o">.
</span><span class=
"nx">_lastTime
</span><span class=
"o">)
</span> <span class=
"o">:
</span> <span class=
"m">0</span><span class=
"o">;
</span>
323 <span class=
"nx">YAHOO
</span><span class=
"o">.
</span><span class=
"nx">widget
</span><span class=
"o">.
</span><span class=
"nx">Logger
</span><span class=
"o">.
</span><span class=
"nx">_lastTime
</span> <span class=
"o">=
</span> <span class=
"nx">msecs
</span><span class=
"o">;
</span>
325 <span class=
"k">var
</span> <span class=
"nx">output
</span> <span class=
"o">=
</span>
326 <span class=
"nx">localTime
</span> <span class=
"o">+
</span> <span class=
"s2">" (
"</span> <span class=
"o">+
</span>
327 <span class=
"nx">elapsedTime
</span> <span class=
"o">+
</span> <span class=
"s2">"ms):
"</span> <span class=
"o">+
</span>
328 <span class=
"nx">oEntry
</span><span class=
"o">.
</span><span class=
"nx">source
</span> <span class=
"o">+
</span> <span class=
"s2">":
"</span> <span class=
"o">+
</span>
329 <span class=
"nx">oEntry
</span><span class=
"o">.
</span><span class=
"nx">msg
</span><span class=
"o">;
</span>
331 <span class=
"nx">console
</span><span class=
"o">.
</span><span class=
"nx">log
</span><span class=
"o">(
</span><span class=
"nx">output
</span><span class=
"o">);
</span>
332 <span class=
"o">}
</span>
333 <span class=
"o">};
</span>
335 <span class=
"c">/////////////////////////////////////////////////////////////////////////////
</span>
336 <span class=
"c">//
</span>
337 <span class=
"c">// Private event handlers
</span>
338 <span class=
"c">//
</span>
339 <span class=
"c">/////////////////////////////////////////////////////////////////////////////
</span>
340 <span class=
"c"></span>
341 <span class=
"c">/**
</span>
342 <span class=
"c"> * Handles logging of messages due to window error events.
</span>
343 <span class=
"c"> *
</span>
344 <span class=
"c"> * @method _onWindowError
</span>
345 <span class=
"c"> * @param sMsg {String} The error message.
</span>
346 <span class=
"c"> * @param sUrl {String} URL of the error.
</span>
347 <span class=
"c"> * @param sLine {String} Line number of the error.
</span>
348 <span class=
"c"> * @private
</span>
349 <span class=
"c"> */
</span>
350 <span class=
"nx">YAHOO
</span><span class=
"o">.
</span><span class=
"nx">widget
</span><span class=
"o">.
</span><span class=
"nx">Logger
</span><span class=
"o">.
</span><span class=
"nx">_onWindowError
</span> <span class=
"o">=
</span> <span class=
"k">function
</span><span class=
"o">(
</span><span class=
"nx">sMsg
</span><span class=
"o">,
</span><span class=
"nx">sUrl
</span><span class=
"o">,
</span><span class=
"nx">sLine
</span><span class=
"o">)
</span> <span class=
"o">{
</span>
351 <span class=
"c">// Logger is not in scope of this event handler
</span>
352 <span class=
"c"></span> <span class=
"k">try
</span> <span class=
"o">{
</span>
353 <span class=
"nx">YAHOO
</span><span class=
"o">.
</span><span class=
"nx">widget
</span><span class=
"o">.
</span><span class=
"nx">Logger
</span><span class=
"o">.
</span><span class=
"nx">log
</span><span class=
"o">(
</span><span class=
"nx">sMsg
</span><span class=
"o">+
</span><span class=
"s1">' (
'</span><span class=
"o">+
</span><span class=
"nx">sUrl
</span><span class=
"o">+
</span><span class=
"s1">', line
'</span><span class=
"o">+
</span><span class=
"nx">sLine
</span><span class=
"o">+
</span><span class=
"s1">')
'</span><span class=
"o">,
</span> <span class=
"s2">"window
"</span><span class=
"o">);
</span>
354 <span class=
"k">if
</span><span class=
"o">(
</span><span class=
"nx">YAHOO
</span><span class=
"o">.
</span><span class=
"nx">widget
</span><span class=
"o">.
</span><span class=
"nx">Logger
</span><span class=
"o">.
</span><span class=
"nx">_origOnWindowError
</span><span class=
"o">)
</span> <span class=
"o">{
</span>
355 <span class=
"nx">YAHOO
</span><span class=
"o">.
</span><span class=
"nx">widget
</span><span class=
"o">.
</span><span class=
"nx">Logger
</span><span class=
"o">.
</span><span class=
"nx">_origOnWindowError
</span><span class=
"o">();
</span>
356 <span class=
"o">}
</span>
357 <span class=
"o">}
</span>
358 <span class=
"k">catch
</span><span class=
"o">(
</span><span class=
"nx">e
</span><span class=
"o">)
</span> <span class=
"o">{
</span>
359 <span class=
"k">return
</span> <span class=
"kc">false
</span><span class=
"o">;
</span>
360 <span class=
"o">}
</span>
361 <span class=
"o">};
</span>
363 <span class=
"c">/////////////////////////////////////////////////////////////////////////////
</span>
364 <span class=
"c">//
</span>
365 <span class=
"c">// Enable handling of native JavaScript errors
</span>
366 <span class=
"c">// NB: Not all browsers support the window.onerror event
</span>
367 <span class=
"c">//
</span>
368 <span class=
"c">/////////////////////////////////////////////////////////////////////////////
</span>
369 <span class=
"c"></span>
370 <span class=
"k">if
</span><span class=
"o">(
</span><span class=
"nb">window
</span><span class=
"o">.
</span><span class=
"nx">onerror
</span><span class=
"o">)
</span> <span class=
"o">{
</span>
371 <span class=
"c">// Save any previously defined handler to call
</span>
372 <span class=
"c"></span> <span class=
"nx">YAHOO
</span><span class=
"o">.
</span><span class=
"nx">widget
</span><span class=
"o">.
</span><span class=
"nx">Logger
</span><span class=
"o">.
</span><span class=
"nx">_origOnWindowError
</span> <span class=
"o">=
</span> <span class=
"nb">window
</span><span class=
"o">.
</span><span class=
"nx">onerror
</span><span class=
"o">;
</span>
373 <span class=
"o">}
</span>
374 <span class=
"nb">window
</span><span class=
"o">.
</span><span class=
"nx">onerror
</span> <span class=
"o">=
</span> <span class=
"nx">YAHOO
</span><span class=
"o">.
</span><span class=
"nx">widget
</span><span class=
"o">.
</span><span class=
"nx">Logger
</span><span class=
"o">.
</span><span class=
"nx">_onWindowError
</span><span class=
"o">;
</span>
376 <span class=
"c">/////////////////////////////////////////////////////////////////////////////
</span>
377 <span class=
"c">//
</span>
378 <span class=
"c">// First log
</span>
379 <span class=
"c">//
</span>
380 <span class=
"c">/////////////////////////////////////////////////////////////////////////////
</span>
381 <span class=
"c"></span>
382 <span class=
"nx">YAHOO
</span><span class=
"o">.
</span><span class=
"nx">widget
</span><span class=
"o">.
</span><span class=
"nx">Logger
</span><span class=
"o">.
</span><span class=
"nx">log
</span><span class=
"o">(
</span><span class=
"s2">"Logger initialized
"</span><span class=
"o">);
</span>
394 <li class=
""><a href=
"module_animation.html">animation
</a></li>
396 <li class=
""><a href=
"module_autocomplete.html">autocomplete
</a></li>
398 <li class=
""><a href=
"module_button.html">button
</a></li>
400 <li class=
""><a href=
"module_calendar.html">calendar
</a></li>
402 <li class=
""><a href=
"module_connection.html">connection
</a></li>
404 <li class=
""><a href=
"module_container.html">container
</a></li>
406 <li class=
""><a href=
"module_datasource.html">datasource
</a></li>
408 <li class=
""><a href=
"module_datatable.html">datatable
</a></li>
410 <li class=
""><a href=
"module_dom.html">dom
</a></li>
412 <li class=
""><a href=
"module_dragdrop.html">dragdrop
</a></li>
414 <li class=
""><a href=
"module_element.html">element
</a></li>
416 <li class=
""><a href=
"module_event.html">event
</a></li>
418 <li class=
""><a href=
"module_history.html">history
</a></li>
420 <li class=
"selected"><a href=
"module_logger.html">logger
</a></li>
422 <li class=
""><a href=
"module_menu.html">menu
</a></li>
424 <li class=
""><a href=
"module_slider.html">slider
</a></li>
426 <li class=
""><a href=
"module_tabview.html">tabview
</a></li>
428 <li class=
""><a href=
"module_treeview.html">treeview
</a></li>
430 <li class=
""><a href=
"module_yahoo.html">yahoo
</a></li>
437 <li class=
""><a href=
"LogMsg.html">LogMsg
</a></li>
438 <li class=
""><a href=
"LogReader.html">LogReader
</a></li>
439 <li class=
""><a href=
"LogWriter.html">LogWriter
</a></li>
440 <li class=
""><a href=
"YAHOO.widget.Logger.html">YAHOO.widget.Logger
</a></li>
447 <li class=
"selected"><a href=
"Logger.js.html">Logger.js
</a></li>
448 <li class=
""><a href=
"LogMsg.js.html">LogMsg.js
</a></li>
449 <li class=
""><a href=
"LogReader.js.html">LogReader.js
</a></li>
450 <li class=
""><a href=
"LogWriter.js.html">LogWriter.js
</a></li>
463 Copyright
© 2007 Yahoo! Inc. All rights reserved.