Skip to content

Instantly share code, notes, and snippets.

@Flushot
Created July 30, 2025 23:53
Show Gist options
  • Save Flushot/2eb47b4f93ea52be1d289abe897fbc88 to your computer and use it in GitHub Desktop.
Save Flushot/2eb47b4f93ea52be1d289abe897fbc88 to your computer and use it in GitHub Desktop.
Python logger: In-place updating progress bar
import time
import logging
from tqdm import tqdm
LOG = logging.getLogger(__name__)
log_interval = 5
cursor_up = r'\033[A' # CSI -> A (Cursor up) https://en.wikipedia.org/wiki/ANSI_escape_code
if __name__ == '__main__':
logging.basicConfig()
LOG.info('First line')
with tqdm(
range(1, 100),
desc='Test progress bar',
bar_format='{l_bar}{bar:15}{r_bar}{bar:-10b}',
file=open(os.devnull, 'w')
) as pbar:
for i, val in enumerate(pbar):
if i == 0:
LOG.info(str(pbar))
elif i % log_interval == 0:
LOG.info(f'{cursor_up}{str(pbar)}')
time.sleep(0.08)
LOG.info(f'{cursor_up}{str(pbar)}')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment