@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.
@@ -389,6 +389,13 @@
389
389
  function tab() {
390
390
  return " ".repeat(Math.max(0, __inside__ * 2 - 1));
391
391
  }
392
+ var __trace_machine_format__ = 0;
393
+ function gobj_set_trace_machine_format(format) {
394
+ __trace_machine_format__ = Number(format) === 1 ? 1 : 0;
395
+ }
396
+ function gobj_trace_machine_format() {
397
+ return __trace_machine_format__;
398
+ }
392
399
  /************************************************************
393
400
  *
394
401
  ************************************************************/
@@ -2121,9 +2128,12 @@
2121
2128
  return -1;
2122
2129
  }
2123
2130
  if (tracea) {
2124
- let action_name = "";
2125
- if (event_action.action) action_name = get_function_name(event_action.action);
2126
- 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)));
2131
+ 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)));
2132
+ else {
2133
+ let action_name = "";
2134
+ if (event_action.action) action_name = get_function_name(event_action.action);
2135
+ 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)));
2136
+ }
2127
2137
  if (kw) {
2128
2138
  if (tracea > 1) {
2129
2139
  if (json_object_size(kw)) trace_json(kw);
@@ -2135,7 +2145,7 @@
2135
2145
  try {
2136
2146
  if (event_action.action) ret = event_action.action(dst, event, kw, src);
2137
2147
  } finally {}
2138
- 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));
2148
+ 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));
2139
2149
  __inside__--;
2140
2150
  return ret;
2141
2151
  }
@@ -2619,6 +2629,21 @@
2619
2629
  var f_warning = _console.warn;
2620
2630
  var f_info = _console.info;
2621
2631
  var f_debug = _console.debug;
2632
+ var __log_callback__ = null;
2633
+ function set_log_callback(fn) {
2634
+ __log_callback__ = typeof fn === "function" ? fn : null;
2635
+ }
2636
+ var __in_log_callback__ = false;
2637
+ function emit_log_callback(level, msg, hora) {
2638
+ if (__log_callback__ && !__in_log_callback__) {
2639
+ __in_log_callback__ = true;
2640
+ try {
2641
+ __log_callback__(level, msg, hora);
2642
+ } catch (e) {} finally {
2643
+ __in_log_callback__ = false;
2644
+ }
2645
+ }
2646
+ }
2622
2647
  function set_remote_log_functions(remote_log_fn) {
2623
2648
  if (remote_log_fn) {
2624
2649
  f_error = remote_log_fn;
@@ -2658,6 +2683,7 @@
2658
2683
  window.console.error("%c" + hora + " ERROR: " + String(msg), "color:red");
2659
2684
  f_error(`${hora} ERROR: ${String(msg)}`);
2660
2685
  }
2686
+ emit_log_callback("error", msg, hora);
2661
2687
  }
2662
2688
  function log_warning(format) {
2663
2689
  let msg = format_log(format);
@@ -2667,25 +2693,30 @@
2667
2693
  window.console.warn("%c" + hora + " WARNING: " + String(msg), "color:yellow");
2668
2694
  f_warning(`${hora} WARNING: ${String(msg)}`);
2669
2695
  }
2696
+ emit_log_callback("warning", msg, hora);
2670
2697
  }
2671
2698
  function log_info(format) {
2672
2699
  let msg = format_log(format);
2673
2700
  let hora = current_timestamp();
2674
2701
  if (f_info) f_info("%c" + hora + " INFO: " + String(msg), "color:cyan");
2702
+ emit_log_callback("info", msg, hora);
2675
2703
  }
2676
2704
  function log_debug(format) {
2677
2705
  let msg = format_log(format);
2678
2706
  let hora = current_timestamp();
2679
2707
  if (f_debug) f_debug("%c" + hora + " DEBUG: " + String(msg), "color:silver");
2708
+ emit_log_callback("debug", msg, hora);
2680
2709
  }
2681
2710
  function trace_msg(format) {
2682
2711
  let msg = format_log(format);
2683
2712
  let hora = current_timestamp();
2684
2713
  if (f_debug) f_debug("%c" + hora + " MSG: " + String(msg), "color:cyan");
2714
+ emit_log_callback("msg", msg, hora);
2685
2715
  }
2686
2716
  function trace_json(jn, msg) {
2687
2717
  if (msg) window.console.warn("=====> " + msg);
2688
2718
  window.console.dir(jn);
2719
+ emit_log_callback("json", jn, current_timestamp());
2689
2720
  }
2690
2721
  /************************************************************
2691
2722
  * Duplicate an object (new references)
@@ -6227,6 +6258,7 @@
6227
6258
  exports.gobj_send_event = gobj_send_event;
6228
6259
  exports.gobj_services = gobj_services;
6229
6260
  exports.gobj_set_bottom_gobj = gobj_set_bottom_gobj;
6261
+ exports.gobj_set_trace_machine_format = gobj_set_trace_machine_format;
6230
6262
  exports.gobj_short_name = gobj_short_name;
6231
6263
  exports.gobj_start = gobj_start;
6232
6264
  exports.gobj_start_children = gobj_start_children;
@@ -6237,6 +6269,7 @@
6237
6269
  exports.gobj_stop_children = gobj_stop_children;
6238
6270
  exports.gobj_stop_tree = gobj_stop_tree;
6239
6271
  exports.gobj_subscribe_event = gobj_subscribe_event;
6272
+ exports.gobj_trace_machine_format = gobj_trace_machine_format;
6240
6273
  exports.gobj_unsubscribe_event = gobj_unsubscribe_event;
6241
6274
  exports.gobj_unsubscribe_list = gobj_unsubscribe_list;
6242
6275
  exports.gobj_walk_gobj_children = gobj_walk_gobj_children;
@@ -6339,6 +6372,7 @@
6339
6372
  exports.safeSrc = safeSrc;
6340
6373
  exports.sdata_flag_t = sdata_flag_t;
6341
6374
  exports.send_http_json_post = send_http_json_post;
6375
+ exports.set_log_callback = set_log_callback;
6342
6376
  exports.set_remote_log_functions = set_remote_log_functions;
6343
6377
  exports.set_timeout = set_timeout;
6344
6378
  exports.set_timeout_periodic = set_timeout_periodic;