|
| 1 | +# Configuration loading |
| 2 | + |
| 3 | +LogIt++ configuration is split into explicit phases: |
| 4 | + |
| 5 | +```text |
| 6 | +JSON value or text |
| 7 | + -> ConfigurationDocument |
| 8 | + -> validation and materialization |
| 9 | + -> programmatic binding resolution |
| 10 | + -> runtime logger construction |
| 11 | +``` |
| 12 | + |
| 13 | +The core semantic model and runtime layers do not depend on a JSON library. |
| 14 | +The JSON frontend is optional and uses `nlohmann::json` only when |
| 15 | +`LOGIT_WITH_JSON_CONFIG=ON` is selected. |
| 16 | + |
| 17 | +## Enabling the JSON frontend |
| 18 | + |
| 19 | +Install `nlohmann_json` or allow the source-tree fallback: |
| 20 | + |
| 21 | +```bash |
| 22 | +cmake -S . -B build \ |
| 23 | + -DLOGIT_WITH_JSON_CONFIG=ON \ |
| 24 | + -DLOGIT_USE_SUBMODULES=ON |
| 25 | +``` |
| 26 | + |
| 27 | +Installed packages configured with this option use |
| 28 | +`find_dependency(nlohmann_json 3.11 CONFIG)`. Installing a build that uses the |
| 29 | +bundled fallback is intentionally rejected; install `nlohmann_json` separately |
| 30 | +for an exportable package. |
| 31 | + |
| 32 | +## Parsing |
| 33 | + |
| 34 | +With the option enabled, `<logit.hpp>` exposes overloads for JSON text and an |
| 35 | +already parsed `nlohmann::json` value: |
| 36 | + |
| 37 | +```cpp |
| 38 | +#include <logit.hpp> |
| 39 | + |
| 40 | +const std::string text = R"json({ |
| 41 | + "schema_version": 1, |
| 42 | + "loggers": [{ |
| 43 | + "id": "application-file", |
| 44 | + "type": "file", |
| 45 | + "strategy": { |
| 46 | + "level": "info", |
| 47 | + "formatter": {"pattern": "%v", "json": false} |
| 48 | + }, |
| 49 | + "backend": { |
| 50 | + "directory": "logs", |
| 51 | + "async": true, |
| 52 | + "use_dedicated_executor": true, |
| 53 | + "queue_capacity": 8192, |
| 54 | + "queue_policy": "block" |
| 55 | + } |
| 56 | + }] |
| 57 | +})json"; |
| 58 | + |
| 59 | +logit::ConfigurationDocument document; |
| 60 | +logit::ConfigurationDiagnostics diagnostics; |
| 61 | +if (!logit::parse_configuration_json(text, document, diagnostics)) { |
| 62 | + // Inspect diagnostics.items(). |
| 63 | +} |
| 64 | +``` |
| 65 | + |
| 66 | +Parsing has no logger side effects and replaces `document` only after a |
| 67 | +complete successful conversion. The frontend reports JSON syntax and |
| 68 | +shape/conversion errors with path-aware diagnostics and uses |
| 69 | +`configuration_parse_failed` for syntax errors. Backend schema validation is a |
| 70 | +later core phase: backend unknown fields, backend types, enum/named values, |
| 71 | +defaults, and feature availability may be diagnosed by |
| 72 | +`materialize_configuration()` rather than by the JSON conversion itself. JSON |
| 73 | +floating-point values are rejected because schema v1 has only signed and |
| 74 | +unsigned integer numeric values. |
| 75 | + |
| 76 | +Call `materialize_configuration()` and `instantiate_configuration()` explicitly |
| 77 | +for the later phases. The frontend does not read files, apply frontend-specific |
| 78 | +defaults, resolve callbacks, or construct loggers. Properties input and hot |
| 79 | +reload remain outside the current implementation. |
0 commit comments