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