Skip to content

Commit a43a330

Browse files
Copilotjsturtevant
andcommitted
Fix compilation errors after log to tracing migration
Co-authored-by: jsturtevant <648372+jsturtevant@users.noreply.github.com>
1 parent cb4f261 commit a43a330

10 files changed

Lines changed: 73 additions & 31 deletions

File tree

Cargo.lock

Lines changed: 2 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/hyperlight_common/src/flatbuffer_wrappers/guest_log_level.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,22 @@ limitations under the License.
1515
*/
1616

1717
use anyhow::{Error, Result, bail};
18-
use log::Level;
1918
#[cfg(feature = "tracing")]
2019
use tracing::{Span, instrument};
2120

2221
use crate::flatbuffers::hyperlight::generated::LogLevel as FbLogLevel;
2322

23+
// Define a minimal Level enum for conversions.
24+
// This mirrors log::Level/tracing::Level but is no_std compatible.
25+
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
26+
pub enum Level {
27+
Trace,
28+
Debug,
29+
Info,
30+
Warn,
31+
Error,
32+
}
33+
2434
#[repr(u8)]
2535
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
2636
pub enum LogLevel {

src/hyperlight_host/src/hypervisor/hyperlight_vm.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,23 @@ use tracing::{Span, instrument};
3030
#[cfg(feature = "trace_guest")]
3131
use tracing_opentelemetry::OpenTelemetrySpanExt;
3232

33+
// Helper function to convert LevelFilter to u64 for guest
34+
fn level_filter_to_u64(filter: LevelFilter) -> u64 {
35+
// Map LevelFilter to numeric values matching the guest expectations
36+
// OFF = 5, ERROR = 4, WARN = 3, INFO = 2, DEBUG = 1, TRACE = 0
37+
if filter >= LevelFilter::ERROR {
38+
4
39+
} else if filter >= LevelFilter::WARN {
40+
3
41+
} else if filter >= LevelFilter::INFO {
42+
2
43+
} else if filter >= LevelFilter::DEBUG {
44+
1
45+
} else {
46+
0
47+
}
48+
}
49+
3350
#[cfg(gdb)]
3451
use super::gdb::{DebugCommChannel, DebugMsg, DebugResponse, DebuggableVm, VcpuStopReason, arch};
3552
use super::regs::{CommonFpu, CommonRegisters};
@@ -229,7 +246,7 @@ impl HyperlightVm {
229246
self.page_size = page_size as usize;
230247

231248
let guest_max_log_level: u64 = match guest_max_log_level {
232-
Some(level) => level as u64,
249+
Some(level) => level_filter_to_u64(level),
233250
None => get_max_log_level().into(),
234251
};
235252

src/hyperlight_host/src/hypervisor/hyperv_linux.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub(crate) fn is_hypervisor_present() -> bool {
4444
match Mshv::new() {
4545
Ok(_) => true,
4646
Err(_) => {
47-
log::info!("MSHV is not available on this system");
47+
tracing::info!("MSHV is not available on this system");
4848
false
4949
}
5050
}

src/hyperlight_host/src/hypervisor/kvm.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,16 @@ pub(crate) fn is_hypervisor_present() -> bool {
3737
match api_version {
3838
version if version == 12 && kvm.check_extension(UserMemory) => true,
3939
12 => {
40-
log::info!("KVM does not have KVM_CAP_USER_MEMORY capability");
40+
tracing::info!("KVM does not have KVM_CAP_USER_MEMORY capability");
4141
false
4242
}
4343
version => {
44-
log::info!("KVM GET_API_VERSION returned {}, expected 12", version);
44+
tracing::info!("KVM GET_API_VERSION returned {}, expected 12", version);
4545
false
4646
}
4747
}
4848
} else {
49-
log::info!("KVM is not available on this system");
49+
tracing::info!("KVM is not available on this system");
5050
false
5151
}
5252
}
@@ -190,7 +190,7 @@ impl DebuggableVm for KvmVm {
190190
fn set_debug(&mut self, enable: bool) -> Result<()> {
191191
use kvm_bindings::{KVM_GUESTDBG_ENABLE, KVM_GUESTDBG_USE_HW_BP, KVM_GUESTDBG_USE_SW_BP};
192192

193-
log::info!("Setting debug to {}", enable);
193+
tracing::info!("Setting debug to {}", enable);
194194
if enable {
195195
self.debug_regs.control |=
196196
KVM_GUESTDBG_ENABLE | KVM_GUESTDBG_USE_HW_BP | KVM_GUESTDBG_USE_SW_BP;
@@ -205,7 +205,7 @@ impl DebuggableVm for KvmVm {
205205
fn set_single_step(&mut self, enable: bool) -> Result<()> {
206206
use kvm_bindings::KVM_GUESTDBG_SINGLESTEP;
207207

208-
log::info!("Setting single step to {}", enable);
208+
tracing::info!("Setting single step to {}", enable);
209209
if enable {
210210
self.debug_regs.control |= KVM_GUESTDBG_SINGLESTEP;
211211
} else {

src/hyperlight_host/src/hypervisor/mod.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
use tracing::level_filters::LevelFilter;
1817

1918
use crate::Result;
2019
use crate::hypervisor::regs::{CommonFpu, CommonRegisters, CommonSpecialRegisters};
@@ -53,7 +52,6 @@ pub(crate) mod crashdump;
5352
pub(crate) mod hyperlight_vm;
5453

5554
use std::fmt::Debug;
56-
use std::str::FromStr;
5755
#[cfg(any(kvm, mshv3))]
5856
use std::sync::atomic::{AtomicBool, AtomicU8, AtomicU64, Ordering};
5957
#[cfg(target_os = "windows")]
@@ -169,10 +167,19 @@ fn get_max_log_level() -> u32 {
169167
val.split(',').find(|s| !s.contains("=")).unwrap_or("")
170168
};
171169

172-
log::info!("Determined guest log level: {}", level);
170+
tracing::info!("Determined guest log level: {}", level);
173171
// Convert the log level string to a LevelFilter
174172
// If no value is found, default to Error
175-
LevelFilter::from_str(level).unwrap_or(LevelFilter::Error) as u32
173+
// tracing::LevelFilter doesn't implement FromStr or as u32, so we need to convert via string matching
174+
let level_filter = match level.to_lowercase().as_str() {
175+
"trace" => 0u32,
176+
"debug" => 1u32,
177+
"info" => 2u32,
178+
"warn" => 3u32,
179+
"error" => 4u32,
180+
_ => 4u32, // Default to Error
181+
};
182+
level_filter
176183
}
177184

178185
/// A trait for platform-specific interrupt handle implementation details
@@ -299,7 +306,7 @@ impl LinuxInterruptHandle {
299306
break;
300307
}
301308

302-
log::info!("Sending signal to kill vcpu thread...");
309+
tracing::info!("Sending signal to kill vcpu thread...");
303310
sent_signal = true;
304311
// Acquire ordering to synchronize with the Release store in set_tid()
305312
// This ensures we see the correct tid value for the currently running vcpu

src/hyperlight_host/src/lib.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,33 +109,33 @@ macro_rules! log_then_return {
109109
None => std::format!($msg),
110110
};
111111
let __err = $crate::HyperlightError::Error(__err_msg);
112-
log::error!("{}", __err);
112+
tracing::error!("{}", __err);
113113
return Err(__err);
114114
}};
115115
($err:expr $(,)?) => {
116-
log::error!("{}", $err);
116+
tracing::error!("{}", $err);
117117
return Err($err);
118118
};
119119
($err:stmt $(,)?) => {
120-
log::error!("{}", $err);
120+
tracing::error!("{}", $err);
121121
return Err($err);
122122
};
123123
($fmtstr:expr, $($arg:tt)*) => {
124124
let __err_msg = std::format!($fmtstr, $($arg)*);
125125
let __err = $crate::error::HyperlightError::Error(__err_msg);
126-
log::error!("{}", __err);
126+
tracing::error!("{}", __err);
127127
return Err(__err);
128128
};
129129
}
130130

131-
/// Same as log::debug!, but will additionally print to stdout if the print_debug feature is enabled
131+
/// Same as tracing::debug!, but will additionally print to stdout if the print_debug feature is enabled
132132
#[macro_export]
133133
macro_rules! debug {
134134
($($arg:tt)+) =>
135135
{
136136
#[cfg(print_debug)]
137137
println!($($arg)+);
138-
log::debug!($($arg)+);
138+
tracing::debug!($($arg)+);
139139
}
140140
}
141141

src/hyperlight_host/src/sandbox/outb.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,24 @@ use std::sync::{Arc, Mutex};
1919
use hyperlight_common::flatbuffer_wrappers::function_types::{FunctionCallResult, ParameterValue};
2020
use hyperlight_common::flatbuffer_wrappers::guest_error::{ErrorCode, GuestError};
2121
use hyperlight_common::flatbuffer_wrappers::guest_log_data::GuestLogData;
22+
use hyperlight_common::flatbuffer_wrappers::guest_log_level::Level as GuestLevel;
2223
use hyperlight_common::outb::{Exception, OutBAction};
2324
use tracing::{Span, instrument};
24-
use tracing_log::{LogTracer, format_trace, log};
25+
use tracing_log::{format_trace, log};
2526

2627
use log::{Level, Record};
2728

29+
// Convert from guest Level to log Level
30+
fn guest_level_to_log_level(guest_level: GuestLevel) -> Level {
31+
match guest_level {
32+
GuestLevel::Trace => Level::Trace,
33+
GuestLevel::Debug => Level::Debug,
34+
GuestLevel::Info => Level::Info,
35+
GuestLevel::Warn => Level::Warn,
36+
GuestLevel::Error => Level::Error,
37+
}
38+
}
39+
2840
use super::host_funcs::FunctionRegistry;
2941
#[cfg(feature = "mem_profile")]
3042
use crate::hypervisor::regs::CommonRegisters;
@@ -45,7 +57,7 @@ pub(super) fn outb_log(mgr: &mut SandboxMemoryManager<HostSharedMemory>) -> Resu
4557

4658
let log_data: GuestLogData = mgr.read_guest_log_data()?;
4759

48-
let record_level: Level = (&log_data.level).into();
60+
let record_level: Level = guest_level_to_log_level((&log_data.level).into());
4961

5062
// Work out if we need to log or trace
5163
// this API is marked as follows but it is the easiest way to work out if we should trace or log

src/hyperlight_testing/src/logger.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,14 @@ impl Logger {
4646
pub fn initialize_test_logger() {
4747
INITLOGGER.call_once(|| {
4848
set_logger(&LOGGER).unwrap();
49-
set_max_level(log::LevelFilter::Trace);
49+
set_max_level(LevelFilter::Trace);
5050
});
5151
}
5252

5353
pub fn initialize_log_tracer() {
5454
INITLOGGER.call_once(|| {
5555
set_logger(&*LOG_TRACER).unwrap();
56-
set_max_level(log::LevelFilter::Trace);
56+
set_max_level(LevelFilter::Trace);
5757
});
5858
}
5959

src/hyperlight_testing/src/simplelogger.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ impl SimpleLogger {
4444
pub fn initialize_test_logger() {
4545
INITLOGGER.call_once(|| {
4646
set_logger(&LOGGER).unwrap();
47-
set_max_level(log::LevelFilter::Trace);
47+
set_max_level(tracing_log::log::LevelFilter::Trace);
4848
});
4949
}
5050

@@ -86,7 +86,7 @@ impl Log for SimpleLogger {
8686
if metadata.target() == "hyperlight_guest" {
8787
NUMBER_OF_ENABLED_CALLS += 1;
8888
}
89-
metadata.target() == "hyperlight_guest" && metadata.level() <= log::max_level()
89+
metadata.target() == "hyperlight_guest" && metadata.level() <= tracing_log::log::max_level()
9090
}
9191
}
9292
fn log(&self, record: &Record) {

0 commit comments

Comments
 (0)