mark 0.3.0 copy "mark: ^0.3.0" to clipboard
mark: ^0.3.0 copied to clipboard

Extensible and customizable logging framework for Dart and Flutter.

example/mark_example.dart

import 'dart:io';

import 'package:mark/mark.dart';

import 'custom_message.dart';
import 'custom_processor.dart';

Future<void> main(List<String> args) async {
  final logs = File('logs.csv').openWrite(mode: FileMode.append)
    ..write(
      'Type, Meta, StackTrace, Data\n',
    );

  final logger = Logger(
    processors: [
      const EphemeralMessageProcessor(),
      FileMessageProcessor(sink: logs),
    ],
  )..info('Started example');

  await ZonedMeta.attach(
    'Counter',
    () => counterExample(logger),
  );
  ZonedMeta.attach(
    'Exceptions',
    () => exceptionsExample(logger),
  );
  logger.info('Finished example');
  await logs.flush();
  await logs.close();
  await logger.dispose();
}

Future<void> counterExample(Logger sourceLogger) async {
  final counterProcessor = CounterMessagesProcessor();
  final logger = sourceLogger.fork(
    processors: [
      counterProcessor,
    ],
  );
  var counter = 0;
  void mutateCounter(int delta) {
    counter += delta;
    logger.counter(delta);
  }

  while (counter < 10) {
    mutateCounter(1);
  }
  mutateCounter(-2);
  logger.info('Deltas history: ${counterProcessor.history}');
  await logger.dispose();
}

void exceptionsExample(Logger logger) {
  try {
    throw Exception('Example exception');
  } on Object catch (e, s) {
    logger.error(e, stackTrace: s);
  }
}
4
likes
160
points
299
downloads

Publisher

verified publisheryakov.codes

Weekly Downloads

Extensible and customizable logging framework for Dart and Flutter.

Repository (GitHub)
View/report issues

Documentation

Documentation
API reference

License

MIT (license)

Dependencies

meta

More

Packages that depend on mark