log method

void log(
  1. String eventName,
  2. EventLevel level,
  3. Map<String, dynamic> parameters
)

Logs an event to the Firebase Firestore database.

This method logs an event to the Firebase Firestore database. The event is stored in the 'logs' collection.

  • eventName is the name of the event.
  • level is the level of the event. (info, warning, error, trace, debug)
  • parameters is a map containing the parameters of the event.

Example:

EventLogger.logEvent("login", EventLevel.info, {
"custom_parameter": "custom_value",
});

The event will be stored in the 'logs' collection with the following fields:

  • user_id: The UID of the current user.
  • email: The email of the current user.
  • level: The level of the event.
  • event: The name of the event.
  • timestamp: The timestamp of the event.
  • custom_parameter: The custom value of the event.

Implementation

void log(
    String eventName, EventLevel level, Map<String, dynamic> parameters) {
  FirebaseFirestore.instance.collection(_collectionName).add(
        parameters
          ..addAll({
            'user_id': currentUserUid(),
            'email': currentUserEmail(),
            'level': level.toString().split('.').last,
            'event': eventName,
            'timestamp': DateTime.now(),
          }),
      );
  _localLogger.log(eventName, level, parameters);
}