@yuneta/gobj-js 7.22.1 → 7.22.2

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