Skip to content

Commit 18ae558

Browse files
committed
feat(config): add optional JSON frontend
Map JSON text and nlohmann::json values into the parser-neutral configuration document without runtime side effects. Propagate the optional dependency through CMake and pkg-config packages, add focused tests and Linux CI coverage, and document the supported scope.
1 parent a293dbb commit 18ae558

17 files changed

Lines changed: 798 additions & 5 deletions

‎.github/workflows/ci.yml‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,48 @@ jobs:
2525
run: cmake --install build --prefix install
2626
- name: Test
2727
run: ctest --test-dir build --output-on-failure
28+
- name: Install optional JSON configuration frontend dependency
29+
if: matrix.std == 11
30+
run: sudo apt-get update && sudo apt-get install -y nlohmann-json3-dev
31+
- name: Configure optional JSON configuration frontend
32+
if: matrix.std == 11
33+
run: >-
34+
cmake -S . -B build-json-config
35+
-DLOGIT_CPP_BUILD_TESTS=ON
36+
-DLOGIT_WITH_JSON_CONFIG=ON
37+
-DLOGIT_WITH_SYSLOG=OFF
38+
-DLOGIT_WITH_WIN_EVENT_LOG=OFF
39+
-DCMAKE_CXX_STANDARD=11
40+
- name: Build optional JSON configuration frontend test
41+
if: matrix.std == 11
42+
run: cmake --build build-json-config --target configuration_json_test
43+
- name: Test optional JSON configuration frontend
44+
if: matrix.std == 11
45+
run: ctest --test-dir build-json-config --output-on-failure -R '^configuration_json_test$'
46+
- name: Install optional JSON configuration package
47+
if: matrix.std == 11
48+
run: cmake --install build-json-config --prefix install-json-config
49+
- name: Configure optional JSON installed-package consumer
50+
if: matrix.std == 11
51+
run: >-
52+
cmake -S tests/install_consumer -B build-json-consumer
53+
-DCMAKE_PREFIX_PATH=${{ github.workspace }}/install-json-config
54+
-DCMAKE_CXX_STANDARD=11
55+
- name: Build and run optional JSON installed-package consumer
56+
if: matrix.std == 11
57+
run: |
58+
cmake --build build-json-consumer
59+
./build-json-consumer/install_consumer
60+
- name: Configure optional JSON pkg-config consumer
61+
if: matrix.std == 11
62+
env:
63+
PKG_CONFIG_PATH: ${{ github.workspace }}/install-json-config/share/pkgconfig:${{ github.workspace }}/install-json-config/lib/pkgconfig
64+
run: cmake -S tests/pkgconfig_consumer -B build-json-pkgconfig
65+
- name: Build and run optional JSON pkg-config consumer
66+
if: matrix.std == 11
67+
run: |
68+
cmake --build build-json-pkgconfig
69+
./build-json-pkgconfig/pkgconfig_consumer
2870
- name: Configure benchmarks
2971
# if: ${{ github.event_name == 'pull_request' || (github.event_name == 'push' && github.ref == 'refs/heads/stable') }}
3072
run: cmake -S . -B build-bench -DLOGIT_BENCH_ENABLE=ON -DLOGIT_BENCH_WITH_SPDLOG=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_STANDARD=${{ matrix.std }} -DLOGIT_WITH_SYSLOG=ON -DLOGIT_WITH_WIN_EVENT_LOG=OFF

‎CHANGELOG.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ All notable changes to this project will be documented in this file.
2424
- Added MDBX runtime factory support when the optional MDBX backend is enabled.
2525
- Added optional typed MDBX `on_error` binding support and build-feature-aware
2626
validation for MDBX payload compression.
27+
- Added an optional nlohmann::json frontend that maps JSON text or values into
28+
the parser-neutral configuration model without performing runtime side effects.
2729

2830
### Fixed
2931

