OLD | NEW |
---|---|
(Empty) | |
1 Support for logging. | |
sethladd
2014/07/24 16:48:13
Nit: start line with # ?
kevmoo
2014/07/24 17:44:18
Done.
| |
2 | |
sethladd
2014/07/24 16:48:13
READMEs often include notes about where to file bu
kevmoo
2014/07/24 17:44:18
There's already a license file in the package. We
| |
3 ## Initializing | |
4 | |
5 By default, the logging package does not do anything useful with the | |
6 log messages. You must configure the logging level and add a handler | |
7 for the log messages. | |
8 | |
9 Here is a simple logging configuration that logs all messages | |
10 via `print`. | |
11 | |
12 ```dart | |
13 Logger.root.level = Level.ALL; | |
14 Logger.root.onRecord.listen((LogRecord rec) { | |
15 print('${rec.level.name}: ${rec.time}: ${rec.message}'); | |
16 }); | |
17 ``` | |
18 | |
19 First, set the root [Level]. All messages at or above the level are | |
20 sent to the [onRecord] stream. | |
21 | |
22 Then, listen on the [onRecord] stream for [LogRecord] events. The | |
23 [LogRecord] class has various properties for the message, error, | |
24 logger name, and more. | |
25 | |
26 ## Logging messages | |
27 | |
28 Create a [Logger] with a unique name to easily identify the source | |
29 of the log messages. | |
30 | |
31 ```dart | |
32 final Logger log = new Logger('MyClassName'); | |
33 ``` | |
34 | |
35 Here is an example of logging a debug message and an error: | |
36 | |
37 ```dart | |
38 var future = doSomethingAsync().then((result) { | |
39 log.fine('Got the result: $result'); | |
40 processResult(result); | |
41 }).catchError((e, stackTrace) => log.severe('Oh noes!', e, stackTrace)); | |
42 ``` | |
43 | |
44 See the [Logger] class for the different logging methods. | |
OLD | NEW |