tdiwef_logging 1.0.1 copy "tdiwef_logging: ^1.0.1" to clipboard
tdiwef_logging: ^1.0.1 copied to clipboard

Fork from package logging-1.0.2. Changed logging levels to tfiwer style Provides APIs for debugging and error logging, similar to loggers in other languages, such as the NodeJS.

example/main.dart

import 'package:tdiwef_logging/tdiwef_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.ERROR; // 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.fatal('Unexpected negative n: $n');
    return 1;
  } else {
    log.info('recursion: n = $n');
    return fibonacci(n - 2) + fibonacci(n - 1);
  }
}
0
likes
140
pub points
0%
popularity

Publisher

unverified uploader

Fork from package logging-1.0.2. Changed logging levels to tfiwer style Provides APIs for debugging and error logging, similar to loggers in other languages, such as the NodeJS.

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (LICENSE)

More

Packages that depend on tdiwef_logging