-1

I need to show logging messages while debugging what should I do to show messages with the code like this:

logs.out("Here are the error messages")
logs.clear()
  • 1
    Possible duplicate of [Using Python logging in multiple modules](https://stackoverflow.com/questions/15727420/using-python-logging-in-multiple-modules) – Nathan Jul 08 '19 at 16:59
  • Does this answer your question? [How do I log a Python error with debug information?](https://stackoverflow.com/questions/5191830/how-do-i-log-a-python-error-with-debug-information) – Florian Jun 06 '23 at 09:10

2 Answers2

2

You should be using the logging module. Here is an example:

import logging

logging.debug('debug message')
logging.info('information message')
logging.warning('A warning message')
logging.error('Error Description')
logging.critical('Critical messages should be here')
Florian
  • 2,562
  • 5
  • 25
  • 35
Nitish
  • 565
  • 4
  • 16
  • 1
    Try something like this: logging.basicConfig(filename='file.log', filemode='w', format='%(name)s - %(levelname)s - %(message)s') – Nitish Jul 08 '19 at 17:00
0

If you prefer to just output some common text for logging then you can opt in the print() function of Python or else of you want to log like the proper way that it should be then you can use the logging API provided by the Python itself as a library.

`

import logging
logging.basicConfig(filename='example.log', level=logging.debug)
logging.debug("Debugging")

`

Bikash Das
  • 147
  • 1
  • 12