import logging
# Configure logging
logging.basicConfig(filename="anjha.log",level=logging.INFO)
# Logging different levels of messages
logging.info("log this line of execution by anjha")
logging.info("Dusra line likhta hu")
logging.debug("this is debugging message")
logging.warning("This is Warning message")
logging.error("This is error message")
logging.critical("This is my critical message")
These are The level
NOTSET | DEBUG | INFO | WARNING | ERROR | CRITICAL
import logging
logging.basicConfig(
filename="anjha1.log",
level=logging.DEBUG,
format='%(asctime)s %(message)s'
)
logging.debug("this is first debuging message")
logging.critical("This is my first critical message")
logging.error("this is my first error")
import logging
logging.basicConfig(
filename="anjha2.log",
level=logging.DEBUG,
format='%(asctime)s %(name)s %(levelname)s %(message)s'
)
logging.debug("this is in second debuging message")
logging.critical("This is my second critical message")
logging.error("this is my second error")
import logging
# Configure logging
logging.basicConfig(
filename="anjha3.log",
level=logging.DEBUG,
format="%(asctime)s - %(levelname)s - %(message)s"
)
l = [1, 2, 3, 4, 5, [7,9,33], "an", "jha"]
l1_int = []
l2_str = []
# Iterate through the list
for i in l:
logging.info("Iterating through the list, current element: %s", str(i))
if isinstance(i, list):
logging.info("Element is a list: %s", str(i))
for j in i:
logging.info("Iterating through nested list, current element: %s", str(j))
if isinstance(j, int):
logging.info("Nested element is an integer: %s", str(j))
l1_int.append(j)
elif isinstance(i, int):
logging.info("Element is an integer: %s", str(i))
l1_int.append(i)
elif isinstance(i, str):
logging.info("Element is a string: %s", str(i))
l2_str.append(i)
logging.info(f"my final result is for integer is {l1_int} and for String is {l2_str} ")