loguru icon indicating copy to clipboard operation
loguru copied to clipboard

Same log line output twice?

Open MoonBunnyZZZ opened this issue 3 years ago • 6 comments

I add this line below in my code. logger.add(sys.stdout, colorize=True, format="<green><b>{time:YYYY-MM-DD :mm:ss}</b></green> - {level} - {file} - {line} - {message}")

The same log output twice in terminal like:

2022-03-31 18:19:10.853 | INFO | main:main:33 - Set random seed to 1 2022-03-31 :19:10 - INFO - train.py - 33 - Set random seed to 1

MoonBunnyZZZ avatar Mar 31 '22 10:03 MoonBunnyZZZ

This is probably because of the default handler added automatically which logs messages to sys.stderr. You need to call logger.remove() first.

Delgan avatar Mar 31 '22 12:03 Delgan

@Delgan I think I've seen this question quite a few times, maybe its time to create a FAQ section? Just for reference: #481

urmzd avatar Apr 04 '22 13:04 urmzd

You're right @urmzd, thanks for the suggestion.

I added it to the "Help & Guides" page of the documentation: Avoiding logs to be printed twice on the terminal.

Perhaps the "FAQ" format would be more appropriate, but it should be filled with more questions.

Delgan avatar Apr 04 '22 17:04 Delgan

@Delgan I can take a look and see if there are any more duplicate questions if you'd like. Having a FAQ section readily available will make onboarding simpler for new python users or users migrating from logging (even though the documentation is already comprehensive IMO).

urmzd avatar Apr 04 '22 20:04 urmzd

@urmzd Thank you for your kind offer! I could certainly find a couple of questions that would fit in the FAQ as well. If you have any ideas that could help to grasp Loguru, please don't hesitate. I just wonder if it isn't too much repetition / overload between the already existing "Readme", "Migration" and "Help & Guides" sections (although I agree a FAQ has its own advantages).

Delgan avatar Apr 04 '22 21:04 Delgan

@Delgan From the sounds of it, a discussion surrounding documentation architecture might be good. A good start might just include adding a table of contents to the README. What do you think?

urmzd avatar Apr 08 '22 19:04 urmzd

@Delgan From the sounds of it, a discussion surrounding documentation architecture might be good. A good start might just include adding a table of contents to the README. What do you think?

Sorry, I forgot to answer you. To be honest, I prefer not to overload the current README. I quite like its relative simplicity with examples and links to the documentation for details.

I'm closing this ticket as I answered the initial question, but a new one can be opened about possible documentation improvements.

Delgan avatar Oct 07 '22 16:10 Delgan