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
uvrunpythonexample.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.")
# Use official Python + uv imageFROMghcr.io/astral-sh/uv:python3.10-alpine
# Set working directoryWORKDIR/app
# Copy project filesCOPY..
# Install dependencies defined in pyproject.toml (no dev deps)RUNuvsync--no-dev
# Make sure the project virtualenv is on PATH (optional but handy)ENVPATH="/app/.venv/bin:$PATH"# Set environment variablesENVENVIRONMENT="container"ENVLOGS_DIR="/var/logs"ENVLOG_LEVEL="INFO"ENVENABLE_INTERNAL_LOGGER="true"# Create logs directory with proper permissionsRUNmkdir-p/var/logs&&chmod-R777/var/logs
# Define entrypoint (runs with the uv-managed environment)CMD["uv","run","python","app.py"]
Step 3. Build and run the Docker Container
Build the container:
dockerbuild-thestia-test.
Run the container:
dockerrun--rm-v$(pwd)/logs:/var/logshestia-test
The -v $(pwd)/logs:/var/logs mounts the logs folder from the container to your local machine.
This ensures logs persist outside the container.