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.

Use with logging module

See original GitHub issue

In my module, I use the python logging module to print out messages.

During the operation which I want to monitor using alive-progress it may happen that messages are sent out using the logging module. Then, artifacts of the bar remain in the console:

Loading the fmu took 0.34800148010253906 s.

Starting simulation at t=0.0 s.          | ▁▃▅ 0/1000 [0%] in 0s (0.0/s, eta: ?)
Simulation took 0.7570006847381592 s.β–ˆβ–ˆβ–ˆβ–Œ| β–…β–‡β–‡ 990/1000 [99%] in 0s (1126.2/s, eta: 0s)
Simulation finished at t=1000.0 s.
|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 1000/1000 [100%] in 0.9s (1096.43/s)

The first message (β€œloading … took …”) was logged before i instantiated the alive bar. The other messages were emitted while the bar was active. I am using a vanilla StreamHandler that sends everything to stdout.

By the way - dunno if that’s possible - is it possible to have the alive bar redirected to a logging module, too? Might be interesting to have the complete (or not, in case of an error!) progress bar in a log file. Gives structure…

By the way 2: it’s pretty awesome πŸ˜ƒ

Cheers, Jan

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:27 (21 by maintainers)

github_iconTop GitHub Comments

2reactions
rsalmeicommented, Jun 10, 2020

Hey, I’m glad to report I’ve finally mastered this! πŸŽ‰ The proper logging support will be included in the next major version!

on 0: WARNING:__main__:hey 0
on 80: WARNING:__main__:hey 80
|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 100/100 [100%] in 1.2s (85.97/s)

Now it is all automatically setup! The code to generate the above output is only:

from alive_progress import alive_bar
import time, logging

logging.basicConfig()
logger = logging.getLogger(__name__)

with alive_bar(100) as bar:
    for i in range(100):
        time.sleep(.01)
        if i % 80 == 0:
            logger.warning('hey %s', i)
        bar()
0reactions
TheTechRobocommented, Nov 26, 2021

Wasn’t that the bug found with Windoze?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Logging HOWTO β€” Python 3.11.1 documentation
Logging is performed by calling methods on instances of the Logger class (hereafter called loggers). Each instance has a name, and they are...
Read more >
python - Using logging in multiple modules - Stack Overflow
Best practice is, in each module, to have a logger defined like this: import logging logger = logging.getLogger(__name__).
Read more >
Python Logging Basics - The Ultimate Guide To Logging
Python comes with a logging module in the standard library that can provide a flexible framework for emitting log messages from Python programs....
Read more >
Logging in Python - GeeksforGeeks
The Basics Β· Create and configure the logger. It can have several parameters. Β· Here the format of the logger can also be...
Read more >
Python Logging - Simplest Guide with Full Code and Examples
Create a new project directory and a new python file named ' example.py '. Import the logging module and configure the root logger...
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