|
4 | 4 |
|
5 | 5 | package io.ktor.server.config |
6 | 6 |
|
| 7 | +import io.ktor.util.logging.* |
| 8 | + |
7 | 9 | internal expect val CONFIG_PATH: List<String> |
8 | 10 |
|
| 11 | +private val logger = KtorSimpleLogger("io.ktor.server.config.ConfigLoader") |
| 12 | + |
9 | 13 | /** |
10 | 14 | * Loads an application configuration. |
11 | 15 | * An implementation of this interface should return [ApplicationConfig] if applicable configuration is found |
@@ -51,23 +55,34 @@ public interface ConfigLoader { |
51 | 55 | */ |
52 | 56 | public fun load(path: String? = null): ApplicationConfig { |
53 | 57 | if (path == null) { |
| 58 | + logger.debug("Loading default configuration") |
54 | 59 | val default = loadDefault() |
55 | 60 | if (default != null) return default |
56 | 61 | } |
57 | 62 |
|
58 | 63 | for (loader in configLoaders) { |
| 64 | + logger.debug("Trying ConfigLoader: ${loader::class.simpleName}") |
59 | 65 | val config = loader.load(path) |
60 | | - if (config != null) return config |
| 66 | + if (config != null) { |
| 67 | + logger.debug("Configuration loaded successfully using ${loader::class.simpleName} from path: $path") |
| 68 | + return config |
| 69 | + } |
61 | 70 | } |
62 | 71 |
|
| 72 | + logger.debug("No configuration found, using empty MapApplicationConfig") |
63 | 73 | return MapApplicationConfig() |
64 | 74 | } |
65 | 75 |
|
66 | 76 | private fun loadDefault(): ApplicationConfig? { |
67 | 77 | for (defaultPath in CONFIG_PATH) { |
| 78 | + logger.debug("Trying default config path: $defaultPath") |
68 | 79 | for (loader in configLoaders) { |
| 80 | + logger.debug("Trying ConfigLoader: ${loader::class.simpleName} for path: $defaultPath") |
69 | 81 | val config = loader.load(defaultPath) |
70 | | - if (config != null) return config |
| 82 | + if (config != null) { |
| 83 | + logger.debug("Default configuration loaded using ${loader::class.simpleName} from path: $defaultPath") |
| 84 | + return config |
| 85 | + } |
71 | 86 | } |
72 | 87 | } |
73 | 88 |
|
|
0 commit comments