- 
                Notifications
    You must be signed in to change notification settings 
- Fork 1.2k
KTOR-6610: feat: add debug log of ConfigLoader when server starts #5140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
| WalkthroughAdded debug logging to ConfigLoaders.kt in the load() and loadDefault() methods. Imported logging utilities and created a private logger instance. Logs indicate which ConfigLoader is attempted, success/failure outcomes, and default configuration loading events. No public API modifications. Changes
 Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Pre-merge checks and finishing touches❌ Failed checks (1 warning)
 ✅ Passed checks (2 passed)
 ✨ Finishing touches
 🧪 Generate unit tests (beta)
 Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment  | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
ktor-server/ktor-server-core/common/src/io/ktor/server/config/ConfigLoaders.kt (1)
63-70: Consider clarifying the log message for null paths.When
pathis null (which can occur ifloadDefault()returns null and a loader subsequently succeeds with a null path), line 67 logs "from path: null", which may be confusing.Consider making the message more explicit:
if (config != null) { - logger.debug("Configuration loaded successfully using ${loader::class.simpleName} from path: $path") + val pathInfo = path?.let { "from path: $it" } ?: "with null path (fallback)" + logger.debug("Configuration loaded successfully using ${loader::class.simpleName} $pathInfo") return config }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
- ktor-server/ktor-server-core/common/src/io/ktor/server/config/ConfigLoaders.kt(2 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{kt,kts}
📄 CodeRabbit inference engine (CLAUDE.md)
**/*.{kt,kts}: Follow Kotlin official style guide for all Kotlin source and build scripts
Use star imports for io.ktor.* packages
Max line length is 120 characters
Indent with 4 spaces in Kotlin code
Include a copyright header in new Kotlin files
Files:
- ktor-server/ktor-server-core/common/src/io/ktor/server/config/ConfigLoaders.kt
**/*.kt
📄 CodeRabbit inference engine (CLAUDE.md)
**/*.kt: Document all public Kotlin APIs, including parameters, return types, and exceptions
Annotate internal APIs with @internalapi
Follow Kotlin error-handling conventions and use specific Ktor exceptions
Files:
- ktor-server/ktor-server-core/common/src/io/ktor/server/config/ConfigLoaders.kt
🔇 Additional comments (5)
ktor-server/ktor-server-core/common/src/io/ktor/server/config/ConfigLoaders.kt (5)
7-8: LGTM: Import follows coding guidelines.The star import for
io.ktor.*packages aligns with the project's coding guidelines and properly imports the logging utilities needed for the debug functionality.
11-11: LGTM: Logger instance properly initialized.The private logger with a descriptive name is appropriate for this companion object's diagnostic logging needs.
57-61: LGTM: Default configuration loading logging is clear.The debug log appropriately indicates when the default configuration path is being attempted, providing useful diagnostic information.
72-73: LGTM: Clear fallback logging.The debug log appropriately indicates when no configuration is found and an empty
MapApplicationConfigis used as a fallback.
76-90: LGTM: Comprehensive default configuration loading logs.The nested logging structure clearly traces which default paths and loaders are being attempted, providing valuable diagnostic information. While this generates multiple debug messages in the nested loops, this is appropriate for debug-level logging and aligns with the PR's objective to reveal which ConfigLoader is used at server start.
Subsystem
ktor-server-core(io.ktor.server.config)Motivation
This PR fixes KTOR-6610. Related to KTOR-8992, too.
Adding debug log when server starts will reveal which configuration file is used.
If configuration is inappropriate, it gives following error as is.
However, adding debug log, the output is like:
Thus we can realize the ConfigLoader is not HoconConfigLoader, but YamlConfigLoader because we include
ktor-server-config-yamlon the classpath.Solution
Using KtorSimpleLogger and add debug log to ConfigLoader companion object.
I referred https://github.com/ktorio/ktor/blob/main/ktor-server/ktor-server-core/jvm/src/io/ktor/server/http/content/ETagProvider.kt as code style.
output example
Hocon
Yaml
No configuration