MCPcopy Create free account
hub / github.com/awslabs/llrt / json_log_format

Function json_log_format

llrt_core/src/modules/console.rs:397–477  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

395
396 #[tokio::test]
397 async fn json_log_format() {
398 test_sync_with(|ctx| {
399 BasePrimordials::init(&ctx)?;
400 let write_log = |args| {
401 let mut result = String::new();
402
403 write_lambda_log(
404 &ctx,
405 &mut result,
406 Rest(args),
407 LogLevel::Info,
408 false,
409 true,
410 LogLevel::Info as usize,
411 "",
412 )?;
413
414 //validate json
415 ctx.json_parse(result.clone())?;
416
417 Ok::<_, Error>(result)
418 };
419
420 assert_eq!(
421 write_log(["Hello".into_js(&ctx)?].into())?,
422 r#"{"time":"","level":"INFO","message":"Hello"}"#
423 );
424
425 assert_eq!(
426 write_log([1.into_js(&ctx)?].into())?,
427 r#"{"time":"","level":"INFO","message":1}"#
428 );
429
430 assert_eq!(
431 write_log([true.into_js(&ctx)?].into())?,
432 r#"{"time":"","level":"INFO","message":true}"#
433 );
434
435 assert_eq!(
436 write_log([Undefined.into_js(&ctx)?].into())?,
437 r#"{"time":"","level":"INFO"}"#
438 );
439
440 assert_eq!(
441 write_log([Null.into_js(&ctx)?].into())?,
442 r#"{"time":"","level":"INFO","message":null}"#
443 );
444
445 let obj = Object::new(ctx.clone())?;
446 obj.set("a", 1)?;
447 obj.set("b", "Hello")?;
448
449 assert_eq!(
450 write_log([obj.clone().into_value()].into())?,
451 r#"{"time":"","level":"INFO","message":{"a":1,"b":"Hello"}}"#
452 );
453
454 //validate second argument passed

Callers

nothing calls this directly

Calls 5

test_sync_withFunction · 0.85
write_lambda_logFunction · 0.85
initFunction · 0.70
cloneMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected