Skip to content

Conversation

@bigbrett
Copy link
Contributor

  • Introduces generic logging framework consisting of front-end API with back-end callbacks
  • Adds two basic built-in back-end engines: Single threaded ring buffer and POSIX file log
  • Adds global wolfHSM system time macro for things like logging or benchmarks

Unrelated:

  • Truncate metadata label when caching keys

@bigbrett bigbrett requested a review from Copilot November 21, 2025 21:00
Copilot finished reviewing on behalf of bigbrett November 21, 2025 21:03
Copy link
Contributor

Copilot AI left a 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 via clock_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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants