@yuneta/gobj-js 7.6.7 → 7.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -386,6 +386,13 @@ var Event_Type = class {
386
386
  function tab() {
387
387
  return " ".repeat(Math.max(0, __inside__ * 2 - 1));
388
388
  }
389
+ var __trace_machine_format__ = 0;
390
+ function gobj_set_trace_machine_format(format) {
391
+ __trace_machine_format__ = Number(format) === 1 ? 1 : 0;
392
+ }
393
+ function gobj_trace_machine_format() {
394
+ return __trace_machine_format__;
395
+ }
389
396
  /************************************************************
390
397
  *
391
398
  ************************************************************/
@@ -2118,9 +2125,12 @@ function gobj_send_event(dst, event, kw, src) {
2118
2125
  return -1;
2119
2126
  }
2120
2127
  if (tracea) {
2121
- let action_name = "";
2122
- if (event_action.action) action_name = get_function_name(event_action.action);
2123
- trace_machine(sprintf("🔄 mach(%s%s^%s), st: %s, ev: %s%s%s, ac: %s, from(%s%s^%s)", !dst.running ? "!!" : "", gobj_gclass_name(dst), gobj_name(dst), state.state_name, "", event ? event : "", "", action_name, src && !src.running ? "!!" : "", gobj_gclass_name(src), gobj_name(src)));
2128
+ if (__trace_machine_format__ === 1) trace_machine(sprintf("🔄 %s %s%s %s from %s%s", event ? event : "", !dst.running ? "!!" : "", gobj_short_name(dst), state.state_name, src && !src.running ? "!!" : "", gobj_short_name(src)));
2129
+ else {
2130
+ let action_name = "";
2131
+ if (event_action.action) action_name = get_function_name(event_action.action);
2132
+ trace_machine(sprintf("🔄 mach(%s%s^%s), st: %s, ev: %s%s%s, ac: %s, from(%s%s^%s)", !dst.running ? "!!" : "", gobj_gclass_name(dst), gobj_name(dst), state.state_name, "", event ? event : "", "", action_name, src && !src.running ? "!!" : "", gobj_gclass_name(src), gobj_name(src)));
2133
+ }
2124
2134
  if (kw) {
2125
2135
  if (tracea > 1) {
2126
2136
  if (json_object_size(kw)) trace_json(kw);
@@ -2132,7 +2142,7 @@ function gobj_send_event(dst, event, kw, src) {
2132
2142
  try {
2133
2143
  if (event_action.action) ret = event_action.action(dst, event, kw, src);
2134
2144
  } finally {}
2135
- if (tracea && !(dst.obflag & obflag_t.obflag_destroyed)) trace_machine(sprintf("<- mach(%s%s^%s), st: %s, ev: %s, ret: %d", !dst.running ? "!!" : "", gobj_gclass_name(dst), gobj_name(dst), dst.current_state.state_name, event ? event : "", is_number(ret) ? ret : 0));
2145
+ if (tracea && __trace_machine_format__ !== 1 && !(dst.obflag & obflag_t.obflag_destroyed)) trace_machine(sprintf("<- mach(%s%s^%s), st: %s, ev: %s, ret: %d", !dst.running ? "!!" : "", gobj_gclass_name(dst), gobj_name(dst), dst.current_state.state_name, event ? event : "", is_number(ret) ? ret : 0));
2136
2146
  __inside__--;
2137
2147
  return ret;
2138
2148
  }
@@ -2616,6 +2626,21 @@ var f_error = _console.error;
2616
2626
  var f_warning = _console.warn;
2617
2627
  var f_info = _console.info;
2618
2628
  var f_debug = _console.debug;
2629
+ var __log_callback__ = null;
2630
+ function set_log_callback(fn) {
2631
+ __log_callback__ = typeof fn === "function" ? fn : null;
2632
+ }
2633
+ var __in_log_callback__ = false;
2634
+ function emit_log_callback(level, msg, hora) {
2635
+ if (__log_callback__ && !__in_log_callback__) {
2636
+ __in_log_callback__ = true;
2637
+ try {
2638
+ __log_callback__(level, msg, hora);
2639
+ } catch (e) {} finally {
2640
+ __in_log_callback__ = false;
2641
+ }
2642
+ }
2643
+ }
2619
2644
  function set_remote_log_functions(remote_log_fn) {
2620
2645
  if (remote_log_fn) {
2621
2646
  f_error = remote_log_fn;
@@ -2655,6 +2680,7 @@ function log_error(format) {
2655
2680
  window.console.error("%c" + hora + " ERROR: " + String(msg), "color:red");
2656
2681
  f_error(`${hora} ERROR: ${String(msg)}`);
2657
2682
  }
2683
+ emit_log_callback("error", msg, hora);
2658
2684
  }
2659
2685
  function log_warning(format) {
2660
2686
  let msg = format_log(format);
@@ -2664,25 +2690,30 @@ function log_warning(format) {
2664
2690
  window.console.warn("%c" + hora + " WARNING: " + String(msg), "color:yellow");
2665
2691
  f_warning(`${hora} WARNING: ${String(msg)}`);
2666
2692
  }
2693
+ emit_log_callback("warning", msg, hora);
2667
2694
  }
2668
2695
  function log_info(format) {
2669
2696
  let msg = format_log(format);
2670
2697
  let hora = current_timestamp();
2671
2698
  if (f_info) f_info("%c" + hora + " INFO: " + String(msg), "color:cyan");
2699
+ emit_log_callback("info", msg, hora);
2672
2700
  }
2673
2701
  function log_debug(format) {
2674
2702
  let msg = format_log(format);
2675
2703
  let hora = current_timestamp();
2676
2704
  if (f_debug) f_debug("%c" + hora + " DEBUG: " + String(msg), "color:silver");
2705
+ emit_log_callback("debug", msg, hora);
2677
2706
  }
2678
2707
  function trace_msg(format) {
2679
2708
  let msg = format_log(format);
2680
2709
  let hora = current_timestamp();
2681
2710
  if (f_debug) f_debug("%c" + hora + " MSG: " + String(msg), "color:cyan");
2711
+ emit_log_callback("msg", msg, hora);
2682
2712
  }
2683
2713
  function trace_json(jn, msg) {
2684
2714
  if (msg) window.console.warn("=====> " + msg);
2685
2715
  window.console.dir(jn);
2716
+ emit_log_callback("json", jn, current_timestamp());
2686
2717
  }
2687
2718
  /************************************************************
2688
2719
  * Duplicate an object (new references)
@@ -6224,6 +6255,7 @@ exports.gobj_search_path = gobj_search_path;
6224
6255
  exports.gobj_send_event = gobj_send_event;
6225
6256
  exports.gobj_services = gobj_services;
6226
6257
  exports.gobj_set_bottom_gobj = gobj_set_bottom_gobj;
6258
+ exports.gobj_set_trace_machine_format = gobj_set_trace_machine_format;
6227
6259
  exports.gobj_short_name = gobj_short_name;
6228
6260
  exports.gobj_start = gobj_start;
6229
6261
  exports.gobj_start_children = gobj_start_children;
@@ -6234,6 +6266,7 @@ exports.gobj_stop = gobj_stop;
6234
6266
  exports.gobj_stop_children = gobj_stop_children;
6235
6267
  exports.gobj_stop_tree = gobj_stop_tree;
6236
6268
  exports.gobj_subscribe_event = gobj_subscribe_event;
6269
+ exports.gobj_trace_machine_format = gobj_trace_machine_format;
6237
6270
  exports.gobj_unsubscribe_event = gobj_unsubscribe_event;
6238
6271
  exports.gobj_unsubscribe_list = gobj_unsubscribe_list;
6239
6272
  exports.gobj_walk_gobj_children = gobj_walk_gobj_children;
@@ -6336,6 +6369,7 @@ exports.register_c_yuno = register_c_yuno;
6336
6369
  exports.safeSrc = safeSrc;
6337
6370
  exports.sdata_flag_t = sdata_flag_t;
6338
6371
  exports.send_http_json_post = send_http_json_post;
6372
+ exports.set_log_callback = set_log_callback;
6339
6373
  exports.set_remote_log_functions = set_remote_log_functions;
6340
6374
  exports.set_timeout = set_timeout;
6341
6375
  exports.set_timeout_periodic = set_timeout_periodic;