Skip to content

Commit

Permalink
Add example, update description (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
mit-mit committed Sep 14, 2021
1 parent 575781e commit 48dcc33
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 5 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
@@ -1,4 +1,7 @@
## 1.0.2-dev
## 1.0.2

* Update description.
* Add example.

## 1.0.1

Expand Down
37 changes: 37 additions & 0 deletions example/main.dart
@@ -0,0 +1,37 @@
import 'package:logging/logging.dart';

final log = Logger('ExampleLogger');

/// Example of configuring a logger to print to stdout.
///
/// This example will print:
///
/// INFO: 2021-09-13 15:35:10.703401: recursion: n = 4
/// INFO: 2021-09-13 15:35:10.707974: recursion: n = 3
/// Fibonacci(4) is: 3
/// Fibonacci(5) is: 5
/// SHOUT: 2021-09-13 15:35:10.708087: Unexpected negative n: -42
/// Fibonacci(-42) is: 1
void main() {
Logger.root.level = Level.ALL; // defaults to Level.INFO
Logger.root.onRecord.listen((record) {
print('${record.level.name}: ${record.time}: ${record.message}');
});

print('Fibonacci(4) is: ${fibonacci(4)}');

Logger.root.level = Level.SEVERE; // skip logs less then severe.
print('Fibonacci(5) is: ${fibonacci(5)}');

print('Fibonacci(-42) is: ${fibonacci(-42)}');
}

int fibonacci(int n) {
if (n <= 2) {
if (n < 0) log.shout('Unexpected negative n: $n');
return 1;
} else {
log.info('recursion: n = $n');
return fibonacci(n - 2) + fibonacci(n - 1);
}
}
7 changes: 3 additions & 4 deletions pubspec.yaml
@@ -1,10 +1,9 @@
name: logging
version: 1.0.2-dev
version: 1.0.2

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

environment:
Expand Down

0 comments on commit 48dcc33

Please sign in to comment.