added log level

This commit is contained in:
2026-03-17 11:45:14 +11:00
parent 1d3eaff622
commit 2b3fe0630f
5 changed files with 93 additions and 6 deletions

View File

@@ -6,6 +6,16 @@
#pragma once
// Log level constants shared between C/C++ and Rust
typedef enum {
RUST_LOG_LEVEL_FATAL = 0,
RUST_LOG_LEVEL_ERROR = 1,
RUST_LOG_LEVEL_WARN = 2,
RUST_LOG_LEVEL_INFO = 3,
RUST_LOG_LEVEL_DEBUG = 4,
RUST_LOG_LEVEL_TRACE = 5,
} RustLogLevel;
#ifdef __cplusplus
extern "C" {
#endif
@@ -16,9 +26,21 @@ void rust_init_logging(const char* log_path);
// Authenticate user (stub)
int rust_auth_user(const char* user, const char* password);
// Log event (file sink)
// Legacy: Log event (file sink) — forwards to INFO level on Rust side
void rust_log_event(const char* event);
// New: Log event with explicit level
void rust_log_event_with_level(const char* event, RustLogLevel level);
#ifdef __cplusplus
}
#endif
// Convenience macros for C/C++ callers
#define RUST_LOG_FATAL(msg) rust_log_event_with_level((msg), RUST_LOG_LEVEL_FATAL)
#define RUST_LOG_ERROR(msg) rust_log_event_with_level((msg), RUST_LOG_LEVEL_ERROR)
#define RUST_LOG_WARN(msg) rust_log_event_with_level((msg), RUST_LOG_LEVEL_WARN)
#define RUST_LOG_INFO(msg) rust_log_event_with_level((msg), RUST_LOG_LEVEL_INFO)
#define RUST_LOG_DEBUG(msg) rust_log_event_with_level((msg), RUST_LOG_LEVEL_DEBUG)
#define RUST_LOG_TRACE(msg) rust_log_event_with_level((msg), RUST_LOG_LEVEL_TRACE)

View File

@@ -15,7 +15,7 @@ extern "C" {
int pam_sm_authenticate(pam_handle_t* pamh, int flags, int argc, const char** argv) {
try {
rust_init_logging(nullptr); // Ensure logger is initialized
rust_log_event("PAM authentication attempt");
RUST_LOG_INFO("PAM authentication attempt");
const char* user = nullptr;