How to implement logging in flutter web app using Logger package

I am trying to add logging to my Flutter web app by using the Logger package.

I have followed the documentation on the Logger page in Pub.dev but I have not been successful, yet.

I have added the package, created the ddLog variable and put it in the catch portion of the try/catch.

I am getting an error on ddLog. Here is the error:

Instance members can’t be accessed from a static method.

Why am I getting this error?

This is the code where I am trying to use the Logger:

import 'dart:convert';
import 'dart:io';

import 'package:add_2_calendar/add_2_calendar.dart';
import 'package:deal_diligence/Providers/event_provider.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:google_sign_in/google_sign_in.dart';
import 'package:http/http.dart' as http;
import 'package:logger/logger.dart';

final GoogleSignIn _googleSignIn = GoogleSignIn(
  clientId: dotenv.env["GOOGLE_CALENDAR_CLIENT_ID"],
  scopes: [
    'https://www.googleapis.com/auth/calendar',
  ],
);

class AddEventsToAllCalendars {
  static GoogleSignInAuthentication? auth;
  var ddLog = Logger(
    filter: null, 
    printer: PrettyPrinter(), 
    output: FileOutput(file: File("../lib/log.txt")), 
  );

  static void addEvent(Events eventCal) async {
    // Define your custom format using DateFormat
    GoogleSignInAuthentication? auth;
    if (!kIsWeb) {
      Add2Calendar.addEvent2Cal(buildEvent(eventCal));
    } else {
      try {
        final signInAccountSilently = await _googleSignIn.signInSilently();
        if (signInAccountSilently != null) {
          auth = await signInAccountSilently.authentication;
        } else {
          final signInAccount = await _googleSignIn.signIn();
          auth = await signInAccount?.authentication;
        }

        if (auth == null) return;
        const String calendarId =
            "primary"; // Use 'primary' for the default calendar.
        const String url =
            'https://www.googleapis.com/calendar/v3/calendars/$calendarId/events';
        debugPrint("EventDate: ${eventCal.eventDate?.toIso8601String()}");
        debugPrint("EventDuration: ${eventCal.eventDuration}");
        final event = {
          "summary": eventCal.eventName,
          "description": eventCal.eventDescription,
          "location": eventCal.location, // Add location
          "start": {
            "dateTime": eventCal.eventDate?.toUtc().toIso8601String(),
            "timeZone": "UTC",
          },
          "end": {
            "dateTime": eventCal.eventDate
                ?.add(Duration(
                    minutes: int.parse(eventCal.eventDuration != ""
                        ? eventCal.eventDuration ?? "30"
                        : '30')))
                .toUtc()
                .toIso8601String(),
            "timeZone": "UTC",
          },
          "recurrence": [
            "RRULE:FREQ=DAILY;INTERVAL=${eventCal.interval};COUNT=${eventCal.occurrences}"
          ], // Recurrence rule: daily with interval and occurrences
        };

        final response = await http.post(
          Uri.parse(url),
          headers: {
            'Authorization': 'Bearer ${auth.accessToken}',
            'Content-Type': 'application/json',
          },
          body: jsonEncode(event),
        );
        if (response.statusCode == 200) {
          debugPrint('Event created successfully');
        } else {
          debugPrint('Error creating event: ${response.statusCode}');
        }
      } catch (e) {
        debugPrint("RethrowError: ${e.toString()}");
        ddLog.e("ERROR:  ${e.toString()}");  <<<< LOGGING HERE
        rethrow;
      }
    }
  }

  static Future<void> addMultipleEvent(Events eventCal) async {
    // Define your custom format using DateFormat

    if (!kIsWeb) {
      Add2Calendar.addEvent2Cal(buildEvent(eventCal));
    } else {
      try {
        if (auth == null) {
          final signInAccountSilently = await _googleSignIn.signInSilently();
          if (signInAccountSilently != null) {
            auth = await signInAccountSilently.authentication;
          } else {
            final signInAccount = await _googleSignIn.signIn();
            auth = await signInAccount?.authentication;
          }
        }

        if (auth == null) return;

        // for (var eventCal in eventsList) {
        const String calendarId =
            "primary"; // Use 'primary' for the default calendar.
        const String url =
            'https://www.googleapis.com/calendar/v3/calendars/$calendarId/events';
        final event = {
          "summary": eventCal.eventName,
          "description": eventCal.eventDescription,
          "location": eventCal.location, // Add location
          "start": {
            "dateTime": eventCal.eventDate?.toUtc().toIso8601String(),
            "timeZone": "UTC",
          },
          "end": {
            "dateTime": eventCal.eventDate
                ?.add(Duration(
                    minutes: int.parse(eventCal.eventDuration != ""
                        ? eventCal.eventDuration ?? "30"
                        : '30')))
                .toUtc()
                .toIso8601String(),
            "timeZone": "UTC",
          }, // Recurrence rule: daily with interval and occurrences
        };

        final response = await http.post(
          Uri.parse(url),
          headers: {
            'Authorization': 'Bearer ${auth?.accessToken}',
            'Content-Type': 'application/json',
          },
          body: jsonEncode(event),
        );
        if (response.statusCode == 200) {
          debugPrint('Event created successfully');
        } else {
          debugPrint('Error creating event: ${response.statusCode}');
        }
        // }
      } catch (e) {
        debugPrint("RethrowError: ${e.toString()}");
        ddLog.e("ERROR: ${e.toString()}"); <<< LOGGING HERE
        rethrow;
      }
    }
  }

  static Event buildEvent(Events event) {
    Frequency freq = Frequency.yearly;

    if (event.frequency != "" && event.frequency != null) {
      if (event.frequency == 'daily') {
        freq = Frequency.daily;
      } else if (event.frequency == 'weekly') {
        freq = Frequency.weekly;
      } else if (event.frequency == 'monthly') {
        freq = Frequency.monthly;
      }
    }

    if (event.eventDuration == "" || event.eventDuration == null) {
      event.eventDuration = "30";
    }

    return Event(
      title: event.eventName!,
      description: event.eventDescription,
      location: event.location,
      startDate: event.eventDate!,
      endDate: event.eventStartTime!
          .add(Duration(minutes: int.parse(event.eventDuration!))),
      allDay: event.allDay,
      // iosParams: const IOSParams(
      //   reminder: Duration(minutes: 40),
      //   url: "http://example.com",
      // ),
      androidParams: const AndroidParams(
        emailInvites: ["[email protected]"],
      ),
      recurrence: Recurrence(
        frequency: freq,
        endDate: event.recurrenceEndDate,
      ),
    );
  }
}

Thanks for any help

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật