gruns / icecream

🍦 Never use print() to debug again.
MIT License
9.21k stars 187 forks source link

Need of ic.debug(**kwargs), ic.info(**kwargs) like methods to lib to increase production usage #188

Open UlucFVardar opened 2 months ago

UlucFVardar commented 2 months ago

ic is a great library, but I think it has one shortcoming.

When using it in a big project, it becomes critical to perform the print operation according to the logging level.

In my current codes, there is always a code add-on like the one below.

if os.environ.get('LOGGING_LEVEL', 'INFO') == 'DEBUG':
    ic(MY_VALUE)

This is a big need to be added to the library!

from icecream import ic
ic.debug()
ic.info()
ic.warning()
ic()

OR

from icecream import ic_error
from icecream import ic_warning
from icecream import ic_debug
from icecream import ic_info
from icecream import ic
ic_debug()
ic_info()
ic_warning()
ic()

Using it like this will be very useful in projects.

Also, if the colors printed according to the logging level are changed, we will have a much more understandable print style.

salabim commented 2 months ago

You can do all this with an alternative package, called ycecream (www.github.com/salabim/ycecream).

Xaelias commented 1 month ago

You can define multiple instances of ic with their own output method to address this.

Smth like:

from icecream import IceCreamDebugger

import logging

logging.basicConfig(level=logging.DEBUG)

logger = logging.getLogger(__name__)

def error(input: str):
    logger.error(input)

def debug(input: str):
    logger.debug(input)

icd = IceCreamDebugger(outputFunction=debug)
ice = IceCreamDebugger(outputFunction=error)