‎CMakeLists.txt‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ option(LOGIT_WITH_OTLP "Enable OTLP/HTTP log export via optional kurlyk dependen
1313
option(LOGIT_WITH_PROMETHEUS "Enable Prometheus text payload support" OFF)
1414
option(LOGIT_WITH_PROMETHEUS_SERVER "Enable Prometheus HTTP server backend" OFF)
1515
option(LOGIT_WITH_MDBX "Enable MDBX structured log storage backend" OFF)
16+
option(LOGIT_WITH_JSON_CONFIG "Enable the optional nlohmann::json configuration frontend" OFF)
1617
option(LOGIT_USE_SUBMODULES "Allow bundled optional dependency fallback" OFF)
1718
option(LOGIT_WITH_SYSLOG "Enable POSIX syslog backend" ON)
1819
option(LOGIT_WITH_WIN_EVENT_LOG "Enable Windows Event Log backend" ON)
@@ -103,6 +104,25 @@ if(LOGIT_WITH_FMT)
103104
target_link_libraries(log-it-cpp INTERFACE fmt::fmt)
104105
endif()
105106

107+
# ---------- JSON configuration frontend ----------
108+
if(LOGIT_WITH_JSON_CONFIG)
109+
if(NOT TARGET nlohmann_json::nlohmann_json)
110+
find_package(nlohmann_json 3.11 QUIET CONFIG)
111+
endif()
112+
if(NOT TARGET nlohmann_json::nlohmann_json AND LOGIT_USE_SUBMODULES)
113+
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/external/kurlyk/external/json/CMakeLists.txt")
114+
set(JSON_BuildTests OFF CACHE BOOL "Disable bundled nlohmann/json tests" FORCE)
115+
add_subdirectory(external/kurlyk/external/json EXCLUDE_FROM_ALL)
116+
endif()
117+
endif()
118+
if(NOT TARGET nlohmann_json::nlohmann_json)
119+
message(FATAL_ERROR
120+
"nlohmann_json not found. Install nlohmann_json or enable LOGIT_USE_SUBMODULES with the kurlyk submodule present.")
121+
endif()
122+
target_compile_definitions(log-it-cpp INTERFACE LOGIT_WITH_JSON_CONFIG=1)
123+
target_link_libraries(log-it-cpp INTERFACE nlohmann_json::nlohmann_json)
124+
endif()
125+
106126
# ---------- OTLP/HTTP (kurlyk) ----------
107127
if(LOGIT_WITH_OTLP)
108128
if(EMSCRIPTEN)
@@ -329,6 +349,18 @@ if(LOGIT_WITH_FMT AND TARGET fmt::fmt)
329349
endif()
330350
endif()
331351

352+
if(LOGIT_WITH_JSON_CONFIG AND TARGET nlohmann_json::nlohmann_json)
353+
get_target_property(_nlohmann_json_imported nlohmann_json::nlohmann_json IMPORTED)
354+
if(NOT _nlohmann_json_imported)
355+
set(_logit_install_export_supported OFF)
356+
install(CODE [[
357+
message(FATAL_ERROR
358+
"log-it-cpp: Installing with bundled nlohmann_json is not supported. "
359+
"Install nlohmann_json separately and use find_package(nlohmann_json), or disable LOGIT_WITH_JSON_CONFIG.")
360+
]])
361+
endif()
362+
endif()
363+
332364
if(LOGIT_WITH_PROMETHEUS_SERVER)
333365
set(_logit_install_export_supported OFF)
334366
install(CODE [[
@@ -393,6 +425,13 @@ write_basic_package_version_file(
393425
INSTALL_DESTINATION lib/cmake/log-it-cpp
394426
)
395427

428+
set(LOGIT_PC_REQUIRES "time-shield >= 2.0.0, time-shield < 2.1.0")
429+
set(LOGIT_PC_CFLAGS "")
430+
if(LOGIT_WITH_JSON_CONFIG)
431+
string(APPEND LOGIT_PC_REQUIRES ", nlohmann_json >= 3.11")
432+
string(APPEND LOGIT_PC_CFLAGS " -DLOGIT_WITH_JSON_CONFIG=1")
433+
endif()
434+
396435
configure_file(
397436
cmake/log-it-cpp.pc.in
398437
"${CMAKE_CURRENT_BINARY_DIR}/log-it-cpp.pc"

‎README-RU.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ scope-замер.
5454
- [`docs/quickstart.md`](docs/quickstart.md) — краткий старт и карта документации.
5555
- [`docs/installation.md`](docs/installation.md) — установка через CMake, vendored и installed package сценарии.
5656
- [`docs/backends.md`](docs/backends.md) — матрица бэкендов, платформ, зависимостей и packaging.
57+
- [`docs/configuration-loading-RU.md`](docs/configuration-loading-RU.md) — parser-neutral pipeline конфигурации и optional JSON frontend.
5758
- [`docs/benchmarks.md`](docs/benchmarks.md) — методика benchmark и исторический snapshot.
5859
- [`docs/comparison-RU.md`](docs/comparison-RU.md) — сравнение со spdlog, Quill, Boost.Log, glog и IceCream-Cpp.
5960

‎README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ Detailed guides and documentation map:
7070
- [`docs/quickstart.md`](docs/quickstart.md) — quick start and documentation map.
7171
- [`docs/installation.md`](docs/installation.md) — CMake, vendored, installed-package, and package-manager setup.
7272
- [`docs/backends.md`](docs/backends.md) — backend, platform, dependency, and packaging matrix.
73+
- [`docs/configuration-loading.md`](docs/configuration-loading.md) — parser-neutral configuration pipeline and optional JSON frontend.
7374
- [`docs/benchmarks.md`](docs/benchmarks.md) — benchmark methodology and historical snapshot.
7475
- [`docs/comparison.md`](docs/comparison.md) — comparison with spdlog, Quill, Boost.Log, glog, and IceCream-Cpp.
7576

‎cmake/log-it-cpp.pc.in‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ includedir=${prefix}/include
66
Name: log-it-cpp
77
Description: LogIt C++ logging library
88
Version: @PROJECT_VERSION@
9-
Requires: time-shield >= 2.0.0, time-shield < 2.1.0
10-
Cflags: -I${includedir}/logit_cpp
9+
Requires: @LOGIT_PC_REQUIRES@
10+
Cflags: -I${includedir}/logit_cpp@LOGIT_PC_CFLAGS@
1111
Libs:

‎cmake/log-it-cppConfig.cmake.in‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ if(@LOGIT_WITH_FMT@ AND NOT TARGET fmt::fmt)
99
find_dependency(fmt CONFIG)
1010
endif()
1111

12+
if(@LOGIT_WITH_JSON_CONFIG@ AND NOT TARGET nlohmann_json::nlohmann_json)
13+
find_dependency(nlohmann_json 3.11 CONFIG)
14+
endif()
15+
1216
if(@LOGIT_WITH_OTLP@ AND NOT TARGET kurlyk)
1317
find_dependency(kurlyk CONFIG)
1418
endif()

‎docs/configuration-loading-RU.md‎

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Загрузка конфигурации
2+
3+
Конфигурация LogIt++ разделена на явные этапы:
4+
5+
```text
6+
JSON value или text
7+
-> ConfigurationDocument
8+
-> validation и materialization
9+
-> разрешение programmatic bindings
10+
-> создание runtime logger'ов
11+
```
12+
13+
Основная semantic model и runtime-слои не зависят от JSON-библиотеки. JSON
14+
frontend является optional и использует `nlohmann::json` только при включённой
15+
опции `LOGIT_WITH_JSON_CONFIG=ON`.
16+
17+
## Включение JSON frontend
18+
19+
Установите `nlohmann_json` либо разрешите fallback из дерева исходников:
20+
21+
```bash
22+
cmake -S . -B build \
23+
-DLOGIT_WITH_JSON_CONFIG=ON \
24+
-DLOGIT_USE_SUBMODULES=ON
25+
```
26+
27+
Установленный пакет с этой опцией использует
28+
`find_dependency(nlohmann_json 3.11 CONFIG)`. Установка сборки с bundled
29+
fallback намеренно запрещена: для экспортируемого пакета установите
30+
`nlohmann_json` отдельно.
31+
32+
## Разбор JSON
33+
34+
При включённой опции `<logit.hpp>` предоставляет overload'ы для JSON-текста и
35+
уже разобранного значения `nlohmann::json`:
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+
"backend": {
46+
"directory": "logs",
47+
"async": true,
48+
"use_dedicated_executor": true,
49+
"queue_capacity": 8192,
50+
"queue_policy": "block"
51+
}
52+
}]
53+
})json";
54+
55+
logit::ConfigurationDocument document;
56+
logit::ConfigurationDiagnostics diagnostics;
57+
if (!logit::parse_configuration_json(text, document, diagnostics)) {
58+
// Обработайте diagnostics.items().
59+
}
60+
```
61+
62+
Разбор не создаёт logger'ы и заменяет `document` только после полного успеха.
63+
Синтаксические ошибки используют категорию `configuration_parse_failed`;
64+
структурные ошибки, неверные типы, named values и неизвестные поля получают
65+
path-aware diagnostics. Floating-point значения JSON отклоняются, поскольку в
66+
schema v1 предусмотрены только signed и unsigned integer значения.
67+
68+
Следующие этапы вызываются явно через `materialize_configuration()` и
69+
`instantiate_configuration()`. Frontend не читает файлы, не вводит собственные
70+
defaults, не разрешает callback'и и не создаёт logger'ы. Properties input и hot
71+
reload пока не реализованы.

‎docs/configuration-loading.md‎

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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. Syntax errors use
68+
`configuration_parse_failed`; structural, type, named-value, and unknown-field
69+
errors retain path-aware diagnostics. JSON floating-point values are rejected
70+
because schema v1 has only signed and unsigned integer numeric values.
71+
72+
Call `materialize_configuration()` and `instantiate_configuration()` explicitly
73+
for the later phases. The frontend does not read files, apply frontend-specific
74+
defaults, resolve callbacks, or construct loggers. Properties input and hot
75+
reload remain outside the current implementation.

‎docs/future-plans.md‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,10 @@ Legend:
5151
failures and are covered by tests.
5252
- [ ] **Configuration loading** — design a versioned JSON/properties mapping to
5353
the existing backend configuration. The proposed contract is recorded in
54-
[ADR 0009](adr/0009-configuration-loading-contract.md). Treat file
55-
watching/hot reload as a follow-up, not part of the first configuration API.
54+
[ADR 0009](adr/0009-configuration-loading-contract.md). The parser-neutral
55+
model, built-in materialization/runtime layers, and optional JSON text/value
56+
frontend are delivered; file-loading convenience and a properties frontend
57+
remain follow-ups. File watching/hot reload is not part of this API.
5658
- [ ] **Extended filtering** — evaluate source/file, message, tag/MDC, and
5759
range filters; define their cost and ordering before adding public API.
5860
- [x] **Benchmark follow-up** — formatted and passthrough public-macro scenarios,

0 commit comments

Comments
 (0)