LogRecord objects do not have a .message attribute by default — it is
only populated after the record has been formatted by a Formatter.
The correct way to retrieve the formatted log message is getMessage().
This fixes AttributeError: 'LogRecord' object has no attribute 'message'
in test_cost_calculation_uses_debug_level and
test_batch_cost_calculation_uses_debug_level.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The cost calculation log level tests were failing when run with pytest-xdist
parallel execution because caplog doesn't work reliably across worker processes.
This causes "ValueError: I/O operation on closed file" errors.
Solution: Replace caplog fixture with a custom LogRecordHandler that directly
attaches to the logger. This approach works correctly in parallel execution
because each worker process has its own handler instance.
Fixes test failures in PR #21277 when running with --dist=loadscope.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Change verbose_logger.info() to verbose_logger.debug() for cost calculation messages
- Ensures cost calculation details are only shown when DEBUG logging is enabled
- Reduces log noise in production environments
Part 2/2 of fix for #9815