Logging
Abstra Logger
The Abstra Logger is a builtin python logger. It provides various methods to log messages at different severity levels such as debug
, info
, warning
, error
, and critical
.
from abstra.logging import logger
def divide(a, b):
try:
logger.debug(f"Attempting to divide {a} by {b}")
result = a / b
logger.info(f"Division successful: {result}")
return result
except ZeroDivisionError as e:
logger.error("Division by zero error")
logger.exception(e)
except Exception as e:
logger.critical("An unexpected error occurred")
logger.exception(e)
# Example calls
divide(10, 2)
divide(10, 0)
Configuring
It is possible to configure both the loglevel and logformat for your application using the following environment variables (and their default values):
ABSTRA_LOGLEVEL=WARNING
ABSTRA_LOGFORMAT=[%(asctime)s][%(levelname)s][%(name)s] %(message)s
See this to learn more about log levels and this to learn about logformats