Skip to content

Commit

Permalink
Replace OPENVAS_LIBSSH_DEBUG with the tracing Level
Browse files Browse the repository at this point in the history
  • Loading branch information
Tehforsch committed Nov 26, 2024
1 parent 3b4c917 commit 7322ddd
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions rust/src/nasl/builtin/ssh/libssh/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ use libssh_rs::{LogLevel, SshOption};
use russh::cipher;
use russh_keys::key;
use tokio::sync::{Mutex, MutexGuard};
use tracing::debug;
use tracing::{debug, Level};
use tracing_subscriber::filter::LevelFilter;

use super::error::Result;
use super::Ssh;
Expand All @@ -25,17 +26,28 @@ pub use session::SshSession;
pub type SessionId = i32;
pub type Socket = std::os::raw::c_int;

// Currently, our tests are executed with a TRACE filter. In a normal
// run, this translates to a `LogLevel` of `Functions`, which is very
// verbose.
//
// Since libssh prints its logs to stderr, its output is not filtered
// out by `cargo test`, resulting in tons of annoying output, even if
// the test passes. To make sure this doesn't happen, we set
// `NoLogging` in all test runs.
#[cfg(test)]
pub fn get_log_level() -> LogLevel {
LogLevel::NoLogging
}

#[cfg(not(test))]
pub fn get_log_level() -> LogLevel {
let verbose = std::env::var("OPENVAS_LIBSSH_DEBUG")
.map(|x| x.parse::<i32>().unwrap_or_default())
.unwrap_or(0);

match verbose {
0 => LogLevel::NoLogging,
1 => LogLevel::Warning,
2 => LogLevel::Protocol,
3 => LogLevel::Packet,
_ => LogLevel::Functions,
let log_level = LevelFilter::current().into_level();
match log_level {
None => LogLevel::NoLogging,
Some(Level::ERROR) | Some(Level::WARN) => LogLevel::Warning,
Some(Level::INFO) => LogLevel::Protocol,
Some(Level::DEBUG) => LogLevel::Packet,
Some(Level::TRACE) => LogLevel::Functions,
}
}

Expand Down

0 comments on commit 7322ddd

Please sign in to comment.