Skip to content

Support external logger #243

@darkstarx

Description

@darkstarx

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions