Update logger.py
This commit is contained in:
24
logger.py
24
logger.py
@@ -14,28 +14,34 @@ logging.basicConfig(
|
|||||||
)
|
)
|
||||||
|
|
||||||
def main_task():
|
def main_task():
|
||||||
|
"""
|
||||||
|
Main task execution function. Simulates a workflow and handles errors.
|
||||||
|
"""
|
||||||
try:
|
try:
|
||||||
# Example task
|
|
||||||
logging.info("Starting the main task...")
|
logging.info("Starting the main task...")
|
||||||
|
|
||||||
# Simulated error
|
# Simulated task and error condition
|
||||||
if some_condition(): # Replace with actual logic
|
if some_condition():
|
||||||
raise ValueError("Simulated error occurred.")
|
raise ValueError("Simulated error occurred.")
|
||||||
|
|
||||||
logging.info("Main task completed successfully.")
|
logging.info("Main task completed successfully.")
|
||||||
|
|
||||||
except ValueError as ve:
|
except ValueError as ve:
|
||||||
logging.error(f"ValueError: {ve}")
|
logging.error(f"ValueError occurred: {ve}", exc_info=True)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(f"Unexpected error: {e}")
|
logging.error(f"Unexpected error occurred: {e}", exc_info=True)
|
||||||
finally:
|
finally:
|
||||||
logging.info("Task execution finished.")
|
logging.info("Task execution finished.")
|
||||||
|
|
||||||
def some_condition():
|
def some_condition():
|
||||||
# Simulate an error condition
|
"""
|
||||||
|
Simulates an error condition. Returns True to trigger an error.
|
||||||
|
Replace this logic with actual task conditions.
|
||||||
|
"""
|
||||||
return True
|
return True
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
# Application workflow
|
||||||
logging.info("Application started.")
|
logging.info("Application started.")
|
||||||
main_task()
|
main_task()
|
||||||
logging.info("Application exited.")
|
logging.info("Application exited.")
|
||||||
|
|||||||
Reference in New Issue
Block a user