Bird
0
0

How can you modify this logging function to also save logs to a file?

hard📝 Application Q9 of 15
Agentic AI - Agent Observability
How can you modify this logging function to also save logs to a file?
def log_call(tool, result):
    print(f"Calling {tool}...")
    print(f"Result: {result}")
AUse print with extra arguments for file output
BReplace print with return statements
CChange function to accept a filename parameter only
DAdd file open and write statements inside the function
Step-by-Step Solution
Solution:
  1. Step 1: Understand how to write logs to a file

    Open a file in append mode and write log lines inside the function.
  2. Step 2: Evaluate options for saving logs

    Add file open and write statements inside the function correctly adds file writing; others do not save logs to file properly.
  3. Final Answer:

    Add file open and write statements inside the function -> Option D
  4. Quick Check:

    File writing requires open() and write() calls [OK]
Quick Trick: Use open('file', 'a') and write() to save logs [OK]
Common Mistakes:
  • Replacing print with return
  • Misusing print for file output
  • Changing parameters without writing

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Agentic AI Quizzes