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

Support loggers in verbose mode #138

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

Conversation

jacksonllee
Copy link

Thank you for this wonderful library!

A print statement is used for the various CleverCSV functions where one can set verbose=True, but a logger is sometimes preferred (if not necessary, especially in a production environment) for its flexibility in stream handling and other features unavailable to print statements. This pull request adds a logger keyword argument alongside the existing verbose, so that a logging.Logger instance can be passed in and used. No code changes are made under clevercsv/console/, as the logger doesn't appear to be relevant to the console use cases.

@GjjvdBurg
Copy link
Collaborator

Thanks @jacksonllee for this suggestion and your contribution! I agree that using logging is indeed a better way to go than the verbose flag. However I think we can use the logging module a bit more fully, by configuring logging for a library as described here.

Then, we can do two things:

  • In each file where a logger is used, we can simply instantiate it as a global for that module, like LOGGER = logging.getLogger(__name__)
  • In the console scripts, we can set the logging level of the library based on whether the verbose flag is specified (by configuring a StreamHandler on the library root logger) and setting its log level to info.

By doing this any application that uses CleverCSV would be able to configure the log level they want from it, and as an added benefit we can remove the verbose and logger flags from various functions, which would clean up the codebase.

Let me know what you think of this suggestion and if you're interested in implementing it!

@jacksonllee
Copy link
Author

Hello @GjjvdBurg, I wasn't planning on making breaking changes (e.g., changing or even removing the kwarg verbose), but that sounds like what you'd actually want. For context, I ran into your library for my day job. The logger kwarg that I've added as you see here served my purposes well. I passed in a logger with streaming behaviors set for my company's production environment. The pattern that you've suggested is reasonable. I don't know if I have the bandwidth to help implement it since I've already got a working version for my use case, but perhaps between Christmas and New Years when things are quieter at work? I'll keep you posted.

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.

2 participants