fromhestia_loggerimportget_logger# Get a logger instancelogger=get_logger("development")# Log messages with different levelslogger.debug("This is a DEBUG log")logger.info("Application started successfully")logger.warning("Low disk space warning")logger.error("Failed to connect to database")logger.critical("System is down!")
Run the Script
poetryrunpythonexample.py
📌 Expected output in logs/app.log:
{"timestamp":"2025-03-14T13:57:41.Z","level":"INFO","service":"development","environment":"local","hostname":"ubuntu","app_version":"1.0.0","message":"Application started successfully"}{"timestamp":"2025-03-14T13:57:41.Z","level":"WARNING","service":"development","environment":"local","hostname":"ubuntu","app_version":"1.0.0","message":"Low disk space warning"}{"timestamp":"2025-03-14T13:57:41.Z","level":"ERROR","service":"development","environment":"local","hostname":"ubuntu","app_version":"1.0.0","message":"Failed to connect to database"}{"timestamp":"2025-03-14T13:57:41.Z","level":"CRITICAL","service":"development","environment":"local","hostname":"ubuntu","app_version":"1.0.0","message":"System is down!"}
📌 Expected output in logs/development.log:
2025-03-14 13:57:41,052 - development - INFO - Application started successfully
2025-03-14 13:57:41,052 - development - WARNING - Low disk space warning
2025-03-14 13:57:41,053 - development - ERROR - Failed to connect to database
2025-03-14 13:57:41,053 - development - CRITICAL - System is down!
HESTIA Logger provides a decorator to automatically log function execution.
fromhestia_loggerimportget_loggerfromhestia_logger.decoratorsimportlog_execution# Initialize the loggerlogger=get_logger("decorator")@log_executiondefadd_numbers(a,b):"""Adds two numbers and returns the result."""returna+b@log_executiondefsimulate_task():"""Simulates a task that takes time."""importtimetime.sleep(2)return"Task completed!"# Call the functionsif__name__=="__main__":result=add_numbers(5,10)logger.info(f"Result: {result}")task_status=simulate_task()logger.info(f"Task Status: {task_status}")
📌 Expected log output:
{"timestamp":"2025-03-14T12:35:00.123Z","level":"INFO","service":"decorator","message":"📌 Started: add_numbers()"}{"timestamp":"2025-03-14T12:35:00.125Z","level":"INFO","service":"decorator","message":"✅ Finished: add_numbers() in 0.0004 sec"}
HESTIA supports custom metadata to extend the default content of the logger instance:
fromhestia_loggerimportget_loggerimporttime# Get logger instancelogger=get_logger("container_test")logger.info("🚀 Starting Hestia Logger inside Docker...")foriinrange(5):logger.debug(f"Iteration {i+1}: Debugging log message")logger.info(f"Iteration {i+1}: Info log message")time.sleep(1)# Simulate worklogger.warning("⚠️ This is a warning log inside Docker.")logger.error("❌ This is an error log inside Docker.")logger.critical("🔥 Critical system failure inside Docker!")logger.info("✅ Hestia Logger test completed inside Docker.")