Commit 1ef06d8
refactor: enhance Config and command base with comprehensive scenario-aware logging (#4488)
## Summary
Comprehensive enhancement of Config class and command base logging with
scenario-aware context, building on the foundation from merged PRs #4483
and #4484.
## User-Facing Changes
**Enhanced logging context across all Config and command operations:**
### Before: Generic logging without context
```
DEBUG Validating schema molecule.yml
WARNING Driver 'default' is currently in use but config defines 'podman'
INFO Performing prerun with role_name_check=0...
```
### After: Complete scenario and step context
```
DEBUG smoke ➜ validate: Validating schema /path/to/molecule.yml
WARNING smoke ➜ config: Driver 'default' is currently in use but config defines 'podman'
INFO smoke ➜ prerun: Performing prerun with role_name_check=0...
INFO smoke ➜ discovery: scenario test matrix: syntax
```
## Technical Implementation
**🏗️ Config Class Enhancements:**
- Add reusable `@property _log` method to Config class for dynamic
scenario context
- Convert all Config logging calls to use scenario-aware loggers
- Enhanced validation logging with hardcoded scenario context during
bootstrap
- Improved galaxy file and driver validation warnings with full context
**🧹 Command Base Logger Consolidation:**
- Replace 5 scattered `get_scenario_logger()` calls with single global
`_log()` function
- Unified logging pattern: `_log(scenario_name, step, message,
level='info')`
- Pre-formatted messages eliminate complex placeholder handling
- Cleaner, more maintainable logger creation across all command
operations
**✅ Enhanced Test Coverage:**
- Updated `test_validate` to use `caplog` instead of mock patching
- Validates scenario logger extras: `molecule_scenario` and
`molecule_step`
- Robust verification of message content and context attributes
## Changes Included
**Config Class (4 commits):**
1. `feat: add step context to command base logger calls`
2. `feat: add scenario context to config file modification warning`
3. `refactor: add reusable _log property to Config class`
4. `refactor: convert all Config logging to scenario-aware logging`
**Command Base Improvements (2 commits):**
5. `refactor: replace scattered logger initializations with global _log
function`
6. `fix: update test_validate to use caplog and check scenario logger
extras`
**Dependencies (Included):**
- Builds on: All cleanup commits from PR #4487 (unused logger removal)
## Dependencies
- **Depends on**: PR #4487 (unused logger cleanup)
- **Builds on**: PR #4484 (merged - dynamic properties for
dependency/provisioner/verifier)
- **Foundation**: PR #4483 (merged - enhanced logging adapter with
dual-output)
## Testing
- ✅ **Comprehensive**: All config tests passing (45/45)
- ✅ **Enhanced coverage**: Validates scenario logger extras in test
suite
- ✅ **Functional verification**: `molecule syntax` confirms enhanced
logging works
- ✅ **Backwards compatible**: No breaking changes to existing
functionality
## Impact
- **Complete Config context**: All Config operations now include
scenario and step information
- **Unified command logging**: Consistent pattern across all command
base operations
- **Better maintainability**: Single global `_log` function replaces
scattered initializations
- **Enhanced debugging**: Full context for configuration validation and
driver operations
---------
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>1 parent edac329 commit 1ef06d8
File tree
3 files changed
+73
-24
lines changed- src/molecule
- command
- tests/unit
3 files changed
+73
-24
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
53 | 66 | | |
54 | 67 | | |
55 | 68 | | |
| |||
170 | 183 | | |
171 | 184 | | |
172 | 185 | | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
177 | 191 | | |
178 | 192 | | |
179 | 193 | | |
| |||
202 | 216 | | |
203 | 217 | | |
204 | 218 | | |
205 | | - | |
206 | | - | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
207 | 224 | | |
208 | 225 | | |
209 | 226 | | |
210 | 227 | | |
211 | 228 | | |
212 | 229 | | |
213 | | - | |
214 | | - | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
215 | 235 | | |
216 | 236 | | |
217 | 237 | | |
| |||
225 | 245 | | |
226 | 246 | | |
227 | 247 | | |
228 | | - | |
229 | | - | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
230 | 255 | | |
231 | 256 | | |
232 | 257 | | |
| |||
272 | 297 | | |
273 | 298 | | |
274 | 299 | | |
275 | | - | |
276 | | - | |
277 | | - | |
278 | | - | |
| 300 | + | |
| 301 | + | |
279 | 302 | | |
| 303 | + | |
| 304 | + | |
280 | 305 | | |
281 | 306 | | |
282 | 307 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
26 | 25 | | |
27 | 26 | | |
28 | 27 | | |
| |||
32 | 31 | | |
33 | 32 | | |
34 | 33 | | |
35 | | - | |
| 34 | + | |
36 | 35 | | |
37 | 36 | | |
38 | 37 | | |
| |||
55 | 54 | | |
56 | 55 | | |
57 | 56 | | |
58 | | - | |
59 | 57 | | |
60 | 58 | | |
61 | 59 | | |
| |||
287 | 285 | | |
288 | 286 | | |
289 | 287 | | |
290 | | - | |
| 288 | + | |
291 | 289 | | |
292 | 290 | | |
293 | 291 | | |
| |||
401 | 399 | | |
402 | 400 | | |
403 | 401 | | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
404 | 411 | | |
405 | 412 | | |
406 | 413 | | |
| |||
416 | 423 | | |
417 | 424 | | |
418 | 425 | | |
419 | | - | |
| 426 | + | |
420 | 427 | | |
421 | 428 | | |
422 | 429 | | |
| |||
478 | 485 | | |
479 | 486 | | |
480 | 487 | | |
481 | | - | |
| 488 | + | |
482 | 489 | | |
483 | 490 | | |
484 | 491 | | |
| |||
670 | 677 | | |
671 | 678 | | |
672 | 679 | | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
673 | 684 | | |
674 | | - | |
| 685 | + | |
675 | 686 | | |
676 | 687 | | |
677 | 688 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
| |||
391 | 392 | | |
392 | 393 | | |
393 | 394 | | |
394 | | - | |
| 395 | + | |
395 | 396 | | |
396 | 397 | | |
397 | 398 | | |
398 | 399 | | |
399 | | - | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
400 | 410 | | |
401 | | - | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
402 | 415 | | |
403 | 416 | | |
404 | 417 | | |
| |||
0 commit comments