diff --git a/Cargo.lock b/Cargo.lock index 30a55fdf..eda26143 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -707,15 +707,6 @@ dependencies = [ "serde_json", ] -[[package]] -name = "fluence" -version = "0.2.8" -source = "git+https://github.com/fluencelabs/rust-sdk#4d6c4f6b862c22ebd8db7244daac0adf3f1bd2fd" -dependencies = [ - "fluence-sdk-macro 0.2.8 (git+https://github.com/fluencelabs/rust-sdk)", - "fluence-sdk-main 0.2.8 (git+https://github.com/fluencelabs/rust-sdk)", -] - [[package]] name = "fluence" version = "0.2.8" @@ -726,6 +717,15 @@ dependencies = [ "fluence-sdk-main 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "fluence" +version = "0.2.8" +source = "git+https://github.com/fluencelabs/rust-sdk#4d6c4f6b862c22ebd8db7244daac0adf3f1bd2fd" +dependencies = [ + "fluence-sdk-macro 0.2.8 (git+https://github.com/fluencelabs/rust-sdk)", + "fluence-sdk-main 0.2.8 (git+https://github.com/fluencelabs/rust-sdk)", +] + [[package]] name = "fluence-app-service" version = "0.1.10" @@ -763,14 +763,6 @@ dependencies = [ "wasmer-wasi-fl", ] -[[package]] -name = "fluence-sdk-macro" -version = "0.2.8" -source = "git+https://github.com/fluencelabs/rust-sdk#4d6c4f6b862c22ebd8db7244daac0adf3f1bd2fd" -dependencies = [ - "fluence-sdk-wit 0.2.8 (git+https://github.com/fluencelabs/rust-sdk)", -] - [[package]] name = "fluence-sdk-macro" version = "0.2.8" @@ -781,13 +773,11 @@ dependencies = [ ] [[package]] -name = "fluence-sdk-main" +name = "fluence-sdk-macro" version = "0.2.8" source = "git+https://github.com/fluencelabs/rust-sdk#4d6c4f6b862c22ebd8db7244daac0adf3f1bd2fd" dependencies = [ - "fluence-sdk-macro 0.2.8 (git+https://github.com/fluencelabs/rust-sdk)", - "log", - "serde", + "fluence-sdk-wit 0.2.8 (git+https://github.com/fluencelabs/rust-sdk)", ] [[package]] @@ -802,9 +792,20 @@ dependencies = [ ] [[package]] -name = "fluence-sdk-wit" +name = "fluence-sdk-main" version = "0.2.8" source = "git+https://github.com/fluencelabs/rust-sdk#4d6c4f6b862c22ebd8db7244daac0adf3f1bd2fd" +dependencies = [ + "fluence-sdk-macro 0.2.8 (git+https://github.com/fluencelabs/rust-sdk)", + "log", + "serde", +] + +[[package]] +name = "fluence-sdk-wit" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "560baf91197ded38a99a5c94ff366a3dd971ebf33f5d987ecce31d3dedf86d17" dependencies = [ "proc-macro2", "quote", @@ -817,8 +818,7 @@ dependencies = [ [[package]] name = "fluence-sdk-wit" version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "560baf91197ded38a99a5c94ff366a3dd971ebf33f5d987ecce31d3dedf86d17" +source = "git+https://github.com/fluencelabs/rust-sdk#4d6c4f6b862c22ebd8db7244daac0adf3f1bd2fd" dependencies = [ "proc-macro2", "quote", diff --git a/fluence-faas/src/misc/log_utf8_string_impl.rs b/fluence-faas/src/misc/log_utf8_string_impl.rs index 6814bbb6..9484ce41 100644 --- a/fluence-faas/src/misc/log_utf8_string_impl.rs +++ b/fluence-faas/src/misc/log_utf8_string_impl.rs @@ -17,10 +17,38 @@ use wasmer_core::vm::Ctx; use wasmer_core::memory::ptr::{Array, WasmPtr}; -pub(super) fn log_utf8_string(ctx: &mut Ctx, offset: i32, size: i32) { - let wasm_ptr = WasmPtr::::new(offset as _); - match wasm_ptr.get_utf8_string(ctx.memory(0), size as _) { - Some(msg) => log::info!("{}", msg), - None => log::warn!("logger: incorrect UTF8 string's been supplied to logger"), +pub(super) fn log_utf8_string( + ctx: &mut Ctx, + level: i32, + target_offset: i32, + target_size: i32, + msg_offset: i32, + msg_size: i32, +) { + let level = level_from_i32(level); + let target = read_string(ctx, target_offset, target_size); + let msg = read_string(ctx, msg_offset, msg_size); + match (msg, target) { + (Some(msg), Some(target)) => log::log!(target: target, level, "{}", msg), + (Some(msg), None) => log::log!(level, "{}", msg), + (None, _) => log::warn!("logger: incorrect UTF8 string's been supplied to logger"), + } +} + +#[inline] +fn read_string(ctx: &Ctx, offset: i32, size: i32) -> Option<&str> { + let wasm_ptr = WasmPtr::::new(offset as _); + wasm_ptr.get_utf8_string(ctx.memory(0), size as _) +} + +#[inline] +fn level_from_i32(level: i32) -> log::Level { + match level { + 1 => log::Level::Error, + 2 => log::Level::Warn, + 3 => log::Level::Info, + 4 => log::Level::Debug, + 5 => log::Level::Trace, + _ => log::Level::max(), } }