loguru icon indicating copy to clipboard operation
loguru copied to clipboard

Is there a way to incorporate Icecream as a default output function?

Open SuperPauly opened this issue 8 months ago • 2 comments

I've seen this issue #541 but since it's quite old was wondering if there is a newer way to use Icecream pretty output?

My logger.debug() mode dumps quite a lot of dictionarys, lists, json strings and objects and it would be much much nice to read it in a structured way.

Thanks.

SuperPauly avatar Apr 14 '25 18:04 SuperPauly

my intuition is with the availability of ic.format() it will be quite straightforward to wrap the 2?

or is there sophisticated usage of either tool required in your usecase that necessitates a low-level merge?

jkpjkpjkp avatar May 26 '25 05:05 jkpjkpjkp

Hi.

I don't know if this exactly meets your needs, but note that I plan to extend the logging functions so that keyword arguments are automatically logged.

logger.debug("Message", foo=123)
# Planned output: 2025-07-27 18:03:17.115 +02:00 | DEBUG    | __main__:<module>:4 - Message (foo=123)

However, this has not yet been implemented, and it'll be less advanced formatting that the one provided by icecream.

As suggested by @jkpjkpjkp, I think the simplest solution is just to use ic.format() like so:

from icecream import ic
from loguru import logger

def foo(i):
    return i + 333

logger.debug("Message: {}", ic.format(foo(123)))

The icecream library is doing some introspection magic to produce foo(123): 456 output and I don't think it can be integrated otherwise with Loguru.

Delgan avatar Jul 27 '25 16:07 Delgan