mirror of
https://github.com/ibm-s390-linux/s390-tools.git
synced 2026-08-05 02:14:52 +00:00
Prepare pv & pv_core crates to be released on crates.io: * Remove any unused API to stay flexible * Remove utils dependency * Move cli, tmpfile and version utilities to local utils crate * Use the new utilities in the pv tools * Rename Secret into Confidential to avoid confusion of Secret (now Confidential) and AddSecret requests. * Move the uvsecret module out of the request module and change the name to secret. * Cleanup dependencies * Precise and correct minimal dependency versions * Inline `Aes256Key::from_digest` The cleanup ensures that the code also compiles with the dependencies resolved to their minimal versions using: $ cargo +nightly -Z minimal-versions update $ cargo build For more information refer to this blog post: https://users.rust-lang.org/t/psa-please-specify-precise-dependency-versions-in-cargo-toml/71277/8 Signed-off-by: Marc Hartmayer <mhartmay@de.ibm.com> Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
50 lines
1.3 KiB
Rust
50 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) {}
|
|
}
|