Skip to content

Conversation

@ranelpadon
Copy link

@ranelpadon ranelpadon commented Jun 19, 2023

Thanks for this awesome tool! :)

I usually have these use cases when working with our Python/Django projects:

  • printing to terminal: ic() with context and custom prefix
  • piping to logger: ic() without context and prefix

But currently, these 2 cases could not exist at the same time since configureOutput() is being applied on the same ic object.

Figured out that an effective solution is to have a way to create multiple instances of IceCream wherein each of them could have different configurations and could be added in builtins with different names (e.g. ic() and ik()):

  • printing to terminal: ic() with context and custom prefix
  • piping to logger: ik() without context and prefix

Hence, created this PR. I use the code changes here in our projects for some time already and it's working as intended. Likewise, updated the unit tests and README. Cheers!

@turbotimon
Copy link

turbotimon commented May 2, 2025

I was looking to do a similar think (special ic instance) and was about to do a PR for at least adding the "Multi-Configuration" part to the README. Then I saw your PR which does this already 🙂 This PR is open quite a while, @gruns would you agree this is a great feature and usefull?

Copy link

@turbotimon turbotimon left a comment

Choose a reason for hiding this comment

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

Consider clearer naming


def install(ic='ic'):
setattr(builtins, ic, icecream.ic)
def install(attribute='ic', value=icecream.ic):

Choose a reason for hiding this comment

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

Maybe a better naming here? Like e.g. name and instance?

If you agree, please also change it in the uninstall

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