Skip to content

feat: Talker http logger v1.0.0#362

Merged
Frezyx merged 38 commits intoFrezyx:masterfrom
techouse:feat/http-logger-v1.0.0
Jun 13, 2025
Merged

feat: Talker http logger v1.0.0#362
Frezyx merged 38 commits intoFrezyx:masterfrom
techouse:feat/http-logger-v1.0.0

Conversation

@techouse
Copy link
Contributor

@techouse techouse commented May 4, 2025

This pull request introduces a significant overhaul of the talker_http_logger package, including updates to its functionality, documentation, and example project. The most important changes involve the migration to the http_interceptor package, enhancements to the package's logging capabilities, and the addition of a comprehensive example project.

Package Overhaul and Feature Enhancements:

  • Migrated the package from using http to http_interceptor for HTTP client logging, with updated usage instructions and examples in the README.md. New features include customizable log colors, request/response filtering, and the ability to hide sensitive headers. [1] [2] [3]
  • Updated CHANGELOG.md to reflect the complete overhaul of the package, marking version 1.0.0.

Developer Tooling and Workflow:

  • Added a Makefile with various commands for code analysis, formatting, testing, and dependency management to streamline development workflows.
  • Introduced a GitHub Actions workflow (talker_http_logger.yaml) for automated testing of the package on push and pull request events.

Example Project:

  • Added a fully functional example project demonstrating the usage of the talker_http_logger package, including setup instructions, customizations, and directory structure documentation.
  • Configured the example project for Flutter, including platform-specific files for Android, such as build.gradle.kts, AndroidManifest.xml, and other supporting resources. [1] [2] [3] [4] [5]

Documentation and Configuration:

  • Updated the README.md with detailed usage instructions, including advanced features like printing cURL commands, hiding sensitive headers, and customizing log colors. [1] [2]
  • Added analysis options (analysis_options.yaml) for the example project to enforce linting rules and exclude generated files.

These changes collectively modernize the talker_http_logger package, improve its usability, and provide developers with robust tools and examples to integrate it into their projects.


Summary by Sourcery

Complete overhaul of the talker_http_logger package, introducing comprehensive HTTP logging capabilities with extensive customization options

New Features:

  • Added extensive configuration options for HTTP logging
  • Implemented curl command generation for requests
  • Added support for filtering requests and responses
  • Introduced custom console log coloring
  • Added response time logging

Enhancements:

  • Improved logging granularity
  • Added more detailed error and response logging
  • Enhanced request and response log formatting
  • Implemented more robust error handling

Documentation:

  • Updated README with comprehensive usage examples
  • Added example project demonstrating package features

Tests:

  • Added comprehensive unit tests for HTTP request, response, and error logging
  • Implemented 100% test coverage
  • Added tests for various logging scenarios and configurations

Chores:

  • Updated package dependencies
  • Migrated to latest Dart SDK version
  • Restructured package architecture

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented May 4, 2025

Reviewer's Guide

This pull request refactors the talker_http_logger by introducing dedicated log classes (HttpRequestLog, HttpResponseLog, HttpErrorLog) managed by a new TalkerHttpLogger interceptor, controlled through an expanded TalkerHttpLoggerSettings class for granular configuration of log content, formatting, and filtering. Curl command generation is added via a BaseRequest extension, and response time is calculated using timestamps injected by the interceptor.

Sequence Diagram for HTTP Request Interception and Logging

sequenceDiagram
  participant Client
  participant TalkerHttpLogger
  participant Talker
  participant HttpRequestLog
  participant HttpResponseLog
  participant HttpErrorLog

  Client->>TalkerHttpLogger: makeRequest(request)
  activate TalkerHttpLogger
  TalkerHttpLogger->>TalkerHttpLogger: Check settings (enabled, filters)
  alt Request Logging Enabled
    TalkerHttpLogger->>TalkerHttpLogger: Add timestamp header (if needed)
    TalkerHttpLogger->>HttpRequestLog: new HttpRequestLog(request, settings)
    activate HttpRequestLog
    HttpRequestLog-->>TalkerHttpLogger: requestLog
    deactivate HttpRequestLog
    TalkerHttpLogger->>Talker: logCustom(requestLog)
  end
  TalkerHttpLogger-->>Client: modifiedRequest
  deactivate TalkerHttpLogger

  Note right of Client: Request sent to network...

  Client->>TalkerHttpLogger: receiveResponse(response)
  activate TalkerHttpLogger
  TalkerHttpLogger->>TalkerHttpLogger: Check settings (enabled, filters)
  alt Response is Success (status < 400)
    TalkerHttpLogger->>HttpResponseLog: new HttpResponseLog(response, settings)
    activate HttpResponseLog
    HttpResponseLog-->>TalkerHttpLogger: responseLog
    deactivate HttpResponseLog
    TalkerHttpLogger->>Talker: logCustom(responseLog)
  else Response is Error (status >= 400)
    TalkerHttpLogger->>HttpErrorLog: new HttpErrorLog(response, settings)
    activate HttpErrorLog
    HttpErrorLog-->>TalkerHttpLogger: errorLog
    deactivate HttpErrorLog
    TalkerHttpLogger->>Talker: logCustom(errorLog)
  end
  TalkerHttpLogger-->>Client: response
  deactivate TalkerHttpLogger
Loading

File-Level Changes

Change Details Files
Refactored core logic and added extensive configuration options.
  • Replaced previous implementation with a new TalkerHttpLogger interceptor.
  • Introduced dedicated log classes (HttpRequestLog, HttpResponseLog, HttpErrorLog) for formatting.
  • Expanded TalkerHttpLoggerSettings for fine-grained control (output details, custom colors, filtering).
  • Updated README with new features and usage.
  • Bumped package version to 1.0.0 and updated dependencies.
packages/talker_http_logger/lib/talker_http_logger_settings.dart
packages/talker_http_logger/lib/talker_http_logger.dart
packages/talker_http_logger/lib/talker_http_logger_interceptor.dart
packages/talker_http_logger/lib/http_request_log.dart
packages/talker_http_logger/lib/http_error_log.dart
packages/talker_http_logger/lib/http_response_log.dart
packages/talker_http_logger/README.md
packages/talker_http_logger/pubspec.yaml
packages/talker_http_logger/CHANGELOG.md
Added curl command generation for requests.
  • Created toCurl extension method on BaseRequest.
  • Integrated curl logging into HttpRequestLog based on settings.
packages/talker_http_logger/lib/curl_request.dart
packages/talker_http_logger/lib/http_request_log.dart
packages/talker_http_logger/test/logs_test.dart
packages/talker_http_logger/README.md
Added response time logging.
  • Added timestamp injection to request headers in the interceptor.
  • Created ResponseTime mixin to calculate duration.
  • Integrated response time logging into HttpResponseLog and HttpErrorLog.
packages/talker_http_logger/lib/talker_http_logger_interceptor.dart
packages/talker_http_logger/lib/response_time.dart
packages/talker_http_logger/lib/http_response_log.dart
packages/talker_http_logger/lib/http_error_log.dart
packages/talker_http_logger/test/logger_test.dart
packages/talker_http_logger/test/logs_test.dart
Added comprehensive unit tests.
  • Created tests for log message generation (logs_test.dart).
  • Created tests for interceptor logic (logger_test.dart).
  • Created tests for settings functionality (settings_test.dart).
packages/talker_http_logger/test/logs_test.dart
packages/talker_http_logger/test/logger_test.dart
packages/talker_http_logger/test/settings_test.dart
packages/talker_http_logger/test/helpers/multipart_request_extension.dart
Added example project and development tooling.
  • Created a new Flutter example project.
  • Added Android, iOS, and Web configuration files for the example.
  • Added a Makefile for common development tasks.
  • Added a GitHub Actions workflow for automated testing.
packages/talker_http_logger/example/
packages/talker_http_logger/Makefile
.github/workflows/talker_http_logger.yaml
packages/talker_http_logger/tool/makefile_helpers.sh

