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;
22
23use crate::host_function_call::{outb, OutBAction};
24use crate::shared_output_data::push_shared_output_data;
25
26fn write_log_data(
27 log_level: LogLevel,
28 message: &str,
29 source: &str,
30 caller: &str,
31 source_file: &str,
32 line: u32,
33) {
34 let guest_log_data = GuestLogData::new(
35 message.to_string(),
36 source.to_string(),
37 log_level,
38 caller.to_string(),
39 source_file.to_string(),
40 line,
41 );
42
43 let bytes: Vec<u8> = guest_log_data
44 .try_into()
45 .expect("Failed to convert GuestLogData to bytes");
46
47 push_shared_output_data(bytes).expect("Unable to push log data to shared output data");
48}
49
50pub fn log_message(
51 log_level: LogLevel,
52 message: &str,
53 source: &str,
54 caller: &str,
55 source_file: &str,
56 line: u32,
57) {
58 write_log_data(log_level, message, source, caller, source_file, line);
59 outb(OutBAction::Log as u16, 0);
60}