@yuneta/gobj-js 7.6.7 → 7.7.0

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,15 @@
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
+ function emit_log_callback(level, msg, hora) {
2637
+ if (__log_callback__) try {
2638
+ __log_callback__(level, msg, hora);
2639
+ } catch (e) {}
2640
+ }
2622
2641
  function set_remote_log_functions(remote_log_fn) {
2623
2642
  if (remote_log_fn) {
2624
2643
  f_error = remote_log_fn;
@@ -2658,6 +2677,7 @@
2658
2677
  window.console.error("%c" + hora + " ERROR: " + String(msg), "color:red");
2659
2678
  f_error(`${hora} ERROR: ${String(msg)}`);
2660
2679
  }
2680
+ emit_log_callback("error", msg, hora);
2661
2681
  }
2662
2682
  function log_warning(format) {
2663
2683
  let msg = format_log(format);
@@ -2667,25 +2687,30 @@
2667
2687
  window.console.warn("%c" + hora + " WARNING: " + String(msg), "color:yellow");
2668
2688
  f_warning(`${hora} WARNING: ${String(msg)}`);
2669
2689
  }
2690
+ emit_log_callback("warning", msg, hora);
2670
2691
  }
2671
2692
  function log_info(format) {
2672
2693
  let msg = format_log(format);
2673
2694
  let hora = current_timestamp();
2674
2695
  if (f_info) f_info("%c" + hora + " INFO: " + String(msg), "color:cyan");
2696
+ emit_log_callback("info", msg, hora);
2675
2697
  }
2676
2698
  function log_debug(format) {
2677
2699
  let msg = format_log(format);
2678
2700
  let hora = current_timestamp();
2679
2701
  if (f_debug) f_debug("%c" + hora + " DEBUG: " + String(msg), "color:silver");
2702
+ emit_log_callback("debug", msg, hora);
2680
2703
  }
2681
2704
  function trace_msg(format) {
2682
2705
  let msg = format_log(format);
2683
2706
  let hora = current_timestamp();
2684
2707
  if (f_debug) f_debug("%c" + hora + " MSG: " + String(msg), "color:cyan");
2708
+ emit_log_callback("msg", msg, hora);
2685
2709
  }
2686
2710
  function trace_json(jn, msg) {
2687
2711
  if (msg) window.console.warn("=====> " + msg);
2688
2712
  window.console.dir(jn);
2713
+ emit_log_callback("json", jn, current_timestamp());
2689
2714
  }
2690
2715
  /************************************************************
2691
2716
  * Duplicate an object (new references)
@@ -6227,6 +6252,7 @@
6227
6252
  exports.gobj_send_event = gobj_send_event;
6228
6253
  exports.gobj_services = gobj_services;
6229
6254
  exports.gobj_set_bottom_gobj = gobj_set_bottom_gobj;
6255
+ exports.gobj_set_trace_machine_format = gobj_set_trace_machine_format;
6230
6256
  exports.gobj_short_name = gobj_short_name;
6231
6257
  exports.gobj_start = gobj_start;
6232
6258
  exports.gobj_start_children = gobj_start_children;
@@ -6237,6 +6263,7 @@
6237
6263
  exports.gobj_stop_children = gobj_stop_children;
6238
6264
  exports.gobj_stop_tree = gobj_stop_tree;
6239
6265
  exports.gobj_subscribe_event = gobj_subscribe_event;
6266
+ exports.gobj_trace_machine_format = gobj_trace_machine_format;
6240
6267
  exports.gobj_unsubscribe_event = gobj_unsubscribe_event;
6241
6268
  exports.gobj_unsubscribe_list = gobj_unsubscribe_list;
6242
6269
  exports.gobj_walk_gobj_children = gobj_walk_gobj_children;
@@ -6339,6 +6366,7 @@
6339
6366
  exports.safeSrc = safeSrc;
6340
6367
  exports.sdata_flag_t = sdata_flag_t;
6341
6368
  exports.send_http_json_post = send_http_json_post;
6369
+ exports.set_log_callback = set_log_callback;
6342
6370
  exports.set_remote_log_functions = set_remote_log_functions;
6343
6371
  exports.set_timeout = set_timeout;
6344
6372
  exports.set_timeout_periodic = set_timeout_periodic;