Loguru: Multiple arguments

Created on 31 Jan 2020  路  5Comments  路  Source: Delgan/loguru

Hi! Can you please tell, it's possible to achieve behavior with loguru.info() like print() function in case of multiple arguments?

For example, with print() i can do: print(1, 'abc', True), but loguru.info() takes only first argument for message.

I can reach desired result if i do:

loguru.info(', '.join([str(a) for a in (1, 'abc', True)]))

But make it every time too exhausting.

question

Most helpful comment

Maybe that Loguru is not the best tool for "rapid debug", and something more appropriate like icecream should be used instead? :confused:

Anyway, I have another suggestion for the {module} / {function} problem: did you try to use opt() to force the context source to be retrieved from the parent function of you wrapper? Something like that:

def debug(*args):
    logger.opt(depth=1).info(" ".join(map(str, args)))

All 5 comments

Hi @filantus. :slightly_smiling_face:

Logging messages with Loguru is more like using format() than print(). Actually, logger.info("{} {} {}", 1, "abc", True) is roughly equivalent to "{} {} {}".format(1, "abc", True).

Brace-formatting is actually more powerful than print(), that's why this is the preferred way to format message using the logger. :wink:

Thank you for answer.
Yes, i now. And since Python 3.6 i also can use f-strings for this purposes. But then i just want rapid debug something, brace-formatting is overburdening me.

I even can replace logger.info() method using from functools import partialmethod with my own wrapper for desired effect, but then appears new problem - {module} and {function} referrers only to wrapper function, not to real invoke place.

So, i understand what loguru.info() not receive multiple message arguments, and probably not will do in future. But maybe there is another way? It's possible to make wrapper and save original {module} and {function} output?

Maybe that Loguru is not the best tool for "rapid debug", and something more appropriate like icecream should be used instead? :confused:

Anyway, I have another suggestion for the {module} / {function} problem: did you try to use opt() to force the context source to be retrieved from the parent function of you wrapper? Something like that:

def debug(*args):
    logger.opt(depth=1).info(" ".join(map(str, args)))

Yeah, it's seems just what i wanted. Thank you very much!

P.S. I understand what loguru not aimed to rapid debugging, and it's not only one purpose for i using loguru. But in some cases i don't want install excess dependencies, just little more comfort with great tool like loguru. :slightly_smiling_face: Thank you again!

P.S. I understand what loguru not aimed to rapid debugging, and it's not only one purpose for i using loguru. But in some cases i don't want install excess dependencies, just little more comfort with great tool like loguru. slightly_smiling_face Thank you again!

Yeah, no problem, I just wanted to mention the existence of more suitable tools. Yet I'm also happy to know that Loguru is modular enough to offer a solution that suits your needs! :smile:

Was this page helpful?
0 / 5 - 0 ratings

Related issues

shmilylty picture shmilylty  路  5Comments

ghost picture ghost  路  4Comments

Gopichand995 picture Gopichand995  路  4Comments

heckad picture heckad  路  4Comments

flybaozi picture flybaozi  路  4Comments