# DLT Log Rust Adapter
DLT Log is a Rust crate that provides a [`log`](https://docs.rs/log) adapter for integrating with the Diagnostic Log and Trace (DLT) system. The library generates FFI bindings to the C DLT library using bindgen and implements a logger that sends log messages to the DLT system. This is commonly used in the automotive industry for logging and tracing in embedded systems.
Always reference these instructions first and fallback to search or bash commands only when you encounter unexpected information that does not match the info here.
## Working Effectively
**CRITICAL**: ALL build and test commands take significant time. NEVER CANCEL any build, test, or coverage command. Set explicit timeouts as shown below.
### Dependencies and Setup
- Run `.devcontainer/onCreateCommand.sh` to install dependencies
### Build Process
- **Build**: `cargo build` -- takes 40 seconds on first build. NEVER CANCEL. Set timeout to 120+ seconds.
- **Documentation**: `cargo doc` -- takes 3 seconds. Set timeout to 30+ seconds.
- **Linting**: `cargo clippy -- -D warnings` -- takes 2 seconds. Set timeout to 30+ seconds.
- **Format check**: `cargo fmt -- --check` -- takes <1 second. Set timeout to 15+ seconds.
### Testing
**IMPORTANT**: Tests interact with the DLT daemon and require specific setup.
- **Tests without DLT daemon**:
- Stop daemon: `killall --wait dlt-daemon || true`
- Run specific test: `cargo test --test init_ok` -- takes 11 seconds. NEVER CANCEL. Set timeout to 60+ seconds.
- **Tests with DLT daemon**:
- Start daemon: `dlt-daemon -d`
- Run all tests: `cargo test` -- takes 60 seconds. NEVER CANCEL. Set timeout to 120+ seconds.
### Examples and Validation
- **Run example**: `cargo run --example simple` -- takes 10 seconds. Set timeout to 60+ seconds.
- **Test with console output**: `DLT_LOCAL_PRINT_MODE=FORCE_ON DLT_INITIAL_LOG_LEVEL="::6" cargo run --example simple`
- Expected output shows log messages with timestamps and log levels from TRACE to ERROR.
### Code Coverage
- **Coverage report**: `./scripts/coverage.sh` -- takes 56 seconds. NEVER CANCEL. Set timeout to 120+ seconds.
### Complete CI Validation
- **Full CI**: `./scripts/ci.sh`
- The CI script performs all build, test, lint steps in sequence.
## Validation Scenarios
ALWAYS test actual functionality after making changes:
1. **Basic functionality test**:
- Ensure DLT daemon is running: `dlt-daemon -d`
- Run: `DLT_LOCAL_PRINT_MODE=FORCE_ON DLT_INITIAL_LOG_LEVEL="::6" cargo run --example simple`
- Verify you see all 5 log levels (verbose, debug, info, warn, error) in console output
2. **Integration test**:
- Run complete test suite: `cargo test`
- Verify all tests pass
3. **Code quality validation**:
- Always run `cargo fmt -- --check` before committing
- Always run `cargo clippy -- -D warnings` before committing
- CI will fail if these checks don't pass
## Common Tasks
### Repository Structure
```
.
├── README.md # Main documentation with usage examples
├── Cargo.toml # Project configuration, dependencies, metadata
├── build.rs # Bindgen configuration for FFI generation
├── src/
│ ├── lib.rs # Main library code with DLT logger implementation
│ ├── libdlt.rs # Generated FFI bindings (auto-generated)
│ └── libdlt_wrapper.h # C header wrapper for bindgen
├── examples/
│ └── simple.rs # Basic usage example showing all log levels
├── tests/ # Integration tests for initialization and logging
├── scripts/
│ ├── ci.sh # Complete CI validation script
│ └── coverage.sh # Coverage report generation
├── .github/workflows/
│ └── ci.yml # GitHub Actions CI configuration
└── .devcontainer/ # Dev container setup for consistent environment
```
### Key Project Information
- **Language**: Rust (minimum version 1.82)
- **Dependencies**: libclang-dev (for bindgen), libdlt-dev (for DLT library), dlt-daemon (for testing)
- **Build system**: Cargo with custom build.rs for FFI binding generation
- **Testing**: Unit tests + integration tests requiring DLT daemon
- **Coverage requirement**: 100% coverage (enforced in CI)
- **Documentation**: Available at [docs.rs/dlt_log](https://docs.rs/dlt_log)
### Environment-Specific Notes
- The DLT daemon may show "System not booted with systemd!" warnings - this is expected in containerized environments
- FIFO connection errors in logs are normal when daemon runs with restricted permissions
- Cross-compilation requires special setup with BINDGEN_EXTRA_CLANG_ARGS environment variable
### Build Artifacts
- **Documentation**: Generated in `target/doc/dlt_log/`
- **Coverage report**: Generated as `target/coverage/lcov.info`
- **Bindings**: Auto-generated `libdlt_bindings.rs` in build output directory
Always build and exercise your changes with the validation scenarios above before considering the task complete.