mirror of
https://github.com/ibm-s390-linux/s390-tools.git
synced 2026-08-05 02:14:52 +00:00
Add a `pv` crate that bundles useful functions and structs for creating requests like `Attestation`, `Add Secret`, or even `Boot` a.k.a. Secure Execution Image. Note pv includes a subcrate `openssl_extensions` that (temporarily) bundles some needed `openssl-rust` functionalities that are not upstream yet. The plan is to remove these, when they become upstream. The pv crate has multiple features: * request - code to generate requests * uvsecret - code to access the UV-secret api with request enabled also generating requests is possible Signed-off-by: Steffen Eiden <seiden@linux.ibm.com> Acked-by: Jan Höppner <hoeppner@linux.ibm.com> Acked-by: Marc Hartmayer <mhartmay@linux.ibm.com> Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
49 lines
1.3 KiB
Rust
49 lines
1.3 KiB
Rust
// SPDX-License-Identifier: MIT
|
|
//
|
|
// Copyright IBM Corp. 2023
|
|
|
|
use log::{self, Level, LevelFilter, Log, Metadata, Record};
|
|
|
|
/// A simple Logger that prints to stderr if the verbosity level is high enough.
|
|
/// Prints log-level for Debug+Trace
|
|
#[derive(Clone, Default, Debug)]
|
|
pub struct PvLogger;
|
|
|
|
fn to_level(verbosity: u8) -> LevelFilter {
|
|
match verbosity {
|
|
// Error and Warn on by default
|
|
0 => LevelFilter::Warn,
|
|
1 => LevelFilter::Info,
|
|
2 => LevelFilter::Debug,
|
|
_ => LevelFilter::Trace,
|
|
}
|
|
}
|
|
|
|
impl PvLogger {
|
|
/// Set self as the logger for this application.
|
|
///
|
|
/// # Errors
|
|
///
|
|
/// An error is returned if a logger has already been set.
|
|
pub fn start(&'static self, verbosity: u8) -> Result<(), log::SetLoggerError> {
|
|
log::set_logger(self).map(|()| log::set_max_level(to_level(verbosity)))
|
|
}
|
|
}
|
|
|
|
impl Log for PvLogger {
|
|
fn enabled(&self, _metadata: &Metadata) -> bool {
|
|
true
|
|
}
|
|
|
|
fn log(&self, record: &Record) {
|
|
if self.enabled(record.metadata()) {
|
|
if record.level() > Level::Info {
|
|
eprintln!("{}: {}", record.level(), record.args());
|
|
} else {
|
|
eprintln!("{}", record.args());
|
|
}
|
|
}
|
|
}
|
|
fn flush(&self) {}
|
|
}
|