import 'dart:collection';

import 'package:flutter/foundation.dart';
import 'package:logging/logging.dart';

const _defaultMaxItems = 1000;

class LogService extends ChangeNotifier {
  var maxItems = _defaultMaxItems;

  final _events = Queue<LogRecord>();

  List<LogRecord> get events => UnmodifiableListView(_events);

  void add(LogRecord event) {
    // final logName = event.loggerName.isEmpty ? 'ROOT' : event.loggerName;
    // final msg =
    //     '${event.level.name} - $logName @ ${event.time}: ${event.message}';
    // print(msg);
    _events.add(event);
    if (_events.length > maxItems) {
      _events.removeFirst();
    }
    notifyListeners();
  }
}
