Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions examples/src/logger_example/logger_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@

from aws_durable_execution_sdk_python.context import (
DurableContext,
StepContext,
durable_with_child_context,
durable_step,
)
from aws_durable_execution_sdk_python.execution import durable_execution

import logging

logging.getLogger().setLevel(logging.INFO)


@durable_with_child_context
def child_workflow(ctx: DurableContext) -> str:
Expand All @@ -26,6 +32,16 @@ def child_workflow(ctx: DurableContext) -> str:
return child_result


@durable_step
def my_step(step_context: StepContext, my_arg: int) -> str:
step_context.logger.info("Hello from my_step")
step_context.logger.warning("Warning from my_step", extra={"my_arg": my_arg})
step_context.logger.error(
"Error from my_step", extra={"my_arg": my_arg, "type": "error"}
)
return f"from my_step: {my_arg}"


@durable_execution
def handler(event: Any, context: DurableContext) -> str:
"""Handler demonstrating logger usage."""
Expand All @@ -38,6 +54,8 @@ def handler(event: Any, context: DurableContext) -> str:
name="process_data",
)

context.step(my_step(123))

context.logger.info("Step 1 completed", extra={"result": result1})

# Child contexts inherit the parent's logger and have their own step ID
Expand Down
Loading