omnilog 0.0.1 copy "omnilog: ^0.0.1" to clipboard
omnilog: ^0.0.1 copied to clipboard

OmniLog.

example/example.dart

import 'dart:io';

import 'package:omnilog/omnilog.dart';

Object? addTimestamp(Object? message) => '${DateTime.now().toIso8601String()}: $message';

bool isA<T>(Object? message) => message is T;

bool isNotA<T>(Object? message) => message is! T;

Logger initLogger(File logFile, [bool isDebug = true]) => MultiLogger([
      TransformLogger.pass(FileLogger(logFile), addTimestamp),
      if (isDebug) ...[
        FilterLogger(IOLogger(stdout), (message) => isNotA<Error>(message)),
        FilterLogger(IOLogger(stderr), (message) => isA<Error>(message)),
      ],
    ]);

void startLogging(Logger logger) {
  void log() {
    logger
      ..log(0.5)
      ..log('Hello, world!')
      ..log(null)
      ..log(UnimplementedError())
      ..log(logger);

    Future.delayed(Duration(seconds: 1), log);
  }

  log();
}

class TestModule {
  final Logger logger;

  TestModule(this.logger) {
    startLogging(logger);
  }
}

Object? Function(Object?) addLabel(String label) {
  String func(Object? message) => '$label $message';

  return func;
}

void main(List<String> arguments) {
  final logger = initLogger(File('log.txt'));

  TestModule(TransformLogger.pass(logger, addLabel('[Module A]')));
  TestModule(TransformLogger.pass(logger, addLabel('[Module B]')));
  TestModule(TransformLogger.pass(logger, addLabel('[Module C]')));
}
0
likes
115
points
51
downloads

Publisher

unverified uploader

Weekly Downloads

OmniLog.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

equatable, meta

More

Packages that depend on omnilog