question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Logger prints multiple times

See original GitHub issue

Hi,

I have a bit of strange issue. When I run my application the logger prints lines multiple times. For instance after while when I close my application:

/dev/tty.usbserial-1420 port closed
/dev/tty.usbserial-1420 port closed
/dev/tty.usbserial-1420 port closed
/dev/tty.usbserial-1420 port closed
/dev/tty.usbserial-1420 port closed
/dev/tty.usbserial-1420 port closed
/dev/tty.usbserial-1420 port closed
/dev/tty.usbserial-1420 port closed
/dev/tty.usbserial-1420 port closed

Even the last message I received was printed 7 times. As my program runs longer this number increases.

I checked, by adding some debug printing in the library, and the printed message is actually logged once but printed multiple times. And my program isn’t leaking any memory or something. So everything does look fine.

I have been searching on it a little bit and the internet is full of the same questions regarding python logger. Like (stackoverflow):

So every time you instantiate your class you add new handlers to the logger and every handler prints a line.

Any idea how to solve this? Do you think this issue be related to having multiple logger handlers?

Thanks, Fokko

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
mlhalescommented, Feb 6, 2019

I just found this issue too. It turns out that it was already fixed in master at dad8aae0d744ae094e36f6f1987b0bf301d753b4 before you even asked your question. It hasn’t been published as a new release though, so you will have to install from source, instead of using pip.

0reactions
tatianaleoncommented, Oct 16, 2020

Fix to this issue at c922ab1051aa6042ebde510f1564504fd14a3012 is already included in release 1.3.0.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python logging module is printing lines multiple times
logger is created once, but multiple handlers are created. Create A once. a = A() for msg in ["hey", "there"]: a.p(msg).
Read more >
How to fix Python logger printing the same entry multiple times
Two solutions · Import the same logger every time · Check if handlers are present.
Read more >
Python Logger Printing Multiple Times - SukhbinderSingh.com
This is my standard boilerplate code for adding any logging functionality in an app. This makes starting and working on projects super easy....
Read more >
How to Get Started with Logging in Python - Better Stack
With the basics of printing log messages in Python out of the way, ... If called multiple times, only the first one will...
Read more >
Python Logging: In-Depth Tutorial - Toptal
The Python logging module comes with the standard library and provides basic logging features. By setting it up correctly, a log message can...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found