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

Adds Request/Response Logging #220

Open
wants to merge 39 commits into
base: master
Choose a base branch
from

Conversation

hayribakici
Copy link
Collaborator

@hayribakici hayribakici commented Jul 6, 2024

This PR fixes #186 and adds logging tools to inspect the interaction with the spotify-API.

In order to do this, a new class SpotifyClient has been added, that wraps the oauth2.Client. This was necessary, since there are no interceptors out there for the oauth2.Client. The http_interceptor would be a much cleaner solution for logging the requests and responses, however it is only compatible with http.Client instances. Since oauth2.Client is its own http.BaseClient implementation, there is no way around to build a custom http.BaseClient that logs the requests and responses, which this new class is doing.

Regarding the logging, most of the code has been used from the interceptor_plus project, which has the MIT licence. I added some modifications regarding readability and code usability.

Example output (simple):

[log] 🚀 🌐 GET Request 🌐 🚀
      🔗 URL: https://api.spotify.com/v1/shows/4rOoJ6Egrf8K2IrywzwOMk
[log] ✅ 🌐 GET Response 🌐 ✅
      🔗 URL: https://api.spotify.com/v1/shows/4rOoJ6Egrf8K2IrywzwOMk
      🔒 Status Code: 200

The logging can be enabled by this new method spotifyBase.enableLogging(bool enable, loggingDetail, logger). Furthermore, the amount of logging verbosity can be configured with the LoggingDetail enum:

  • simple for basic request/response logging (url, statusCode), see above.
  • medium for basic request/response logging (url, statusCode), plus request/response headers
  • full for basic request/response logging (url, statusCode), plus request/response headers and payload

Own Logger: users of this library can use their own logger for e.g. storing the logs into a file. Per default, the DefaultSpotifyLogger is used, which calls the log() function from the dart/developer package. The logs are only visible in the debug console, when debugging a program. However, users can use their own logging method or library, simply by extending the abstract class SpotifyLogger.

@hayribakici hayribakici changed the title Adds Debug Tools Adds Logging Tools Jul 7, 2024
@hayribakici hayribakici changed the title Adds Logging Tools Adds Request/Response Logging Jul 7, 2024
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

Successfully merging this pull request may close these issues.

Add debug tools
1 participant