Skip to content

Commit 4594a3c

Browse files
Alex Wangwangyb-A
authored andcommitted
fix: update logging example
- Set logging level to info so that we can actually print logs at info level - Add logging for warn and error
1 parent 73d9114 commit 4594a3c

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

examples/src/logger_example/logger_example.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,16 @@
44

55
from aws_durable_execution_sdk_python.context import (
66
DurableContext,
7+
StepContext,
78
durable_with_child_context,
9+
durable_step,
810
)
911
from aws_durable_execution_sdk_python.execution import durable_execution
1012

13+
import logging
14+
15+
logging.getLogger().setLevel(logging.INFO)
16+
1117

1218
@durable_with_child_context
1319
def child_workflow(ctx: DurableContext) -> str:
@@ -26,6 +32,16 @@ def child_workflow(ctx: DurableContext) -> str:
2632
return child_result
2733

2834

35+
@durable_step
36+
def my_step(step_context: StepContext, my_arg: int) -> str:
37+
step_context.logger.info("Hello from my_step")
38+
step_context.logger.warning("Warning from my_step", extra={"my_arg": my_arg})
39+
step_context.logger.error(
40+
"Error from my_step", extra={"my_arg": my_arg, "type": "error"}
41+
)
42+
return f"from my_step: {my_arg}"
43+
44+
2945
@durable_execution
3046
def handler(event: Any, context: DurableContext) -> str:
3147
"""Handler demonstrating logger usage."""
@@ -38,6 +54,8 @@ def handler(event: Any, context: DurableContext) -> str:
3854
name="process_data",
3955
)
4056

57+
context.step(my_step(123))
58+
4159
context.logger.info("Step 1 completed", extra={"result": result1})
4260

4361
# Child contexts inherit the parent's logger and have their own step ID

0 commit comments

Comments
 (0)