I hope to overwrite the previous logging every time I run the application. I figure it out for FileHandler by specifying file mode being 'w'. Where can I specify similar behaviour for StreamHandler? Consider the following code, if running multiple times, 'test.log' will always show a single line of 'test' while the console will show multiple lines of 'test'.
I tried the flush method but it doesn't work.
import logging
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
file_handler = logging.FileHandler('test.log', mode = 'w')
logger.addHandler(file_handler)
streamHandler = logging.StreamHandler()
logger.addHandler(streamHandler)
logger.info('test')
I hope the console will show a single line of 'test' even if running multiple times.