1 | /**
|
2 | * Defines a message level that may be used to control logging output.
|
3 | *
|
4 | * @final
|
5 | */
|
6 | export class Level {
|
7 | name_: string;
|
8 | value_: number;
|
9 |
|
10 | /**
|
11 | * @param {string} name the level's name.
|
12 | * @param {number} level the level's numeric value.
|
13 | */
|
14 | constructor(name: string, level: number);
|
15 |
|
16 | /** @override */
|
17 | toString(): string;
|
18 |
|
19 | /** This logger's name. */
|
20 | name: string;
|
21 |
|
22 | /** The numeric log level. */
|
23 | value: number;
|
24 |
|
25 | /**
|
26 | * Indicates no log messages should be recorded.
|
27 | * @constant
|
28 | */
|
29 | static OFF: Level;
|
30 | /**
|
31 | * Log messages with a level of `1000` or higher.
|
32 | * @constant
|
33 | */
|
34 | static SEVERE: Level;
|
35 | /**
|
36 | * Log messages with a level of `900` or higher.
|
37 | * @constant
|
38 | */
|
39 | static WARNING: Level;
|
40 | /**
|
41 | * Log messages with a level of `800` or higher.
|
42 | * @constant
|
43 | */
|
44 | static INFO: Level;
|
45 | /**
|
46 | * Log messages with a level of `700` or higher.
|
47 | * @constant
|
48 | */
|
49 | static DEBUG: Level;
|
50 | /**
|
51 | * Log messages with a level of `500` or higher.
|
52 | * @constant
|
53 | */
|
54 | static FINE: Level;
|
55 | /**
|
56 | * Log messages with a level of `400` or higher.
|
57 | * @constant
|
58 | */
|
59 | static FINER: Level;
|
60 | /**
|
61 | * Log messages with a level of `300` or higher.
|
62 | * @constant
|
63 | */
|
64 | static FINEST: Level;
|
65 | /**
|
66 | * Indicates all log messages should be recorded.
|
67 | * @constant
|
68 | */
|
69 | static ALL: Level;
|
70 | }
|
71 |
|
72 | /**
|
73 | * Converts a level name or value to a { logging.Level} value.
|
74 | * If the name/value is not recognized, { logging.Level.ALL}
|
75 | * will be returned.
|
76 | * number|string)} nameOrValue The log level name, or value, to
{( |
77 | * convert .
|
78 | * {!logging.Level} The converted level.
|
79 | */
|
80 | export function getLevel(nameOrValue: string | number): Level;
|
81 |
|
82 | export interface IEntryJSON {
|
83 | level: string;
|
84 | message: string;
|
85 | timestamp: number;
|
86 | type: string;
|
87 | }
|
88 |
|
89 | /**
|
90 | * A single log entry.
|
91 | */
|
92 | export class Entry {
|
93 | /**
|
94 | * @param {(!logging.Level|string)} level The entry level.
|
95 | * @param {string} message The log message.
|
96 | * @param {number=} opt_timestamp The time this entry was generated, in
|
97 | * milliseconds since 0:00:00, January 1, 1970 UTC. If omitted, the
|
98 | * current time will be used.
|
99 | * @param {string=} opt_type The log type, if known.
|
100 | */
|
101 | constructor(level: Level | string | number, message: string, opt_timestamp?: number, opt_type?: string | IType);
|
102 |
|
103 | level: Level;
|
104 |
|
105 | message: string;
|
106 |
|
107 | timestamp: number;
|
108 |
|
109 | type: string;
|
110 |
|
111 | /**
|
112 | * @return {{level: string, message: string, timestamp: number,
|
113 | * type: string}} The JSON representation of this entry.
|
114 | */
|
115 | toJSON(): IEntryJSON;
|
116 | }
|
117 |
|
118 | /**
|
119 | * An object used to log debugging messages. Loggers use a hierarchical,
|
120 | * dot-separated naming scheme. For instance, 'foo' is considered the parent of
|
121 | * the 'foo.bar' and an ancestor of 'foo.bar.baz'.
|
122 | *
|
123 | * Each logger may be assigned a {@linkplain #setLevel log level}, which
|
124 | * controls which level of messages will be reported to the
|
125 | * {@linkplain #addHandler handlers} attached to this instance. If a log level
|
126 | * is not explicitly set on a logger, it will inherit its parent.
|
127 | *
|
128 | * This class should never be directly instantiated. Instead, users should
|
129 | * obtain logger references using the {@linkplain ./logging.getLogger()
|
130 | * getLogger()} function.
|
131 | *
|
132 | * @final
|
133 | */
|
134 | export class Logger {
|
135 | /**
|
136 | * @param {string} name the name of this logger.
|
137 | * @param {Level=} opt_level the initial level for this logger.
|
138 | */
|
139 | constructor(name: string, opt_level?: Level);
|
140 |
|
141 | name_: string;
|
142 | level_: Level;
|
143 | parent_: Logger;
|
144 | handlers_: any;
|
145 |
|
146 | /** @return {string} the name of this logger. */
|
147 | getName(): string;
|
148 |
|
149 | /**
|
150 | * @param {Level} level the new level for this logger, or `null` if the logger
|
151 | * should inherit its level from its parent logger.
|
152 | */
|
153 | setLevel(level: Level): void;
|
154 |
|
155 | /** @return {Level} the log level for this logger. */
|
156 | getLevel(): Level;
|
157 |
|
158 | /**
|
159 | * @return {!Level} the effective level for this logger.
|
160 | */
|
161 | getEffectiveLevel(): Level;
|
162 |
|
163 | /**
|
164 | * @param {!Level} level the level to check.
|
165 | * @return {boolean} whether messages recorded at the given level are loggable
|
166 | * by this instance.
|
167 | */
|
168 | isLoggable(level: Level): boolean;
|
169 |
|
170 | /**
|
171 | * Adds a handler to this logger. The handler will be invoked for each message
|
172 | * logged with this instance, or any of its descendants.
|
173 | *
|
174 | * @param {function(!Entry)} handler the handler to add.
|
175 | */
|
176 | addHandler(handler: any): void;
|
177 |
|
178 | /**
|
179 | * Removes a handler from this logger.
|
180 | *
|
181 | * @param {function(!Entry)} handler the handler to remove.
|
182 | * @return {boolean} whether a handler was successfully removed.
|
183 | */
|
184 | removeHandler(handler: any): void;
|
185 |
|
186 | /**
|
187 | * Logs a message at the given level. The message may be defined as a string
|
188 | * or as a function that will return the message. If a function is provided,
|
189 | * it will only be invoked if this logger's
|
190 | * {@linkplain #getEffectiveLevel() effective log level} includes the given
|
191 | * `level`.
|
192 | *
|
193 | * @param {!Level} level the level at which to log the message.
|
194 | * @param {(string|function(): string)} loggable the message to log, or a
|
195 | * function that will return the message.
|
196 | */
|
197 | log(level: Level, loggable: string | Function): void;
|
198 |
|
199 | /**
|
200 | * Logs a message at the {@link Level.SEVERE} log level.
|
201 | * @param {(string|function(): string)} loggable the message to log, or a
|
202 | * function that will return the message.
|
203 | */
|
204 | severe(loggable: string | Function): void;
|
205 |
|
206 | /**
|
207 | * Logs a message at the {@link Level.WARNING} log level.
|
208 | * @param {(string|function(): string)} loggable the message to log, or a
|
209 | * function that will return the message.
|
210 | */
|
211 | warning(loggable: string | Function): void;
|
212 |
|
213 | /**
|
214 | * Logs a message at the {@link Level.INFO} log level.
|
215 | * @param {(string|function(): string)} loggable the message to log, or a
|
216 | * function that will return the message.
|
217 | */
|
218 | info(loggable: string | Function): void;
|
219 |
|
220 | /**
|
221 | * Logs a message at the {@link Level.DEBUG} log level.
|
222 | * @param {(string|function(): string)} loggable the message to log, or a
|
223 | * function that will return the message.
|
224 | */
|
225 | debug(loggable: string | Function): void;
|
226 |
|
227 | /**
|
228 | * Logs a message at the {@link Level.FINE} log level.
|
229 | * @param {(string|function(): string)} loggable the message to log, or a
|
230 | * function that will return the message.
|
231 | */
|
232 | fine(loggable: string | Function): void;
|
233 |
|
234 | /**
|
235 | * Logs a message at the {@link Level.FINER} log level.
|
236 | * @param {(string|function(): string)} loggable the message to log, or a
|
237 | * function that will return the message.
|
238 | */
|
239 | finer(loggable: string | Function): void;
|
240 |
|
241 | /**
|
242 | * Logs a message at the {@link Level.FINEST} log level.
|
243 | * @param {(string|function(): string)} loggable the message to log, or a
|
244 | * function that will return the message.
|
245 | */
|
246 | finest(loggable: string | Function): void;
|
247 | }
|
248 |
|
249 | /**
|
250 | * Maintains a collection of loggers.
|
251 | *
|
252 | * @final
|
253 | */
|
254 | export class LogManager {
|
255 | /**
|
256 | * Retrieves a named logger, creating it in the process. This function will
|
257 | * implicitly create the requested logger, and any of its parents, if they
|
258 | * do not yet exist.
|
259 | *
|
260 | * @param {string} name the logger's name.
|
261 | * @return {!Logger} the requested logger.
|
262 | */
|
263 | getLogger(name?: string): Logger;
|
264 |
|
265 | /**
|
266 | * Creates a new logger.
|
267 | *
|
268 | * @param {string} name the logger's name.
|
269 | * @param {!Logger} parent the logger's parent.
|
270 | * @return {!Logger} the new logger.
|
271 | */
|
272 | createLogger_(name: string, parent: Logger): Logger;
|
273 | }
|
274 |
|
275 | /**
|
276 | * Retrieves a named logger, creating it in the process. This function will
|
277 | * implicitly create the requested logger, and any of its parents, if they
|
278 | * do not yet exist.
|
279 | *
|
280 | * @param {string} name the logger's name.
|
281 | * @return {!Logger} the requested logger.
|
282 | */
|
283 | export function getLogger(name?: string): Logger;
|
284 |
|
285 | /**
|
286 | * Adds the console handler to the given logger. The console handler will log
|
287 | * all messages using the JavaScript Console API.
|
288 | *
|
289 | * @param {Logger=} opt_logger The logger to add the handler to; defaults
|
290 | * to the root logger.
|
291 | */
|
292 | export function addConsoleHandler(opt_logger?: Logger): void;
|
293 |
|
294 | /**
|
295 | * Removes the console log handler from the given logger.
|
296 | *
|
297 | * @param {Logger=} opt_logger The logger to remove the handler from; defaults
|
298 | * to the root logger.
|
299 | * @see exports.addConsoleHandler
|
300 | */
|
301 | export function removeConsoleHandler(opt_logger?: Logger): void;
|
302 |
|
303 | /**
|
304 | * Installs the console log handler on the root logger.
|
305 | */
|
306 | export function installConsoleHandler(): void;
|
307 |
|
308 | export interface IType {
|
309 | /** Logs originating from the browser. */
|
310 | BROWSER: string;
|
311 | /** Logs from a WebDriver client. */
|
312 | CLIENT: string;
|
313 | /** Logs from a WebDriver implementation. */
|
314 | DRIVER: string;
|
315 | /** Logs related to performance. */
|
316 | PERFORMANCE: string;
|
317 | /** Logs from the remote server. */
|
318 | SERVER: string;
|
319 | }
|
320 |
|
321 | /**
|
322 | * Common log types.
|
323 | */
|
324 | export const Type: IType;
|
325 |
|
326 | /**
|
327 | * Describes the log preferences for a WebDriver session.
|
328 | */
|
329 | export class Preferences {
|
330 | prefs_: Map<string, Level>;
|
331 |
|
332 | constructor();
|
333 |
|
334 | /**
|
335 | * Sets the desired logging level for a particular log type.
|
336 | * @param {(string|Type)} type The log type.
|
337 | * string|number)} level The desired log level.
{(!Level| |
338 | * TypeError} if `type` is not a `string`.
{ |
339 | */
|
340 | setLevel(type: string | IType, level: Level): void;
|
341 |
|
342 | /**
|
343 | * Converts this instance to its JSON representation.
|
344 | * @return {!Object<string, string>} The JSON representation of this set of
|
345 | * preferences.
|
346 | */
|
347 | toJSON(): { [key: string]: string };
|
348 | }
|