Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces a comprehensive generic logging framework for wolfHSM with a frontend API and pluggable backend interface. The framework supports configurable logging levels (INFO, ERROR, SECEVENT), structured log entries with timestamps, and includes two built-in backends: a single-threaded ring buffer and a thread-safe POSIX file logger. The logging system is fully optional via WOLFHSM_CFG_LOGGING and integrates cleanly with the server context.
Key changes:
- Generic logging API with callback-based backends supporting initialization, entry addition, iteration, export, and clearing operations
- Global system time macro (
WH_GETTIME_US) for timestamps, with POSIX implementation viaclock_gettime() - Integration into server context with logging at key operations (init, cleanup, comm events, errors)
Additionally, the PR includes an unrelated fix that silently truncates metadata labels when caching keys instead of rejecting oversized labels with an error.
Reviewed changes
Copilot reviewed 22 out of 22 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| wolfhsm/wh_settings.h | Adds system time configuration and WH_GETTIME_US macro, defines WOLFHSM_CFG_LOG_MSG_MAX |
| wolfhsm/wh_log.h | Core logging API with level enums, entry structure, frontend functions, and macro definitions |
| wolfhsm/wh_log_ringbuf.h | Ring buffer backend header with configuration and callback definitions |
| wolfhsm/wh_server.h | Adds log context to server configuration and context structures |
| src/wh_log.c | Frontend implementation handling entry submission, formatting, and backend delegation |
| src/wh_log_ringbuf.c | Ring buffer backend with wraparound logic and entry management |
| src/wh_server.c | Integrates logging into server lifecycle and communication events |
| src/wh_server_keystore.c | Adds security event logging for non-exportable key access attempts; implements label truncation |
| port/posix/posix_time.{h,c} | POSIX time helper using clock_gettime() for microsecond timestamps |
| port/posix/posix_log_file.{h,c} | Thread-safe POSIX file backend with mutex protection and text-based log format |
| test/wh_test_log.{h,c} | Comprehensive test suite covering frontend, backends, macros, and concurrent access |
| test/wh_test.c | Adds log tests to main test suite |
| test/config/wolfhsm_cfg.h | Enables logging and configures POSIX time for tests |
| tools/whnvmtool/, examples/, benchmark/* | Adds WOLFHSM_CFG_NO_SYS_TIME or POSIX time configuration where needed |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Add system time macro - Fix key cache label truncation
AlexLanzano
left a comment
There was a problem hiding this comment.
Looks great! Can't wait to integrate into the TDA4 port
billphipps
left a comment
There was a problem hiding this comment.
Minor nits and some considers. Looks great especially the testing!! Needs some docs...
billphipps
left a comment
There was a problem hiding this comment.
Great addition! Can't wait to go back and replace some of the existing debug/info statements with these logging commands instead.
|
Thanks! Yep I will have all that integrated in a few follow up PRs. Probably layer by layer. Think we need to centralize some of the error handling a bit first as well to reduce the number of locations in which we need to add logs. Just food for thought |
Unrelated: