Skip to content

Logging#253

Merged
billphipps merged 6 commits intowolfSSL:mainfrom
bigbrett:logging
Dec 9, 2025
Merged

Logging#253
billphipps merged 6 commits intowolfSSL:mainfrom
bigbrett:logging

Conversation

@bigbrett
Copy link
Copy Markdown
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

Copy link
Copy Markdown
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
AlexLanzano
AlexLanzano previously approved these changes Dec 2, 2025
Copy link
Copy Markdown
Member

@AlexLanzano AlexLanzano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Can't wait to integrate into the TDA4 port

billphipps
billphipps previously approved these changes Dec 3, 2025
Copy link
Copy Markdown
Contributor

@billphipps billphipps left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nits and some considers. Looks great especially the testing!! Needs some docs...

@bigbrett bigbrett dismissed stale reviews from billphipps and AlexLanzano via 39e4637 December 9, 2025 20:38
@bigbrett bigbrett requested a review from billphipps December 9, 2025 20:47
Copy link
Copy Markdown
Contributor

@billphipps billphipps left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great addition! Can't wait to go back and replace some of the existing debug/info statements with these logging commands instead.

@bigbrett
Copy link
Copy Markdown
Contributor Author

bigbrett commented Dec 9, 2025

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

@billphipps billphipps merged commit d8afb8c into wolfSSL:main Dec 9, 2025
31 of 34 checks passed
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.

4 participants