Possibly linked issues

  • #0: PR adds 100% test coverage to talker_http_logger package, directly addressing the issue's goal.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@codecov-commenter
Copy link

codecov-commenter commented May 5, 2025

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (5e6705e) to head (3ffb8f8).
Report is 27 commits behind head on master.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@             Coverage Diff             @@
##           master      #362      +/-   ##
===========================================
+ Coverage   98.61%   100.00%   +1.38%     
===========================================
  Files           3         7       +4     
  Lines         144       212      +68     
===========================================
+ Hits          142       212      +70     
+ Misses          2         0       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@techouse techouse marked this pull request as ready for review May 5, 2025 09:28
@techouse
Copy link
Contributor Author

techouse commented May 5, 2025

@sourcery-ai review

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @techouse - I've reviewed your changes - here's some feedback:

  • Review the necessity of the newly added dependencies (equatable, meta, http_parser, qs_dart).
  • Ensure the new file structure with specialized classes remains easy to navigate and maintain.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @techouse - I've reviewed your changes - here's some feedback:

  • Consider moving internal implementation files (like curl_request.dart, http_error_log.dart, response_time.dart, etc.) into a lib/src directory to keep the public API surface cleaner.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@techouse
Copy link
Contributor Author

techouse commented May 5, 2025

@Frezyx this addresses #325 and is now dev complete with 100% coverage 😊

I have added quite a few more features, like request/response filtering etc.

Throw an eye on it once you can.

There are a few caveats with the http_interceptor package though, namely no error interception (like Dio or Chopper), although I have submitted a PR addressing this CodingAleCR/http_interceptor#159

@techouse
Copy link
Contributor Author

techouse commented May 5, 2025

@sourcery-ai review

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @techouse - I've reviewed your changes and found some issues that need to be addressed.

Blocking issues:

  • Replace DateTime.timestamp() with DateTime.now() to get the current time. (link)

  • Use DateTime.now() instead of DateTime.timestamp() for current time retrieval. (link)

  • Consider grouping related flags within TalkerHttpLoggerSettings (e.g., print options) to potentially simplify the configuration API.

  • Adding the x-talker-http-logger-ts header modifies outgoing requests; confirm this behavior is intended and acceptable.

Here's what I looked at during the review
  • 🔴 General issues: 2 blocking issues, 3 other issues
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

techouse and others added 4 commits May 5, 2025 13:42
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
# Conflicts:
#	packages/talker_http_logger/CHANGELOG.md
#	packages/talker_http_logger/README.md
#	packages/talker_http_logger/pubspec.yaml
….0.0

# Conflicts:
#	packages/talker_http_logger/CHANGELOG.md
#	packages/talker_http_logger/README.md
#	packages/talker_http_logger/pubspec.yaml
# Conflicts:
#	packages/talker_http_logger/CHANGELOG.md
#	packages/talker_http_logger/README.md
#	packages/talker_http_logger/pubspec.yaml
@Frezyx Frezyx added talker_http_logger Related to talker_http_logger package awaiting On the list for consideration or merge labels May 21, 2025
@techouse
Copy link
Contributor Author

@Frezyx I suggest you squash-merge this commit so that it doesn't flood the master commit log.

techouse and others added 4 commits May 25, 2025 09:41
# Conflicts:
#	packages/talker_http_logger/CHANGELOG.md
#	packages/talker_http_logger/README.md
#	packages/talker_http_logger/pubspec.yaml
# Conflicts:
#	packages/talker_http_logger/CHANGELOG.md
#	packages/talker_http_logger/README.md
#	packages/talker_http_logger/pubspec.yaml
# Conflicts:
#	packages/talker_http_logger/CHANGELOG.md
#	packages/talker_http_logger/pubspec.yaml
@Frezyx Frezyx merged commit 453b6b1 into Frezyx:master Jun 13, 2025
1 check passed
@techouse techouse deleted the feat/http-logger-v1.0.0 branch June 13, 2025 18:59
@Frezyx Frezyx linked an issue Jun 22, 2025 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting On the list for consideration or merge talker_http_logger Related to talker_http_logger package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Http logger test coverage

3 participants