Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support external logger #243

Open
darkstarx opened this issue Jul 8, 2024 · 0 comments
Open

Support external logger #243

darkstarx opened this issue Jul 8, 2024 · 0 comments

Comments

@darkstarx
Copy link

Hi!
Thanks for the great package!

Can you please support an external logger as an optional alternative to the internal print? Something like:

import 'dart:developer';

SmtpClient.logger = log;

where log is

void log(String message, {
  DateTime? time,
  int? sequenceNumber,
  int level = 0,
  String name = '',
  Zone? zone,
  Object? error,
  StackTrace? stackTrace,
});
``` from the `dart:developer`.

and in your `ClientBase.log` method smth like:
```dart
typedef Logger = void Function(String message, {String name});

/// An optional external logger.
Logger? logger;

void log(final Object? logObject, {
  final bool isClient = true,
  String? initial,
})
{
  if (isLogEnabled) {
    initial ??= (isClient == true) ? initialClient : initialServer;
    if (logger != null) {
      logger(logObject?.toString() ?? '',
        name: initial,
      );
    } else if (logName != null) {
      logger()
      print('$logName $initial: $logObject');
    } else {
      print('$initial: $logObject');
    }
  }
}

So it will be compatible with dart:developer and package:logging at the choice of the package user.
As an alternative, you could use package:logging inside of your package and provide an access to the log level of this logger to set the log level externally (like in the hotreloader package).

Thanks again for your package, guys!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant