Skip to content
This repository was archived by the owner on Oct 18, 2024. It is now read-only.

Commit 48dcc33

Browse files
authored
Add example, update description (#103)
1 parent 575781e commit 48dcc33

File tree

3 files changed

+44
-5
lines changed

3 files changed

+44
-5
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
## 1.0.2-dev
1+
## 1.0.2
2+
3+
* Update description.
4+
* Add example.
25

36
## 1.0.1
47

example/main.dart

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import 'package:logging/logging.dart';
2+
3+
final log = Logger('ExampleLogger');
4+
5+
/// Example of configuring a logger to print to stdout.
6+
///
7+
/// This example will print:
8+
///
9+
/// INFO: 2021-09-13 15:35:10.703401: recursion: n = 4
10+
/// INFO: 2021-09-13 15:35:10.707974: recursion: n = 3
11+
/// Fibonacci(4) is: 3
12+
/// Fibonacci(5) is: 5
13+
/// SHOUT: 2021-09-13 15:35:10.708087: Unexpected negative n: -42
14+
/// Fibonacci(-42) is: 1
15+
void main() {
16+
Logger.root.level = Level.ALL; // defaults to Level.INFO
17+
Logger.root.onRecord.listen((record) {
18+
print('${record.level.name}: ${record.time}: ${record.message}');
19+
});
20+
21+
print('Fibonacci(4) is: ${fibonacci(4)}');
22+
23+
Logger.root.level = Level.SEVERE; // skip logs less then severe.
24+
print('Fibonacci(5) is: ${fibonacci(5)}');
25+
26+
print('Fibonacci(-42) is: ${fibonacci(-42)}');
27+
}
28+
29+
int fibonacci(int n) {
30+
if (n <= 2) {
31+
if (n < 0) log.shout('Unexpected negative n: $n');
32+
return 1;
33+
} else {
34+
log.info('recursion: n = $n');
35+
return fibonacci(n - 2) + fibonacci(n - 1);
36+
}
37+
}

pubspec.yaml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
name: logging
2-
version: 1.0.2-dev
2+
version: 1.0.2
33

44
description: >-
5-
Provides APIs for debugging and error logging. This library introduces
6-
abstractions similar to those used in other languages, such as the Closure
7-
JS Logger and java.util.logging.Logger.
5+
Provides APIs for debugging and error logging, similar to loggers in other
6+
languages, such as the Closure JS Logger and java.util.logging.Logger.
87
repository: https://github.com/dart-lang/logging
98

109
environment:

0 commit comments

Comments
 (0)