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

Dio add custom log level #306

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

Conversation

mylukin
Copy link
Contributor

@mylukin mylukin commented Dec 28, 2024

Background

Currently, TalkerDioLogger does not support customizing log levels for different log types (requests, responses, errors). This limits flexibility in distinguishing critical logs (e.g., errors) from less important ones.

Code

  _dio.interceptors.add(
      TalkerDioLogger(
        talker: talker,
        settings: const TalkerDioLoggerSettings(
          enabled: true,
          logLevel: LogLevel.info, // custom log level
          printRequestHeaders: true,
          printResponseHeaders: false,
          printResponseMessage: true,
        ),
      ),
    );

Changes

  1. Custom Log Levels:

    • Added logLevel to DioRequestLog and DioResponseLog, configurable via TalkerDioLoggerSettings.
    • Set DioErrorLog to always use LogLevel.error for better error visibility.
  2. Enhanced TalkerDioLoggerSettings:

    • Introduced a logLevel option, defaulting to LogLevel.debug, allowing global customization for request and response logs.

Reasons for Changes

  • Flexibility: Users can adjust log levels based on the environment (e.g., debug for development, info for production).
  • Improved Error Handling: Highlighting error logs ensures critical issues are easily noticeable.
  • Better Log Management: Aligns with user strategies for controlling log verbosity.

Impact

  • Fully backward-compatible.
  • Enhances configurability without affecting existing usage.

This update improves TalkerDioLogger's usability and adaptability for various logging needs.

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.

1 participant