mirror of
https://github.com/fluencelabs/marine-rs-sdk
synced 2025-03-15 14:30:48 +00:00
Change 'target' from i64 to i32 in log_utf8_string (#13)
This commit is contained in:
parent
8a2570bbc6
commit
31dc0a30df
@ -62,7 +62,7 @@ pub(crate) fn log<S: AsRef<str>>(msg: S) {
|
|||||||
#[cfg(feature = "debug")]
|
#[cfg(feature = "debug")]
|
||||||
{
|
{
|
||||||
let level = log::Level::Info as i32;
|
let level = log::Level::Info as i32;
|
||||||
let target = 0i64;
|
let target = 0i32;
|
||||||
let msg = msg.as_ref();
|
let msg = msg.as_ref();
|
||||||
logger::log_utf8_string(level, target, msg.as_ptr() as i32, msg.len() as i32);
|
logger::log_utf8_string(level, target, msg.as_ptr() as i32, msg.len() as i32);
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,11 @@ pub const WASM_LOG_ENV_NAME: &'static str = "WASM_LOG";
|
|||||||
/// If WASM_LOG_ENV isn't set, then this level will be used as the default.
|
/// If WASM_LOG_ENV isn't set, then this level will be used as the default.
|
||||||
const WASM_DEFAULT_LOG_LEVEL: LogLevel = LogLevel::Info;
|
const WASM_DEFAULT_LOG_LEVEL: LogLevel = LogLevel::Info;
|
||||||
|
|
||||||
pub type TargetMap = std::collections::HashMap<&'static str, i64>;
|
/// Mapping from logging namespace string to its bitmask.
|
||||||
|
/// TODO: use i64 for bitmask when wasmpack/bindgen issue with i64 is fixed.
|
||||||
|
/// Currently, i64 doesn't work on some versions of V8 because log_utf8_string function
|
||||||
|
/// isn't marked as #[wasm_bindgen]. In result, TS/JS code throws 'TypeError' on every log.
|
||||||
|
pub type TargetMap = std::collections::HashMap<&'static str, i32>;
|
||||||
|
|
||||||
/// The Wasm Logger.
|
/// The Wasm Logger.
|
||||||
///
|
///
|
||||||
@ -165,12 +169,12 @@ impl log::Log for WasmLogger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_arch = "wasm32")]
|
#[cfg(target_arch = "wasm32")]
|
||||||
pub fn log_utf8_string(level: i32, target: i64, msg_ptr: i32, msg_size: i32) {
|
pub fn log_utf8_string(level: i32, target: i32, msg_ptr: i32, msg_size: i32) {
|
||||||
unsafe { log_utf8_string_impl(level, target, msg_ptr, msg_size) };
|
unsafe { log_utf8_string_impl(level, target, msg_ptr, msg_size) };
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
pub fn log_utf8_string(level: i32, target: i64, msg_ptr: i32, msg_size: i32) {
|
pub fn log_utf8_string(level: i32, target: i32, msg_ptr: i32, msg_size: i32) {
|
||||||
use std::str::from_utf8_unchecked;
|
use std::str::from_utf8_unchecked;
|
||||||
use core::slice::from_raw_parts;
|
use core::slice::from_raw_parts;
|
||||||
|
|
||||||
@ -179,13 +183,14 @@ pub fn log_utf8_string(level: i32, target: i64, msg_ptr: i32, msg_size: i32) {
|
|||||||
println!("[{}] {} {}", level, target, msg);
|
println!("[{}] {} {}", level, target, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// TODO: mark `log_utf8_string_impl` as #[wasm_bindgen], so it is polyfilled by bindgen
|
||||||
/// log_utf8_string should be provided directly by a host.
|
/// log_utf8_string should be provided directly by a host.
|
||||||
#[cfg(target_arch = "wasm32")]
|
#[cfg(target_arch = "wasm32")]
|
||||||
#[link(wasm_import_module = "host")]
|
#[link(wasm_import_module = "host")]
|
||||||
extern "C" {
|
extern "C" {
|
||||||
// Writes a byte string of size bytes that starts from ptr to a logger
|
// Writes a byte string of size bytes that starts from ptr to a logger
|
||||||
#[link_name = "log_utf8_string"]
|
#[link_name = "log_utf8_string"]
|
||||||
fn log_utf8_string_impl(level: i32, target: i64, msg_ptr: i32, msg_size: i32);
|
fn log_utf8_string_impl(level: i32, target: i32, msg_ptr: i32, msg_size: i32);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user