This example demonstrates the verbose configuration debugging functionality in the Modular framework. It shows how to enable detailed DEBUG level logging during configuration processing to troubleshoot configuration issues, particularly with InstanceAware environment variable mapping in the Database module.
- Verbose Configuration Debugging: Enable detailed logging of the configuration loading process
- InstanceAware Environment Variable Mapping: Show how multiple database instances are configured from environment variables
- Debug Configuration Processing: Track which configs are being processed, which keys are evaluated, and which environment variables are searched
cd examples/verbose-debug
go run main.go// Create application
app := modular.NewStdApplication(configProvider, logger)
// Enable verbose configuration debugging
app.SetVerboseConfig(true)
// Initialize - this will now show detailed debug logs
err := app.Init()When verbose debugging is enabled, you'll see detailed logs showing:
- Which configuration sections are being processed
- Which environment variables are being looked up
- Which configuration keys are being evaluated
- How instance-aware mapping works
- Success/failure of configuration operations
The example sets up multiple database instances using the pattern:
DB_PRIMARY_*for primary databaseDB_SECONDARY_*for secondary databaseDB_CACHE_*for cache database
Each instance gets its own set of configuration variables like:
DB_PRIMARY_DRIVER=sqliteDB_PRIMARY_DSN=./primary.dbDB_PRIMARY_MAX_CONNS=10
This verbose debugging helps with:
- Troubleshooting: See exactly what the framework is doing during config loading
- Environment Variable Issues: Track which env vars are being searched for
- Instance Mapping Problems: Debug why instance-aware configuration isn't working
- Configuration Flow: Understand the order and process of config loading
- Development: Get insights into how the modular framework processes configuration
When you run the example, you'll see output like:
=== Verbose Configuration Debug Example ===
Setting up environment variables:
APP_NAME=Verbose Debug Example
DB_PRIMARY_DRIVER=sqlite
...
🔧 Enabling verbose configuration debugging...
DEBUG Verbose configuration debugging enabled
🚀 Initializing application with verbose debugging...
DEBUG Starting configuration loading process
DEBUG Configuration feeders available count=1
DEBUG Config feeder registered index=0 type=*feeders.EnvFeeder
DEBUG Added config feeder to builder type=*feeders.EnvFeeder
DEBUG Processing configuration sections
DEBUG Processing main configuration configType=*main.AppConfig section=_main
DEBUG EnvFeeder: Starting feed process structureType=*main.AppConfig
DEBUG EnvFeeder: Processing struct structType=main.AppConfig numFields=3 prefix=
DEBUG EnvFeeder: Processing field fieldName=AppName fieldType=string fieldKind=string
DEBUG EnvFeeder: Found env tag fieldName=AppName envTag=APP_NAME
DEBUG EnvFeeder: Looking up environment variable fieldName=AppName envName=APP_NAME envTag=APP_NAME prefix=
DEBUG EnvFeeder: Environment variable found fieldName=AppName envName=APP_NAME envValue=Verbose Debug Example
DEBUG EnvFeeder: Successfully set field value fieldName=AppName envName=APP_NAME envValue=Verbose Debug Example
...
This functionality is particularly useful for:
- Development: Understanding how configuration loading works
- Debugging: Troubleshooting configuration issues in complex applications
- Production Support: Diagnosing environment variable problems
- Module Development: Testing how modules register and load configuration
- Integration Testing: Verifying configuration flow in CI/CD pipelines