the best simple method to add logging for your python script
import logger
good = logger.Good(FILENAME="good.log", FILEMODE="a", TIME=True, DEBUG_MODE=True)
bad = logger.Bad(FILENAME="bad.log", FILEMODE="a", TIME=True, DEBUG_MODE=True)
try:
num = int(input("Enter a number: "))
print(99/num)
print("SUCCESS")
good.SUCCESS("Divided number by Zero")
except ZeroDivisionError:
print("ERROR")
bad.ERROR("Cannot divide number by Zero")
except Exception as e:
print("ERROR:", e)
bad.ERROR(e)
try:
import nomodulewiththisname
good.IMPORTED("nomodulewiththisname - success")
except ModuleNotFoundError:
print("ERROR")
bad.CRITICAL("No module named 'nomodulewiththisname'")
try:
print(math.sqrt(-1))
except Exception as e:
print("ERROR:", e)
bad.CRITICAL(e)
has
- SUCCESS
- COMPLETED
- DONE
- PASS
- LOADED
- IMPORTED
has
- CRITICAL
- ERROR
- WARNING
- INFO