logging

logging means tracking events when a software runs we add logs to show an event occurred
there are several levels of logging depending on severity include;
| LEVEL | when it is used |
| DEBUG | Provide detailed information when diagnosing |
| INFO | Confirmation that things worked well |
| WARNING | something unexpected happened that might affect you in future like low storage but software runs |
| ERROR | serious problem, causing some specific functionanlity in the program to halt |
| CRITICAL | more serious error, causing the entire program to crash totally |
logging methods are named after levels of severity mentioned above including logging.debug(), logging.info(), logging.warning(), logging.error()
logging is a build-in module in python.
import logging
logging.warning("watch out!")
logging.info("I told you")
logging to file
import logging
logging.basicConfig(filename="my_log", level=logging.DEBUG,
format="%(asctime)s: %(levelname)s: %(message)s")
you can access logging functionality by creating a logger
import logging
logger = getLogger(__name__) # creating a logger to access logging methods
logging.basicConfig(filename="my_log", level=logging.DEBUG,
format="%(asctime)s: %(levelname)s: %(message)s")
logger.debug("this message should appear on console")
logger.info("this message should appear on console")
logger.warning("even this message should appear on console")




