the log wrapper in C/C++ accepts formats
This commit is contained in:
18
pam-module/examples/logging_example.c
Normal file
18
pam-module/examples/logging_example.c
Normal file
@@ -0,0 +1,18 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// C example demonstrating printf-style Rust logging wrapper
|
||||
|
||||
#include "../include/rust_backend_ffi.h"
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
(void)argc; (void)argv;
|
||||
// Ensure logger is initialized (nullptr -> default path)
|
||||
rust_init_logging(NULL);
|
||||
|
||||
const char* user = "alice";
|
||||
int result = 0; // pretend success
|
||||
|
||||
RUST_LOGF_INFO("C example: user=%s authenticated=%d", user, result);
|
||||
RUST_LOGF_DEBUG("C example: debug details: x=%d y=%d", 10, 20);
|
||||
|
||||
return 0;
|
||||
}
|
||||
17
pam-module/examples/logging_example.cpp
Normal file
17
pam-module/examples/logging_example.cpp
Normal file
@@ -0,0 +1,17 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// C++ example demonstrating stream-style Rust logging wrapper
|
||||
|
||||
#include "../include/rust_backend_ffi.h"
|
||||
#include <string>
|
||||
|
||||
int main() {
|
||||
rust_init_logging(nullptr);
|
||||
|
||||
std::string user = "bob";
|
||||
bool ok = true;
|
||||
|
||||
RUST_COUT() << "C++ example: user=" << user << " authenticated=" << (ok?"yes":"no") << std::flush;
|
||||
RUST_CERR() << "C++ example: an error message for user=" << user << std::flush;
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user