Loguru: Why does it logs duplicated message?

Created on 1 Feb 2020  路  3Comments  路  Source: Delgan/loguru

Code

import sys

from loguru import logger
logger.add(sys.stdout, colorize=True, format="{message}~~~~")


logger.debug("This is my logger\n awesome!! haha")
>> 2020-02-01 09:11:45.204 | DEBUG    | __main__:<module>:1 - This is my logger
 awesome!! haha
This is my logger
 awesome!! haha~~~~

Problems

  1. It shows the same message twice
  2. I was meant to print just message alone but it always print 2020-02-01 09:11:45.204 | DEBUG | __main__:<module>:1...

Why does it happen?

question

Most helpful comment

@Delgan Yes. Thank you for a solution : )

All 3 comments

Hi @rightx2.

For convenience, a default sink logging to stderr is automatically attached to the imported logger. That's why you are seeing logs twice: messages are sent both to the default handler (stderr) and your customized handler (stdout).

If you want to get ride of it, you can just call logger.remove() at the start of your script (it will disable all previously added handlers). :+1:

@rightx2 Did the provided solution solved your issue?

@Delgan Yes. Thank you for a solution : )

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ghost picture ghost  路  4Comments

HarveySummers picture HarveySummers  路  4Comments

BarryThrill picture BarryThrill  路  6Comments

shmilylty picture shmilylty  路  5Comments

lgvaz picture lgvaz  路  6Comments