1

Anybody help me to add memory handlers, bufferinghandler to make my program optimal (to flush buffered memory).

import logging
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)#we can set deug_level at logger level also

formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')

ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
ch.setFormatter(formatter)
logger.addHandler(ch)

logger.debug('This is a test log message.')
1
  • Could you describe your problem? In what way is it not efficient? Commented Oct 21, 2012 at 14:46

1 Answer 1

5

Create your memory handler just like you create a stream handler, passing in the stream handler as the target:

streamhandler = logging.StreamHandler()
streamhandler.setFormatter(formatter)
memoryhandler = logging.handlers.MemoryHandler(1024*10, logging.DEBUG, streamhandler)
logger.addHandler(memoryhandler)

You do not add the stream handler with logger.addHandler.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.