-
Notifications
You must be signed in to change notification settings - Fork 22
Logging #253
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Logging #253
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
Unrelated: