mirror of
https://github.com/fluencelabs/marine.git
synced 2024-12-12 14:55:32 +00:00
use module::target as module_path in log
This commit is contained in:
parent
18d435c643
commit
7f89ba5054
@ -87,8 +87,11 @@ impl FluenceFaaS {
|
|||||||
))
|
))
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let fce_module_config =
|
let fce_module_config = crate::misc::make_fce_config(
|
||||||
crate::misc::make_fce_config(Some(module_config), call_parameters.clone())?;
|
module_name.clone(),
|
||||||
|
Some(module_config),
|
||||||
|
call_parameters.clone(),
|
||||||
|
)?;
|
||||||
fce.load_module(module_name, &module_bytes, fce_module_config)?;
|
fce.load_module(module_name, &module_bytes, fce_module_config)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -233,8 +236,10 @@ impl FluenceFaaS {
|
|||||||
FaaSError: From<C::Error>,
|
FaaSError: From<C::Error>,
|
||||||
{
|
{
|
||||||
let config = config.map(|c| c.try_into()).transpose()?;
|
let config = config.map(|c| c.try_into()).transpose()?;
|
||||||
|
let name = name.into();
|
||||||
|
|
||||||
let fce_module_config = crate::misc::make_fce_config(config, self.call_parameters.clone())?;
|
let fce_module_config =
|
||||||
|
crate::misc::make_fce_config(name.clone(), config, self.call_parameters.clone())?;
|
||||||
self.fce
|
self.fce
|
||||||
.load_module(name, &wasm_bytes, fce_module_config)
|
.load_module(name, &wasm_bytes, fce_module_config)
|
||||||
.map_err(Into::into)
|
.map_err(Into::into)
|
||||||
|
@ -17,7 +17,24 @@
|
|||||||
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_closure(
|
||||||
|
module: String,
|
||||||
|
) -> impl for<'a> Fn(&'a mut Ctx, i32, i32, i32, i32, i32) {
|
||||||
|
move |ctx, level, target_offset, target_size, msg_offset, msg_size| {
|
||||||
|
log_utf8_string(
|
||||||
|
&module,
|
||||||
|
ctx,
|
||||||
|
level,
|
||||||
|
target_offset,
|
||||||
|
target_size,
|
||||||
|
msg_offset,
|
||||||
|
msg_size,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub(super) fn log_utf8_string(
|
pub(super) fn log_utf8_string(
|
||||||
|
module: &str,
|
||||||
ctx: &mut Ctx,
|
ctx: &mut Ctx,
|
||||||
level: i32,
|
level: i32,
|
||||||
target_offset: i32,
|
target_offset: i32,
|
||||||
@ -28,10 +45,19 @@ pub(super) fn log_utf8_string(
|
|||||||
let level = level_from_i32(level);
|
let level = level_from_i32(level);
|
||||||
let target = read_string(ctx, target_offset, target_size);
|
let target = read_string(ctx, target_offset, target_size);
|
||||||
let msg = read_string(ctx, msg_offset, msg_size);
|
let msg = read_string(ctx, msg_offset, msg_size);
|
||||||
match (msg, target) {
|
|
||||||
(Some(msg), Some(target)) => log::log!(target: target, level, "{}", msg),
|
let module_path = target.map(|t| format!("{}::{}", module, t));
|
||||||
(Some(msg), None) => log::log!(level, "{}", msg),
|
let module_path = module_path.as_deref().unwrap_or(module);
|
||||||
(None, _) => log::warn!("logger: incorrect UTF8 string's been supplied to logger"),
|
|
||||||
|
match msg {
|
||||||
|
Some(msg) => log::logger().log(
|
||||||
|
&log::Record::builder()
|
||||||
|
.args(format_args!("{}", msg))
|
||||||
|
.level(level)
|
||||||
|
.module_path(module_path.into())
|
||||||
|
.build(),
|
||||||
|
),
|
||||||
|
None => log::warn!("logger: incorrect UTF8 string's been supplied to logger"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,4 +24,4 @@ pub(crate) use modules_load_strategy::ModulesLoadStrategy;
|
|||||||
pub(crate) use utils::create_host_import;
|
pub(crate) use utils::create_host_import;
|
||||||
pub(crate) use utils::make_fce_config;
|
pub(crate) use utils::make_fce_config;
|
||||||
|
|
||||||
pub(self) use log_utf8_string_impl::log_utf8_string;
|
pub(self) use log_utf8_string_impl::log_utf8_string_closure;
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
use crate::config::FaaSModuleConfig;
|
use crate::config::FaaSModuleConfig;
|
||||||
use super::log_utf8_string;
|
use super::log_utf8_string_closure;
|
||||||
|
|
||||||
use fce::FCEModuleConfig;
|
use fce::FCEModuleConfig;
|
||||||
use fce::HostImportDescriptor;
|
use fce::HostImportDescriptor;
|
||||||
@ -77,6 +77,7 @@ fn create_call_parameters_import(
|
|||||||
|
|
||||||
/// Make FCE config from provided FaaS config.
|
/// Make FCE config from provided FaaS config.
|
||||||
pub(crate) fn make_fce_config(
|
pub(crate) fn make_fce_config(
|
||||||
|
module_name: String,
|
||||||
faas_module_config: Option<FaaSModuleConfig>,
|
faas_module_config: Option<FaaSModuleConfig>,
|
||||||
call_parameters: Rc<RefCell<fluence_sdk_main::CallParameters>>,
|
call_parameters: Rc<RefCell<fluence_sdk_main::CallParameters>>,
|
||||||
) -> crate::Result<FCEModuleConfig> {
|
) -> crate::Result<FCEModuleConfig> {
|
||||||
@ -119,7 +120,10 @@ pub(crate) fn make_fce_config(
|
|||||||
|
|
||||||
let mut namespace = Namespace::new();
|
let mut namespace = Namespace::new();
|
||||||
if faas_module_config.logger_enabled {
|
if faas_module_config.logger_enabled {
|
||||||
namespace.insert("log_utf8_string", func!(log_utf8_string));
|
namespace.insert(
|
||||||
|
"log_utf8_string",
|
||||||
|
func!(log_utf8_string_closure(module_name)),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut raw_host_imports = ImportObject::new();
|
let mut raw_host_imports = ImportObject::new();
|
||||||
|
Loading…
Reference in New Issue
Block a user