Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8399091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:12:25+00:00 2026-06-09T21:12:25+00:00

I have a program using the logging module and the print statement. The logging

  • 0

I have a program using the logging module and the print statement. The logging is to inform the user what the program is doing, for example

logging.info("downloading HTML")
time.sleep(1)
logging.info("parsing HTML")
time.sleep(1)
print "the result"

at the end the output on the screen (mixing stdout and stderr) will be:

INFO:downloading HTML
INFO:parsing HTML
the result

I want to hide the last logging output when the next logging output is displayed or when the print is called. For example, start the program, you will see:

INFO:download HTML

wait one seconds, the next info "parsing HTML" will replace the previous "downloading HTML", so on the screen you will see only:

INFO:parsing HTML

and nothing else before, then wait one second, I want to see on the screen only:

"the result"

I want this feauture only when logging on the stderr, and not when logging to a file for example, there I want to see all the logging outputs.

Is it possible?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T21:12:27+00:00Added an answer on June 9, 2026 at 9:12 pm

    On unix-like terminals, you can try prepending ANSI escape sequences to the text;

    import time
    import sys
    
    print 'this is a text',
    sys.stdout.flush()
    
    time.sleep(1)
    print '\x1b[80D'+'\x1b[K'+'Second text',
    sys.stdout.flush()
    

    The character ‘\x1b’ is the escape character. The first sequence moves the cursor up to 80 positions to the left. The second clears the line.

    You need the comma at the end of the print statement to prevent it from going to the second line. Then you need to flush the stdout stream otherwise the text won’t appear.

    Edit: For combinging this with logging, wrap it in a simple function:

    def mylog(text):
        logging.info(text)
        print '\x1b[80D' + '\x1b[K'+ text,
        sys.stdout.flush()
    

    EDIT 2: Integrating this into the standard logging;

    import logging
    # create console handler
    ch = logging.StreamHandler()
    # create formatter
    formatter = logging.Formatter('\x1b[80D\x1b[1A\x1b[K%(message)s')
    # add formatter to console handler
    ch.setFormatter(formatter)
    # add console handler to logger
    logger.addHandler(ch)
    

    Since the logging module seems to add newlines by itself, I’ve added an ANSI sequense (\x1b[1A) to go up one line.

    Also see the logging howto for more information.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have discovered some issues in my program. I was using log4j for logging,
I have a program which write logging as Text File. namespace logging { using
I have a java program which is using the default XML logging as no
I'm using a logging module that can have reporting enabled/disabled at runtime. Calls generally
I have a program using odac(11.2) and oracle client 11.2. Now I want to
I have a c# program using WPF. I have it that when you press
I have a program in C using Solaris with VERY ancient compatibility it seems.
I have the following MonoTouch program: using System.Drawing; using MonoTouch.Foundation; using MonoTouch.UIKit; using System;
I have been asked to write a program using python for an assignment. I
i have made a small opengl program using the d programming language. what i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.