3

I am using python logging module.

When I output the any message it has the default output string as prefix.

For example

    logging.info("any message")

gives output with prefix "INFO:"

    INFO:any message

I want to print simple messages without any prefix.

How one could do that?

2 Answers 2

4

Read the API.

FORMAT = '%(asctime)-15s %(clientip)s %(user)-8s %(message)s'
logging.basicConfig(format=FORMAT)
d = {'clientip': '192.168.0.1', 'user': 'fbloggs'}
logger = logging.getLogger('tcpserver')
logger.warning('Protocol problem: %s', 'connection reset', extra=d)

Gives

2006-02-08 22:20:02,165 192.168.0.1 fbloggs  Protocol problem: connection reset

You will have to customise the FORMAT of the logger, similar to shown above.

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

Comments

2

To output the message only, use the following format string:

logging.basicConfig(format='%(message)s')

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.