@yuneta/gobj-js 7.13.5 → 7.13.7

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,7 +387,7 @@
387
387
  function tab() {
388
388
  return " ".repeat(Math.max(1, __inside__ * 2));
389
389
  }
390
- var __trace_machine_format__ = 0;
390
+ var __trace_machine_format__ = 1;
391
391
  function gobj_set_trace_machine_format(format) {
392
392
  __trace_machine_format__ = Number(format) === 1 ? 1 : 0;
393
393
  }
@@ -3019,6 +3019,19 @@
3019
3019
  function set_console_log_enabled(enabled) {
3020
3020
  __console_output_enabled__ = enabled ? true : false;
3021
3021
  }
3022
+ var __console_log_filter__ = null;
3023
+ function set_console_log_filter(fn) {
3024
+ __console_log_filter__ = typeof fn === "function" ? fn : null;
3025
+ }
3026
+ function console_wants(level, msg) {
3027
+ if (!__console_output_enabled__) return false;
3028
+ if (!__console_log_filter__) return true;
3029
+ try {
3030
+ return __console_log_filter__(level, msg) ? true : false;
3031
+ } catch (e) {
3032
+ return true;
3033
+ }
3034
+ }
3022
3035
  var __in_log_callback__ = false;
3023
3036
  function emit_log_callback(level, msg, hora) {
3024
3037
  if (__log_callback__ && !__in_log_callback__) {
@@ -3066,9 +3079,9 @@
3066
3079
  let hora = current_timestamp();
3067
3080
  if (f_error) {
3068
3081
  if (f_error === _console.error) {
3069
- if (__console_output_enabled__) f_error("%c" + hora + " ERROR: " + String(msg), "color:red");
3082
+ if (console_wants("error", msg)) f_error("%c" + hora + " ERROR: " + String(msg), "color:red");
3070
3083
  } else {
3071
- if (__console_output_enabled__) _console.error("%c" + hora + " ERROR: " + String(msg), "color:red");
3084
+ if (console_wants("error", msg)) _console.error("%c" + hora + " ERROR: " + String(msg), "color:red");
3072
3085
  f_error(`${hora} ERROR: ${String(msg)}`);
3073
3086
  }
3074
3087
  }
@@ -3079,9 +3092,9 @@
3079
3092
  let hora = current_timestamp();
3080
3093
  if (f_warning) {
3081
3094
  if (f_warning === _console.warn) {
3082
- if (__console_output_enabled__) f_warning("%c" + hora + " WARNING: " + String(msg), "color:yellow");
3095
+ if (console_wants("warning", msg)) f_warning("%c" + hora + " WARNING: " + String(msg), "color:yellow");
3083
3096
  } else {
3084
- if (__console_output_enabled__) _console.warn("%c" + hora + " WARNING: " + String(msg), "color:yellow");
3097
+ if (console_wants("warning", msg)) _console.warn("%c" + hora + " WARNING: " + String(msg), "color:yellow");
3085
3098
  f_warning(`${hora} WARNING: ${String(msg)}`);
3086
3099
  }
3087
3100
  }
@@ -3091,7 +3104,7 @@
3091
3104
  let msg = format_log(format);
3092
3105
  let hora = current_timestamp();
3093
3106
  if (f_info) {
3094
- if (__console_output_enabled__) f_info("%c" + hora + " INFO: " + String(msg), "color:cyan");
3107
+ if (console_wants("info", msg)) f_info("%c" + hora + " INFO: " + String(msg), "color:cyan");
3095
3108
  }
3096
3109
  emit_log_callback("info", msg, hora);
3097
3110
  }
@@ -3099,7 +3112,7 @@
3099
3112
  let msg = format_log(format);
3100
3113
  let hora = current_timestamp();
3101
3114
  if (f_debug) {
3102
- if (__console_output_enabled__) f_debug("%c" + hora + " DEBUG: " + String(msg), "color:silver");
3115
+ if (console_wants("debug", msg)) f_debug("%c" + hora + " DEBUG: " + String(msg), "color:silver");
3103
3116
  }
3104
3117
  emit_log_callback("debug", msg, hora);
3105
3118
  }
@@ -3107,12 +3120,12 @@
3107
3120
  let msg = format_log(format);
3108
3121
  let hora = current_timestamp();
3109
3122
  if (f_debug) {
3110
- if (__console_output_enabled__) f_debug("%c" + hora + " MSG: " + String(msg), "color:cyan");
3123
+ if (console_wants("msg", msg)) f_debug("%c" + hora + " MSG: " + String(msg), "color:cyan");
3111
3124
  }
3112
3125
  emit_log_callback("msg", msg, hora);
3113
3126
  }
3114
3127
  function trace_json(jn, msg) {
3115
- if (__console_output_enabled__) {
3128
+ if (console_wants("json", msg)) {
3116
3129
  if (msg) window.console.warn("=====> " + msg);
3117
3130
  window.console.dir(jn);
3118
3131
  }
@@ -6864,6 +6877,7 @@
6864
6877
  exports.sdata_flag_t = sdata_flag_t;
6865
6878
  exports.send_http_json_post = send_http_json_post;
6866
6879
  exports.set_console_log_enabled = set_console_log_enabled;
6880
+ exports.set_console_log_filter = set_console_log_filter;
6867
6881
  exports.set_log_callback = set_log_callback;
6868
6882
  exports.set_remote_log_functions = set_remote_log_functions;
6869
6883
  exports.set_timeout = set_timeout;