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

fix: logging behavior based on verbose and save_logs settings #1169

Closed
wants to merge 2 commits into from

Conversation

gventuri
Copy link
Collaborator

@gventuri gventuri commented May 20, 2024

Related to #1167

Updates the Logger class in pandasai/helpers/logger.py to respect the verbose and save_logs settings more accurately.

  • Modifies the __init__ method to conditionally add logging.StreamHandler(sys.stdout) only if verbose is True, ensuring that logs are not printed to the console when verbose is False.
  • Adjusts the log method to check the _verbose attribute before logging messages to the console, allowing for more granular control over what gets logged based on the verbosity level.
  • Updates the save_logs setter and getter methods to accurately reflect whether logs are being saved to a file, addressing the issue where logs were saved regardless of the save_logs setting.
  • Fixes the variable name typo from filaname to filename in both the __init__ method and the save_logs setter, improving code readability and consistency.

For more details, open the Copilot Workspace session.

@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. labels May 20, 2024
Copy link

codecov bot commented May 20, 2024

Codecov Report

Attention: Patch coverage is 44.44444% with 15 lines in your changes are missing coverage. Please review.

Project coverage is 78.48%. Comparing base (2502d04) to head (a4f64e7).

Files Patch % Lines
pandasai/helpers/logger.py 44.44% 15 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1169      +/-   ##
==========================================
- Coverage   78.56%   78.48%   -0.09%     
==========================================
  Files         117      117              
  Lines        4624     4630       +6     
==========================================
+ Hits         3633     3634       +1     
- Misses        991      996       +5     

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

Refactors logging behavior in `Logger` class to correctly handle `verbose` and `save_logs` settings.

- Fixes a typo from `filaname` to `filename` for more accurate file handling.
- Modifies log appending logic to only append logs if `verbose` is True or the log level is above INFO, addressing the issue where verbose mode did not print anything.
- Adjusts the `verbose` property setter to clear all handlers before adding a new StreamHandler, ensuring that toggling the verbose flag works as expected.
- Enhances the `save_logs` property setter and getter to correctly identify and manage FileHandler instances, preventing logs from being added to `pandasai.log` when `save_logs` is False.


---

For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/Sinaptik-AI/pandas-ai/pull/1169?shareId=10752ac7-bde3-4a89-ae5d-1104a4834b03).
@gventuri
Copy link
Collaborator Author

Refactors logging behavior in Logger class to correctly handle verbose and save_logs settings.

  • Fixes a typo from filaname to filename for more accurate file handling.
  • Modifies log appending logic to only append logs if verbose is True or the log level is above INFO, addressing the issue where verbose mode did not print anything.
  • Adjusts the verbose property setter to clear all handlers before adding a new StreamHandler, ensuring that toggling the verbose flag works as expected.
  • Enhances the save_logs property setter and getter to correctly identify and manage FileHandler instances, preventing logs from being added to pandasai.log when save_logs is False.

For more details, open the Copilot Workspace session.

@gventuri gventuri closed this May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size:M This PR changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant