mirror of
https://github.com/fluencelabs/marine.git
synced 2024-12-12 14:55:32 +00:00
refactor logger
This commit is contained in:
parent
1f2355e6ef
commit
de3d51ef8f
108
Cargo.lock
generated
108
Cargo.lock
generated
@ -35,9 +35,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "anyhow"
|
name = "anyhow"
|
||||||
version = "1.0.34"
|
version = "1.0.35"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "bf8dcb5b4bbaa28653b647d8c77bd4ed40183b48882e130c1f1ffb73de069fd7"
|
checksum = "2c0df63cb2955042487fad3aefd2c6e3ae7389ac5dc1beb28921de0b69f779d4"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "aquamarine-vm"
|
name = "aquamarine-vm"
|
||||||
@ -189,9 +189,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cc"
|
name = "cc"
|
||||||
version = "1.0.65"
|
version = "1.0.66"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "95752358c8f7552394baf48cd82695b345628ad3f170d607de3ca03b8dacca15"
|
checksum = "4c0496836a84f8d0495758516b8621a622beb77c0fed418570e50764093ced48"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cfg-if"
|
name = "cfg-if"
|
||||||
@ -690,7 +690,7 @@ name = "fce-wit-generator"
|
|||||||
version = "0.1.11"
|
version = "0.1.11"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"fce-wit-parser",
|
"fce-wit-parser",
|
||||||
"fluence-sdk-wit 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
"fluence-sdk-wit 0.2.9",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
@ -737,17 +737,26 @@ version = "0.2.9"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "1099731bb64286758969fb8dd6f903d1e4a7398d8e63bdec1be6387576f4d8ab"
|
checksum = "1099731bb64286758969fb8dd6f903d1e4a7398d8e63bdec1be6387576f4d8ab"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"fluence-sdk-macro 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
"fluence-sdk-macro 0.2.9",
|
||||||
"fluence-sdk-main 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
"fluence-sdk-main 0.2.9",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "fluence"
|
name = "fluence"
|
||||||
version = "0.2.9"
|
version = "0.2.9"
|
||||||
source = "git+https://github.com/fluencelabs/rust-sdk#fd9672636e8d7a91275e5e0b8b88a34494336e5a"
|
source = "git+https://github.com/fluencelabs/rust-sdk?branch=logger_env#be250f9c1f75309b1d96d78dbfd380a8fae7fd3f"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"fluence-sdk-macro 0.2.9 (git+https://github.com/fluencelabs/rust-sdk)",
|
"fluence-sdk-macro 0.2.10 (git+https://github.com/fluencelabs/rust-sdk?branch=logger_env)",
|
||||||
"fluence-sdk-main 0.2.9 (git+https://github.com/fluencelabs/rust-sdk)",
|
"fluence-sdk-main 0.2.10 (git+https://github.com/fluencelabs/rust-sdk?branch=logger_env)",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "fluence"
|
||||||
|
version = "0.2.9"
|
||||||
|
source = "git+https://github.com/fluencelabs/rust-sdk#ebf3e63aef8d4aafda41180eeb299c4138628174"
|
||||||
|
dependencies = [
|
||||||
|
"fluence-sdk-macro 0.2.10 (git+https://github.com/fluencelabs/rust-sdk)",
|
||||||
|
"fluence-sdk-main 0.2.10 (git+https://github.com/fluencelabs/rust-sdk)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -772,7 +781,7 @@ dependencies = [
|
|||||||
"env_logger 0.7.1",
|
"env_logger 0.7.1",
|
||||||
"fce",
|
"fce",
|
||||||
"fce-utils",
|
"fce-utils",
|
||||||
"fluence-sdk-main 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
"fluence-sdk-main 0.2.9",
|
||||||
"itertools",
|
"itertools",
|
||||||
"log",
|
"log",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
@ -794,15 +803,23 @@ version = "0.2.9"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ca5ffdf0ccf817b1e4e8438f6da7e8fa024679c706a69bde7aa8cad8b43e90ee"
|
checksum = "ca5ffdf0ccf817b1e4e8438f6da7e8fa024679c706a69bde7aa8cad8b43e90ee"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"fluence-sdk-wit 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
"fluence-sdk-wit 0.2.9",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "fluence-sdk-macro"
|
name = "fluence-sdk-macro"
|
||||||
version = "0.2.9"
|
version = "0.2.10"
|
||||||
source = "git+https://github.com/fluencelabs/rust-sdk#fd9672636e8d7a91275e5e0b8b88a34494336e5a"
|
source = "git+https://github.com/fluencelabs/rust-sdk?branch=logger_env#be250f9c1f75309b1d96d78dbfd380a8fae7fd3f"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"fluence-sdk-wit 0.2.9 (git+https://github.com/fluencelabs/rust-sdk)",
|
"fluence-sdk-wit 0.2.10 (git+https://github.com/fluencelabs/rust-sdk?branch=logger_env)",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "fluence-sdk-macro"
|
||||||
|
version = "0.2.10"
|
||||||
|
source = "git+https://github.com/fluencelabs/rust-sdk#ebf3e63aef8d4aafda41180eeb299c4138628174"
|
||||||
|
dependencies = [
|
||||||
|
"fluence-sdk-wit 0.2.10 (git+https://github.com/fluencelabs/rust-sdk)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -811,17 +828,27 @@ version = "0.2.9"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d4f81c3778c18d372fec6d96049f25e29fc4ff7ba4ab65ef4c2285f971e8670a"
|
checksum = "d4f81c3778c18d372fec6d96049f25e29fc4ff7ba4ab65ef4c2285f971e8670a"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"fluence-sdk-macro 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
"fluence-sdk-macro 0.2.9",
|
||||||
"log",
|
"log",
|
||||||
"serde",
|
"serde",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "fluence-sdk-main"
|
name = "fluence-sdk-main"
|
||||||
version = "0.2.9"
|
version = "0.2.10"
|
||||||
source = "git+https://github.com/fluencelabs/rust-sdk#fd9672636e8d7a91275e5e0b8b88a34494336e5a"
|
source = "git+https://github.com/fluencelabs/rust-sdk?branch=logger_env#be250f9c1f75309b1d96d78dbfd380a8fae7fd3f"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"fluence-sdk-macro 0.2.9 (git+https://github.com/fluencelabs/rust-sdk)",
|
"fluence-sdk-macro 0.2.10 (git+https://github.com/fluencelabs/rust-sdk?branch=logger_env)",
|
||||||
|
"log",
|
||||||
|
"serde",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "fluence-sdk-main"
|
||||||
|
version = "0.2.10"
|
||||||
|
source = "git+https://github.com/fluencelabs/rust-sdk#ebf3e63aef8d4aafda41180eeb299c4138628174"
|
||||||
|
dependencies = [
|
||||||
|
"fluence-sdk-macro 0.2.10 (git+https://github.com/fluencelabs/rust-sdk)",
|
||||||
"log",
|
"log",
|
||||||
"serde",
|
"serde",
|
||||||
]
|
]
|
||||||
@ -842,8 +869,21 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "fluence-sdk-wit"
|
name = "fluence-sdk-wit"
|
||||||
version = "0.2.9"
|
version = "0.2.10"
|
||||||
source = "git+https://github.com/fluencelabs/rust-sdk#fd9672636e8d7a91275e5e0b8b88a34494336e5a"
|
source = "git+https://github.com/fluencelabs/rust-sdk?branch=logger_env#be250f9c1f75309b1d96d78dbfd380a8fae7fd3f"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"serde",
|
||||||
|
"serde_json",
|
||||||
|
"syn",
|
||||||
|
"uuid",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "fluence-sdk-wit"
|
||||||
|
version = "0.2.10"
|
||||||
|
source = "git+https://github.com/fluencelabs/rust-sdk#ebf3e63aef8d4aafda41180eeb299c4138628174"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
@ -1323,15 +1363,15 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libc"
|
name = "libc"
|
||||||
version = "0.2.80"
|
version = "0.2.81"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "4d58d1b70b004888f764dfbf6a26a3b0342a1632d33968e4a179d8011c760614"
|
checksum = "1482821306169ec4d07f6aca392a4681f66c75c9918aa49641a2595db64053cb"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "local_storage"
|
name = "local_storage"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"fluence 0.2.9 (git+https://github.com/fluencelabs/rust-sdk)",
|
"fluence 0.2.9 (git+https://github.com/fluencelabs/rust-sdk?branch=logger_env)",
|
||||||
"log",
|
"log",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -2096,9 +2136,9 @@ checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde"
|
name = "serde"
|
||||||
version = "1.0.117"
|
version = "1.0.118"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b88fa983de7720629c9387e9f517353ed404164b1e482c970a90c1a4aaf7dc1a"
|
checksum = "06c64263859d87aa2eb554587e2d23183398d617427327cf2b3d0ed8c69e4800"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"serde_derive",
|
"serde_derive",
|
||||||
]
|
]
|
||||||
@ -2124,9 +2164,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde_derive"
|
name = "serde_derive"
|
||||||
version = "1.0.117"
|
version = "1.0.118"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "cbd1ae72adb44aab48f325a02444a5fc079349a8d804c1fc922aed3f7454c74e"
|
checksum = "c84d3526699cd55261af4b941e4e725444df67aa4f9e6a3564f18030d12672df"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
@ -2135,9 +2175,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde_json"
|
name = "serde_json"
|
||||||
version = "1.0.59"
|
version = "1.0.60"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "dcac07dbffa1c65e7f816ab9eba78eb142c6d44410f4eeba1e26e4f5dfa56b95"
|
checksum = "1500e84d27fe482ed1dc791a56eddc2f230046a040fa908c08bda1d9fb615779"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"itoa",
|
"itoa",
|
||||||
"ryu",
|
"ryu",
|
||||||
@ -2195,9 +2235,9 @@ checksum = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "smallvec"
|
name = "smallvec"
|
||||||
version = "1.5.0"
|
version = "1.5.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7acad6f34eb9e8a259d3283d1e8c1d34d7415943d4895f65cc73813c7396fc85"
|
checksum = "ae524f056d7d770e174287294f562e95044c68e88dec909a00d2094805db9d75"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "socket2"
|
name = "socket2"
|
||||||
@ -2237,9 +2277,9 @@ checksum = "343f3f510c2915908f155e94f17220b19ccfacf2a64a2a5d8004f2c3e311e7fd"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "syn"
|
name = "syn"
|
||||||
version = "1.0.53"
|
version = "1.0.54"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8833e20724c24de12bbaba5ad230ea61c3eafb05b881c7c9d3cfe8638b187e68"
|
checksum = "9a2af957a63d6bd42255c359c93d9bfdb97076bd3b820897ce55ffbfbf107f44"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
|
@ -19,14 +19,14 @@ mod path;
|
|||||||
use crate::path::to_full_path;
|
use crate::path::to_full_path;
|
||||||
|
|
||||||
use fluence::fce;
|
use fluence::fce;
|
||||||
use fluence::WasmLogger;
|
use fluence::WasmLoggerBuilder;
|
||||||
|
|
||||||
const RESULT_FILE_PATH: &str = "/tmp/ipfs_rpc_file";
|
const RESULT_FILE_PATH: &str = "/tmp/ipfs_rpc_file";
|
||||||
const IPFS_ADDR_ENV_NAME: &str = "IPFS_ADDR";
|
const IPFS_ADDR_ENV_NAME: &str = "IPFS_ADDR";
|
||||||
const TIMEOUT_ENV_NAME: &str = "timeout";
|
const TIMEOUT_ENV_NAME: &str = "timeout";
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
WasmLogger::new()
|
WasmLoggerBuilder::new()
|
||||||
.with_log_level(log::Level::Info)
|
.with_log_level(log::Level::Info)
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
use fluence::fce;
|
use fluence::fce;
|
||||||
use fluence::WasmLogger;
|
use fluence::WasmLoggerBuilder;
|
||||||
|
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
@ -23,7 +23,7 @@ use std::path::PathBuf;
|
|||||||
const RPC_TMP_FILEPATH: &str = "/tmp/ipfs_rpc_file";
|
const RPC_TMP_FILEPATH: &str = "/tmp/ipfs_rpc_file";
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
WasmLogger::new()
|
WasmLoggerBuilder::new()
|
||||||
.with_log_level(log::Level::Info)
|
.with_log_level(log::Level::Info)
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -15,14 +15,11 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
use fluence::fce;
|
use fluence::fce;
|
||||||
use fluence::WasmLogger;
|
use fluence::WasmLoggerBuilder;
|
||||||
|
|
||||||
/// Log level can be changed by `RUST_LOG` env as well.
|
/// Log level can be changed by `RUST_LOG` env as well.
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
WasmLogger::new()
|
WasmLoggerBuilder::new().build().unwrap();
|
||||||
.with_log_level(log::Level::Info)
|
|
||||||
.build()
|
|
||||||
.unwrap();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[fce]
|
#[fce]
|
||||||
|
@ -15,13 +15,10 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
use fluence::fce;
|
use fluence::fce;
|
||||||
use fluence::WasmLogger;
|
use fluence::WasmLoggerBuilder;
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
WasmLogger::new()
|
WasmLoggerBuilder::new().build().unwrap();
|
||||||
.with_log_level(log::Level::Info)
|
|
||||||
.build()
|
|
||||||
.unwrap();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Combining of modules: `curl` and `local_storage`.
|
/// Combining of modules: `curl` and `local_storage`.
|
||||||
|
@ -9,5 +9,5 @@ name = "local_storage"
|
|||||||
path = "src/main.rs"
|
path = "src/main.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
fluence = { git = "https://github.com/fluencelabs/rust-sdk", features = ["logger"] }
|
fluence = { git = "https://github.com/fluencelabs/rust-sdk", features = ["logger"], branch = "logger_env" }
|
||||||
log = "0.4.8"
|
log = "0.4.8"
|
||||||
|
@ -16,17 +16,14 @@
|
|||||||
|
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use fluence::fce;
|
use fluence::fce;
|
||||||
use fluence::WasmLogger;
|
use fluence::WasmLoggerBuilder;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
const SITES_DIR: &str = "/sites/";
|
const SITES_DIR: &str = "/sites/";
|
||||||
|
|
||||||
/// Log level can be changed by `RUST_LOG` env as well.
|
/// Log level can be changed by `RUST_LOG` env as well.
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
WasmLogger::new()
|
WasmLoggerBuilder::new().build().unwrap();
|
||||||
.with_log_level(log::Level::Info)
|
|
||||||
.build()
|
|
||||||
.unwrap();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// You can read or write files from the file system if there is permission to use directories described in `Config.toml`.
|
/// You can read or write files from the file system if there is permission to use directories described in `Config.toml`.
|
||||||
@ -46,7 +43,7 @@ pub fn put(name: String, file_content: Vec<u8>) -> String {
|
|||||||
|
|
||||||
#[fce]
|
#[fce]
|
||||||
pub fn get(file_name: String) -> Vec<u8> {
|
pub fn get(file_name: String) -> Vec<u8> {
|
||||||
log::info!("get called with file name: {}", file_name);
|
log::debug!("get called with file name: {}", file_name);
|
||||||
|
|
||||||
let tmp_filepath = format!("{}{}", SITES_DIR, file_name);
|
let tmp_filepath = format!("{}{}", SITES_DIR, file_name);
|
||||||
|
|
||||||
|
@ -22,6 +22,8 @@ use crate::IValue;
|
|||||||
use crate::IType;
|
use crate::IType;
|
||||||
use crate::misc::load_modules_from_fs;
|
use crate::misc::load_modules_from_fs;
|
||||||
use crate::misc::ModulesLoadStrategy;
|
use crate::misc::ModulesLoadStrategy;
|
||||||
|
use crate::logger::LoggerFilter;
|
||||||
|
use crate::logger::WASM_LOG_ENV_NAME;
|
||||||
|
|
||||||
use fce::FCE;
|
use fce::FCE;
|
||||||
use fce::IFunctionArg;
|
use fce::IFunctionArg;
|
||||||
@ -91,6 +93,11 @@ impl FluenceFaaS {
|
|||||||
let call_parameters = Rc::new(RefCell::new(<_>::default()));
|
let call_parameters = Rc::new(RefCell::new(<_>::default()));
|
||||||
|
|
||||||
let modules_dir = config.modules_dir;
|
let modules_dir = config.modules_dir;
|
||||||
|
|
||||||
|
// LoggerFilter can be initialized with an empty string
|
||||||
|
let wasm_log_env = std::env::var(WASM_LOG_ENV_NAME).unwrap_or_default();
|
||||||
|
let logger_filter = LoggerFilter::from_env_string(&wasm_log_env);
|
||||||
|
|
||||||
for (module_name, module_config) in config.modules_config {
|
for (module_name, module_config) in config.modules_config {
|
||||||
let module_bytes =
|
let module_bytes =
|
||||||
modules.remove(&module_name).ok_or_else(|| {
|
modules.remove(&module_name).ok_or_else(|| {
|
||||||
@ -104,6 +111,7 @@ impl FluenceFaaS {
|
|||||||
module_name.clone(),
|
module_name.clone(),
|
||||||
Some(module_config),
|
Some(module_config),
|
||||||
call_parameters.clone(),
|
call_parameters.clone(),
|
||||||
|
&logger_filter
|
||||||
)?;
|
)?;
|
||||||
fce.load_module(module_name, &module_bytes, fce_module_config)?;
|
fce.load_module(module_name, &module_bytes, fce_module_config)?;
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
|
|
||||||
mod config;
|
mod config;
|
||||||
mod errors;
|
mod errors;
|
||||||
|
mod logger;
|
||||||
mod faas;
|
mod faas;
|
||||||
mod faas_interface;
|
mod faas_interface;
|
||||||
mod misc;
|
mod misc;
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
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(
|
pub(crate) fn log_utf8_string_closure(
|
||||||
logging_mask: i64,
|
logging_mask: i64,
|
||||||
module: String,
|
module: String,
|
||||||
) -> impl Fn(&mut Ctx, i32, i64, i32, i32) {
|
) -> impl Fn(&mut Ctx, i32, i64, i32, i32) {
|
||||||
@ -28,7 +28,7 @@ pub(super) fn log_utf8_string_closure(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn log_utf8_string(
|
pub(crate) fn log_utf8_string(
|
||||||
module: &str,
|
module: &str,
|
||||||
ctx: &mut Ctx,
|
ctx: &mut Ctx,
|
||||||
level: i32,
|
level: i32,
|
102
fluence-faas/src/logger/logger_filter.rs
Normal file
102
fluence-faas/src/logger/logger_filter.rs
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2020 Fluence Labs Limited
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
use log::LevelFilter;
|
||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
/// A logger filter.
|
||||||
|
///
|
||||||
|
/// This struct can be used to determine whether or not
|
||||||
|
/// a log record should be written to the output.
|
||||||
|
#[derive(Clone, Default, Eq, PartialEq, Debug)]
|
||||||
|
pub(crate) struct LoggerFilter<'env_string> {
|
||||||
|
default_log_level: Option<LevelFilter>,
|
||||||
|
module_levels: HashMap<&'env_string str, LevelFilter>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'env_string> LoggerFilter<'env_string> {
|
||||||
|
/// Parses a content of supplied variable in form of "module_name_1=log_level,module_name_2".
|
||||||
|
pub(crate) fn from_env_string(env: &'env_string str) -> Self {
|
||||||
|
let mut module_levels = HashMap::new();
|
||||||
|
let mut default_log_level: Option<LevelFilter> = None;
|
||||||
|
|
||||||
|
for module_log in env.split(',') {
|
||||||
|
if module_log.is_empty() {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut module_log_parts = module_log.split('=');
|
||||||
|
let part_0 = module_log_parts.next();
|
||||||
|
let part_1 = module_log_parts.next().map(|s| s.trim());
|
||||||
|
if let Some(part_3) = module_log_parts.next() {
|
||||||
|
eprintln!(
|
||||||
|
"logger warning: invalid directive '{}', ignoring it",
|
||||||
|
part_3
|
||||||
|
);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
let (module_name, module_log_level) = match (part_0, part_1) {
|
||||||
|
// "info"
|
||||||
|
// "1"
|
||||||
|
(Some(part), None) => match part.parse() {
|
||||||
|
Ok(num) => (None, num),
|
||||||
|
Err(_) => (Some(part), LevelFilter::max()),
|
||||||
|
},
|
||||||
|
// "module_name="
|
||||||
|
(Some(module_name), Some("")) => (Some(module_name), LevelFilter::max()),
|
||||||
|
// "module_name=info"
|
||||||
|
(Some(module_name), Some(log_level)) => match log_level.parse() {
|
||||||
|
Ok(log_level) => (Some(module_name), log_level),
|
||||||
|
Err(e) => {
|
||||||
|
eprintln!(
|
||||||
|
"logger warning: invalid directive '{}', error '{}', ignoring it",
|
||||||
|
log_level, e
|
||||||
|
);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
d => {
|
||||||
|
eprintln!("logger warning: invalid directive '{:?}', ignoring it", d);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
match (module_name, &mut default_log_level) {
|
||||||
|
(Some(module_name), _) => {
|
||||||
|
module_levels.insert(module_name, module_log_level);
|
||||||
|
}
|
||||||
|
(None, Some(_)) => {
|
||||||
|
eprintln!(
|
||||||
|
"logger warning: can't set default level twice, '{}' ignored",
|
||||||
|
module_log_level
|
||||||
|
);
|
||||||
|
}
|
||||||
|
(None, w) => *w = Some(module_log_level),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Self {
|
||||||
|
default_log_level,
|
||||||
|
module_levels,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn module_level(&self, module_name: &str) -> Option<LevelFilter> {
|
||||||
|
self.module_levels
|
||||||
|
.get(module_name)
|
||||||
|
.map_or_else(|| self.default_log_level, |l| Some(*l))
|
||||||
|
}
|
||||||
|
}
|
23
fluence-faas/src/logger/mod.rs
Normal file
23
fluence-faas/src/logger/mod.rs
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2020 Fluence Labs Limited
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
mod logger_filter;
|
||||||
|
mod log_utf8_string_impl;
|
||||||
|
|
||||||
|
pub const WASM_LOG_ENV_NAME: &str = "WASM_LOG";
|
||||||
|
|
||||||
|
pub(crate) use logger_filter::LoggerFilter;
|
||||||
|
pub(crate) use log_utf8_string_impl::log_utf8_string_closure;
|
@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
mod ivalues_to_json;
|
mod ivalues_to_json;
|
||||||
mod json_to_ivalues;
|
mod json_to_ivalues;
|
||||||
mod log_utf8_string_impl;
|
|
||||||
mod modules_load_strategy;
|
mod modules_load_strategy;
|
||||||
mod utils;
|
mod utils;
|
||||||
|
|
||||||
@ -26,5 +25,3 @@ 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(crate) use utils::load_modules_from_fs;
|
pub(crate) use utils::load_modules_from_fs;
|
||||||
|
|
||||||
pub(self) use log_utf8_string_impl::log_utf8_string_closure;
|
|
||||||
|
@ -14,10 +14,12 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use super::log_utf8_string_closure;
|
|
||||||
use crate::Result;
|
use crate::Result;
|
||||||
use crate::config::FaaSModuleConfig;
|
use crate::config::FaaSModuleConfig;
|
||||||
use crate::errors::FaaSError;
|
use crate::errors::FaaSError;
|
||||||
|
use crate::logger::log_utf8_string_closure;
|
||||||
|
use crate::logger::LoggerFilter;
|
||||||
|
use crate::logger::WASM_LOG_ENV_NAME;
|
||||||
|
|
||||||
use fce::FCEModuleConfig;
|
use fce::FCEModuleConfig;
|
||||||
use fce::HostImportDescriptor;
|
use fce::HostImportDescriptor;
|
||||||
@ -83,6 +85,7 @@ pub(crate) fn make_fce_config(
|
|||||||
module_name: String,
|
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>>,
|
||||||
|
logger_filter: &LoggerFilter<'_>
|
||||||
) -> Result<FCEModuleConfig> {
|
) -> Result<FCEModuleConfig> {
|
||||||
let mut fce_module_config = FCEModuleConfig::default();
|
let mut fce_module_config = FCEModuleConfig::default();
|
||||||
|
|
||||||
@ -123,6 +126,20 @@ 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 {
|
||||||
|
if let Some(level_filter) = logger_filter.module_level(&module_name) {
|
||||||
|
let log_level = level_filter.to_level();
|
||||||
|
let log_level_str = match log_level {
|
||||||
|
Some(log_level) => log_level.to_string(),
|
||||||
|
None => String::from("off")
|
||||||
|
};
|
||||||
|
|
||||||
|
// overwrite possibly installed log variable in config
|
||||||
|
fce_module_config.wasi_envs.insert(
|
||||||
|
WASM_LOG_ENV_NAME.as_bytes().to_owned(),
|
||||||
|
log_level_str.into_bytes(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
let logging_mask = faas_module_config.logging_mask;
|
let logging_mask = faas_module_config.logging_mask;
|
||||||
namespace.insert(
|
namespace.insert(
|
||||||
"log_utf8_string",
|
"log_utf8_string",
|
||||||
@ -190,3 +207,4 @@ pub(crate) fn load_modules_from_fs(
|
|||||||
|
|
||||||
Ok(loaded)
|
Ok(loaded)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user