hyperlight_guest/
logging.rs1use alloc::string::ToString;
18use alloc::vec::Vec;
19
20use hyperlight_common::flatbuffer_wrappers::guest_log_data::GuestLogData;
21use hyperlight_common::flatbuffer_wrappers::guest_log_level::LogLevel;
22use hyperlight_common::outb::OutBAction;
23
24use crate::host_function_call::outb;
25use crate::shared_output_data::push_shared_output_data;
26
27fn write_log_data(
28 log_level: LogLevel,
29 message: &str,
30 source: &str,
31 caller: &str,
32 source_file: &str,
33 line: u32,
34) {
35 let guest_log_data = GuestLogData::new(
36 message.to_string(),
37 source.to_string(),
38 log_level,
39 caller.to_string(),
40 source_file.to_string(),
41 line,
42 );
43
44 let bytes: Vec<u8> = guest_log_data
45 .try_into()
46 .expect("Failed to convert GuestLogData to bytes");
47
48 push_shared_output_data(bytes).expect("Unable to push log data to shared output data");
49}
50
51pub fn log_message(
52 log_level: LogLevel,
53 message: &str,
54 source: &str,
55 caller: &str,
56 source_file: &str,
57 line: u32,
58) {
59 write_log_data(log_level, message, source, caller, source_file, line);
60 outb(OutBAction::Log as u16, &[0]);
61}