mirror of
https://github.com/fluencelabs/marine.git
synced 2024-12-12 14:55:32 +00:00
add level & target to log_utf8_string
This commit is contained in:
parent
f0c382e640
commit
18d435c643
48
Cargo.lock
generated
48
Cargo.lock
generated
@ -707,15 +707,6 @@ dependencies = [
|
|||||||
"serde_json",
|
"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]]
|
[[package]]
|
||||||
name = "fluence"
|
name = "fluence"
|
||||||
version = "0.2.8"
|
version = "0.2.8"
|
||||||
@ -726,6 +717,15 @@ dependencies = [
|
|||||||
"fluence-sdk-main 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
"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]]
|
[[package]]
|
||||||
name = "fluence-app-service"
|
name = "fluence-app-service"
|
||||||
version = "0.1.10"
|
version = "0.1.10"
|
||||||
@ -763,14 +763,6 @@ dependencies = [
|
|||||||
"wasmer-wasi-fl",
|
"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]]
|
[[package]]
|
||||||
name = "fluence-sdk-macro"
|
name = "fluence-sdk-macro"
|
||||||
version = "0.2.8"
|
version = "0.2.8"
|
||||||
@ -781,13 +773,11 @@ dependencies = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "fluence-sdk-main"
|
name = "fluence-sdk-macro"
|
||||||
version = "0.2.8"
|
version = "0.2.8"
|
||||||
source = "git+https://github.com/fluencelabs/rust-sdk#4d6c4f6b862c22ebd8db7244daac0adf3f1bd2fd"
|
source = "git+https://github.com/fluencelabs/rust-sdk#4d6c4f6b862c22ebd8db7244daac0adf3f1bd2fd"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"fluence-sdk-macro 0.2.8 (git+https://github.com/fluencelabs/rust-sdk)",
|
"fluence-sdk-wit 0.2.8 (git+https://github.com/fluencelabs/rust-sdk)",
|
||||||
"log",
|
|
||||||
"serde",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -802,9 +792,20 @@ dependencies = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "fluence-sdk-wit"
|
name = "fluence-sdk-main"
|
||||||
version = "0.2.8"
|
version = "0.2.8"
|
||||||
source = "git+https://github.com/fluencelabs/rust-sdk#4d6c4f6b862c22ebd8db7244daac0adf3f1bd2fd"
|
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 = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
@ -817,8 +818,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "fluence-sdk-wit"
|
name = "fluence-sdk-wit"
|
||||||
version = "0.2.8"
|
version = "0.2.8"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "git+https://github.com/fluencelabs/rust-sdk#4d6c4f6b862c22ebd8db7244daac0adf3f1bd2fd"
|
||||||
checksum = "560baf91197ded38a99a5c94ff366a3dd971ebf33f5d987ecce31d3dedf86d17"
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
|
@ -17,10 +17,38 @@
|
|||||||
use wasmer_core::vm::Ctx;
|
use wasmer_core::vm::Ctx;
|
||||||
use wasmer_core::memory::ptr::{Array, WasmPtr};
|
use wasmer_core::memory::ptr::{Array, WasmPtr};
|
||||||
|
|
||||||
pub(super) fn log_utf8_string(ctx: &mut Ctx, offset: i32, size: i32) {
|
pub(super) fn log_utf8_string(
|
||||||
let wasm_ptr = WasmPtr::<u8, Array>::new(offset as _);
|
ctx: &mut Ctx,
|
||||||
match wasm_ptr.get_utf8_string(ctx.memory(0), size as _) {
|
level: i32,
|
||||||
Some(msg) => log::info!("{}", msg),
|
target_offset: i32,
|
||||||
None => log::warn!("logger: incorrect UTF8 string's been supplied to logger"),
|
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::<u8, Array>::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(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user