Skip to content

Commit

Permalink
allows lib users to add own logger
Browse files Browse the repository at this point in the history
  • Loading branch information
hayribakici committed Jul 7, 2024
1 parent f77ef70 commit 72cdf20
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion example/example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ void main() async {

var credentials = SpotifyApiCredentials(keyMap['id'], keyMap['secret']);
var spotify = SpotifyApi(credentials);
spotify.enableDebugMode(true, LoggingDetail.simple);
spotify.enableLogging(true, loggingDetail: LoggingDetail.simple);
// spotify.loggingDetail = LoggingDetail.simple;

print('\nExpannd shortened spotify link of https://spotify.link/hRkBrwub9xb');
Expand Down
11 changes: 6 additions & 5 deletions lib/src/spotify_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,12 @@ abstract class SpotifyApiBase {
}

/// [enable]s logging of the requests and responses on the debug console.
/// Use [loggingDetail] to control how much should be logged. Default's set
/// to [LoggingDetail.simple].
void enableDebugMode(bool enable,
[LoggingDetail loggingDetail = LoggingDetail.simple]) {
_spotifyClient.enableLogging = enable;
/// [loggingDetail] controls the logging verbosity. Default's set
/// to [LoggingDetail.simple].
/// Use own [logger] is also possible for e.g. saving logs into a file etc.
void enableLogging(bool enable,
{LoggingDetail loggingDetail = LoggingDetail.simple, Logger? logger}) {
_spotifyClient.enableLogging(enable, logger: logger);
_spotifyClient.logginDetail = loggingDetail;
}

Expand Down
8 changes: 5 additions & 3 deletions lib/src/spotify_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ part of '../spotify.dart';
class SpotifyClient with http.BaseClient {
final FutureOr<oauth2.Client> _inner;

final Logger _logger = Logger();
late Logger _logger;

bool _enableLogging = false;
get enableLogging => _enableLogging;
set enableLogging(value) => _enableLogging = value;
void enableLogging(bool enable, {Logger? logger}){
_enableLogging = enable;
_logger = logger ?? Logger();
}

LoggingDetail _detail = LoggingDetail.full;
get loggingDetail => _detail;
Expand Down

0 comments on commit 72cdf20

Please sign in to comment.