You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -547,12 +553,39 @@ Debug logging is very verbose, and targets allow configuration of granular log l
547
553
A `target` is a string value that is added to the standard tracing macro calls (`debug!, error!, etc`).
548
554
Log levels can be configured for each `target` individually.
549
555
550
-
A number of targets are already defined in `log.rs`.
556
+
### Logging Architecture
551
557
552
-
The targets are aligned with the different components and contexts (`PROTOCOL, AUTHENTICATION, MAPPER, etc`)
558
+
The logging system uses a declarative macro approach for managing log targets:
559
+
560
+
-**Single source of truth**: All log targets are defined in `packages/cipherstash-proxy/src/log/targets.rs` using the `define_log_targets!` macro
561
+
-**Automatic generation**: The macro generates target constants, configuration struct fields, and accessor functions
562
+
-**Type safety**: Uses a generated `LogTargetLevels` struct with serde flattening for config integration
563
+
-**Self-documenting**: Clear separation between core config and target-specific levels
564
+
565
+
The targets are aligned with the different components and contexts (`PROTOCOL`, `AUTHENTICATION`, `MAPPER`, etc.).
553
566
554
567
There is a general `DEVELOPMENT` target for logs that don't quite fit into a specific category.
555
568
569
+
### Adding a New Log Target
570
+
571
+
To add a new log target, you only need to add **one line** to the macro in `packages/cipherstash-proxy/src/log/targets.rs`:
572
+
573
+
```rust
574
+
define_log_targets!(
575
+
(DEVELOPMENT, development_level),
576
+
(AUTHENTICATION, authentication_level),
577
+
// ... existing targets ...
578
+
(NEW_TARGET, new_target_level), // <- Add this line
579
+
);
580
+
```
581
+
582
+
The constant name (e.g., `NEW_TARGET`) is automatically converted to a string value using `stringify!()`, so `NEW_TARGET` becomes `"NEW_TARGET"` for use in logging calls.
583
+
584
+
This automatically:
585
+
- Creates the `NEW_TARGET` constant for use in logging calls
586
+
- Generates the `new_target_level` field in `LogTargetLevels` struct
587
+
- Creates the environment variable `CS_LOG__NEW_TARGET_LEVEL`
588
+
- Adds the target to all logging functions and validation
0 commit comments