parent
a4db20fb05
commit
8cfc286beb
4 changed files with 66 additions and 0 deletions
57
lib/src/fnc/script/globals/console.rs
Normal file
57
lib/src/fnc/script/globals/console.rs
Normal file
|
@ -0,0 +1,57 @@
|
|||
#[js::bind(object, public)]
|
||||
#[quickjs(rename = "console")]
|
||||
#[allow(clippy::module_inception)]
|
||||
pub mod console {
|
||||
// Specify the imports
|
||||
use crate::fnc::script::LOG;
|
||||
use crate::sql::value::Value;
|
||||
use js::Rest;
|
||||
/// Log the input values as INFO
|
||||
pub fn log(args: Rest<Value>) {
|
||||
info!(
|
||||
target: LOG,
|
||||
"{}",
|
||||
args.iter().map(|v| v.to_raw_string()).collect::<Vec<String>>().join(" ")
|
||||
);
|
||||
}
|
||||
/// Log the input values as INFO
|
||||
pub fn info(args: Rest<Value>) {
|
||||
info!(
|
||||
target: LOG,
|
||||
"{}",
|
||||
args.iter().map(|v| v.to_raw_string()).collect::<Vec<String>>().join(" ")
|
||||
);
|
||||
}
|
||||
/// Log the input values as WARN
|
||||
pub fn warn(args: Rest<Value>) {
|
||||
warn!(
|
||||
target: LOG,
|
||||
"{}",
|
||||
args.iter().map(|v| v.to_raw_string()).collect::<Vec<String>>().join(" ")
|
||||
);
|
||||
}
|
||||
/// Log the input values as ERROR
|
||||
pub fn error(args: Rest<Value>) {
|
||||
error!(
|
||||
target: LOG,
|
||||
"{}",
|
||||
args.iter().map(|v| v.to_raw_string()).collect::<Vec<String>>().join(" ")
|
||||
);
|
||||
}
|
||||
/// Log the input values as DEBUG
|
||||
pub fn debug(args: Rest<Value>) {
|
||||
debug!(
|
||||
target: LOG,
|
||||
"{}",
|
||||
args.iter().map(|v| v.to_raw_string()).collect::<Vec<String>>().join(" ")
|
||||
);
|
||||
}
|
||||
/// Log the input values as TRACE
|
||||
pub fn trace(args: Rest<Value>) {
|
||||
trace!(
|
||||
target: LOG,
|
||||
"{}",
|
||||
args.iter().map(|v| v.to_raw_string()).collect::<Vec<String>>().join(" ")
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1 +1,2 @@
|
|||
pub mod console;
|
||||
pub mod fetch;
|
||||
|
|
|
@ -5,6 +5,8 @@ use super::modules;
|
|||
use super::modules::loader;
|
||||
use super::modules::resolver;
|
||||
use crate::ctx::Context;
|
||||
use crate::dbs::Options;
|
||||
use crate::dbs::Transaction;
|
||||
use crate::err::Error;
|
||||
use crate::sql::value::Value;
|
||||
use js::Function;
|
||||
|
@ -15,6 +17,8 @@ use js::This;
|
|||
|
||||
pub async fn run(
|
||||
ctx: &Context<'_>,
|
||||
_opt: &Options,
|
||||
_txn: &Transaction,
|
||||
doc: Option<&Value>,
|
||||
src: &str,
|
||||
arg: Vec<Value>,
|
||||
|
@ -57,6 +61,8 @@ pub async fn run(
|
|||
)?;
|
||||
// Register the fetch function to the globals
|
||||
global.init_def::<globals::fetch::Fetch>()?;
|
||||
// Register the console function to the globals
|
||||
global.init_def::<globals::console::Console>()?;
|
||||
// Register the special SurrealDB types as classes
|
||||
global.init_def::<classes::duration::Duration>()?;
|
||||
global.init_def::<classes::record::Record>()?;
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#![cfg(feature = "scripting")]
|
||||
|
||||
const LOG: &str = "surrealdb::jsr";
|
||||
|
||||
pub use main::run;
|
||||
|
||||
mod classes;
|
||||
|
|
Loading…
Reference in a new issue