Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(45)

Side by Side Diff: pkg/logging/README.md

Issue 814113004: Pull args, intl, logging, shelf, and source_maps out of the SDK. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Also csslib. Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/logging/PATENTS ('k') | pkg/logging/lib/logging.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 ## Initializing
2
3 By default, the logging package does not do anything useful with the
4 log messages. You must configure the logging level and add a handler
5 for the log messages.
6
7 Here is a simple logging configuration that logs all messages
8 via `print`.
9
10 ```dart
11 Logger.root.level = Level.ALL;
12 Logger.root.onRecord.listen((LogRecord rec) {
13 print('${rec.level.name}: ${rec.time}: ${rec.message}');
14 });
15 ```
16
17 First, set the root [Level]. All messages at or above the level are
18 sent to the [onRecord] stream.
19
20 Then, listen on the [onRecord] stream for [LogRecord] events. The
21 [LogRecord] class has various properties for the message, error,
22 logger name, and more.
23
24 ## Logging messages
25
26 Create a [Logger] with a unique name to easily identify the source
27 of the log messages.
28
29 ```dart
30 final Logger log = new Logger('MyClassName');
31 ```
32
33 Here is an example of logging a debug message and an error:
34
35 ```dart
36 var future = doSomethingAsync().then((result) {
37 log.fine('Got the result: $result');
38 processResult(result);
39 }).catchError((e, stackTrace) => log.severe('Oh noes!', e, stackTrace));
40 ```
41
42 When logging more complex messages, you can pass a closure instead
43 that will be evaluated only if the message is actually logged:
44
45 ```dart
46 log.fine(() => [1, 2, 3, 4, 5].map((e) => e * 4).join("-"));
47 ```
48
49 See the [Logger] class for the different logging methods.
OLDNEW
« no previous file with comments | « pkg/logging/PATENTS ('k') | pkg/logging/lib/logging.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698