@yuneta/gobj-js 7.22.1 → 7.25.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.
@@ -2547,7 +2547,7 @@ function gobj_send_event(dst, event, kw, src) {
2547
2547
  if (__trace_machine_format__ === 1) trace_machine(sprintf("🔜 %s %s%s %s", event ? event : "", !dst.running ? "!!" : "", gobj_short_name(dst), state.state_name));
2548
2548
  else trace_machine(sprintf("🔃 mach(%s%s), st: %s, ev: %s, from(%s%s)", !dst.running ? "!!" : "", gobj_short_name(dst), state.state_name, event ? event : "", src && !src.running ? "!!" : "", gobj_short_name(src)));
2549
2549
  if (kw) {
2550
- if (tracea > 1) {
2550
+ if (__trace_gobj_ev_kw__(dst)) {
2551
2551
  if (json_object_size(kw)) trace_json(kw);
2552
2552
  }
2553
2553
  }
@@ -2788,7 +2788,7 @@ function gobj_subscribe_event(publisher, event, kw, subscriber) {
2788
2788
  json_array_append(subscriber.dl_subscribings, subs);
2789
2789
  if (__trace_gobj_subscriptions__(subscriber) || __trace_gobj_subscriptions__(publisher)) {
2790
2790
  trace_machine(sprintf("💜💜👍 subscribing event '%s', publisher '%s', subscriber %s", event ? event : "", gobj_short_name(publisher), gobj_short_name(subscriber)));
2791
- if (kw) trace_json(kw);
2791
+ if (kw && (__trace_gobj_ev_kw__(subscriber) || __trace_gobj_ev_kw__(publisher))) trace_json(kw);
2792
2792
  }
2793
2793
  if (publisher.gclass.gmt.mt_subscription_added) {
2794
2794
  let result = publisher.gclass.gmt.mt_subscription_added(publisher, subs);
@@ -2928,7 +2928,7 @@ function gobj_publish_event(publisher, event, kw) {
2928
2928
  if (tracea) {
2929
2929
  if (__trace_machine_format__ === 1) trace_machine(sprintf("🔝🔝 %s %s%s %s", event ? event : "", !publisher.running ? "!!" : "", gobj_short_name(publisher), publisher.current_state.state_name));
2930
2930
  else trace_machine(sprintf("🔝🔝 mach(%s%s^%s), st: %s, ev: %s%s%s", !publisher.running ? "!!" : "", gobj_gclass_name(publisher), gobj_name(publisher), publisher.current_state.state_name, "", event ? event : "", ""));
2931
- if (json_object_size(kw)) trace_json(kw);
2931
+ if (__trace_gobj_ev_kw__(publisher) && json_object_size(kw)) trace_json(kw);
2932
2932
  }
2933
2933
  if (publisher.gclass.gmt.mt_publish_event) {
2934
2934
  let topublish = publisher.gclass.gmt.mt_publish_event(publisher, event, kw);
@@ -2977,7 +2977,7 @@ function gobj_publish_event(publisher, event, kw) {
2977
2977
  if (tracea) {
2978
2978
  if (__trace_machine_format__ === 1) trace_machine(sprintf("🔝🔄 %s (%s) %s%s", event ? event : "", event ? event : "", !subscriber.running ? "!!" : "", gobj_short_name(subscriber)));
2979
2979
  else trace_machine(sprintf("🔝🔄 mach(%s%s), st: %s, ev: %s, from(%s%s)", !subscriber.running ? "!!" : "", gobj_short_name(subscriber), gobj_current_state(subscriber), event ? event : "", publisher && !publisher.running ? "!!" : "", gobj_short_name(publisher)));
2980
- if (json_object_size(kw2publish)) trace_json(kw2publish);
2980
+ if (__trace_gobj_ev_kw__(publisher) && json_object_size(kw2publish)) trace_json(kw2publish);
2981
2981
  }
2982
2982
  let ret_ = gobj_send_event(subscriber, event, kw2publish, publisher);
2983
2983
  if (ret_ < 0 && subs_flag & subs_flag_t.__own_event__) {
@@ -3065,8 +3065,38 @@ var f_warning = _console.warn;
3065
3065
  var f_info = _console.info;
3066
3066
  var f_debug = _console.debug;
3067
3067
  var __log_callback__ = null;
3068
+ var LOG_BACKLOG_MAX = 600;
3069
+ var __log_backlog__ = [];
3070
+ function keep_in_backlog(level, msg, hora) {
3071
+ let m = msg;
3072
+ if (level === "json") try {
3073
+ m = JSON.stringify(msg);
3074
+ } catch (e) {
3075
+ m = String(msg);
3076
+ }
3077
+ __log_backlog__.push([
3078
+ level,
3079
+ m,
3080
+ hora
3081
+ ]);
3082
+ if (__log_backlog__.length > LOG_BACKLOG_MAX) __log_backlog__.shift();
3083
+ }
3068
3084
  function set_log_callback(fn) {
3069
- __log_callback__ = typeof fn === "function" ? fn : null;
3085
+ fn = typeof fn === "function" ? fn : null;
3086
+ if (fn && fn !== __log_callback__) {
3087
+ __log_callback__ = fn;
3088
+ for (const [level, m, hora] of __log_backlog__.slice()) {
3089
+ let msg = m;
3090
+ if (level === "json") try {
3091
+ msg = JSON.parse(m);
3092
+ } catch (e) {
3093
+ msg = m;
3094
+ }
3095
+ __deliver_log__(level, msg, hora);
3096
+ }
3097
+ return;
3098
+ }
3099
+ __log_callback__ = fn;
3070
3100
  }
3071
3101
  var __console_output_enabled__ = true;
3072
3102
  function set_console_log_enabled(enabled) {
@@ -3087,6 +3117,11 @@ function console_wants(level, msg) {
3087
3117
  }
3088
3118
  var __in_log_callback__ = false;
3089
3119
  function emit_log_callback(level, msg, hora) {
3120
+ if (__in_log_callback__) return;
3121
+ keep_in_backlog(level, msg, hora);
3122
+ __deliver_log__(level, msg, hora);
3123
+ }
3124
+ function __deliver_log__(level, msg, hora) {
3090
3125
  if (__log_callback__ && !__in_log_callback__) {
3091
3126
  __in_log_callback__ = true;
3092
3127
  try {