@yuneta/gobj-js 7.26.16 → 7.26.18

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.
@@ -3207,11 +3207,7 @@ var LOG_BACKLOG_MAX = 600;
3207
3207
  var __log_backlog__ = [];
3208
3208
  function keep_in_backlog(level, msg, hora) {
3209
3209
  let m = msg;
3210
- if (level === "json") try {
3211
- m = JSON.stringify(msg);
3212
- } catch (e) {
3213
- m = String(msg);
3214
- }
3210
+ if (level === "json") m = log_stringify(msg);
3215
3211
  __log_backlog__.push([
3216
3212
  level,
3217
3213
  m,
@@ -3287,7 +3283,7 @@ function set_remote_log_functions(remote_log_fn) {
3287
3283
  ************************************************************/
3288
3284
  function log_stringify(v) {
3289
3285
  try {
3290
- return JSON.stringify(v);
3286
+ return JSON.stringify(v, (k, x) => typeof x === "bigint" ? x.toString() : x);
3291
3287
  } catch (e) {
3292
3288
  try {
3293
3289
  return String(v);
@@ -3316,13 +3312,19 @@ function format_log(format) {
3316
3312
  if (typeof format === "string") {
3317
3313
  if (args.length === 1) return format;
3318
3314
  let i = 1;
3319
- output = format.replace(/%[sdifoO]/g, (match) => {
3315
+ output = format.replace(/%[sdifoOj%]/g, (match) => {
3316
+ if (match === "%%") return "%";
3320
3317
  const val = args[i++];
3321
3318
  switch (match) {
3322
3319
  case "%s": return log_string(val);
3323
3320
  case "%d":
3324
- case "%i": return log_number(parseInt, val);
3325
- case "%f": return log_number(parseFloat, val);
3321
+ case "%i":
3322
+ if (typeof val === "bigint") return val.toString();
3323
+ return log_number(parseInt, val);
3324
+ case "%f":
3325
+ if (typeof val === "bigint") return val.toString();
3326
+ return log_number(parseFloat, val);
3327
+ case "%j": return log_stringify(val);
3326
3328
  case "%o":
3327
3329
  case "%O": return typeof val === "object" ? log_stringify(val) : log_string(val);
3328
3330
  default: return match;
@@ -3333,15 +3335,29 @@ function format_log(format) {
3333
3335
  } else output = args.map((arg) => typeof arg === "object" ? log_stringify(arg) : log_string(arg)).join(" ");
3334
3336
  return output;
3335
3337
  }
3338
+ var __in_log_function__ = false;
3339
+ function call_log_function(fn, ...args) {
3340
+ if (__in_log_function__) return;
3341
+ __in_log_function__ = true;
3342
+ try {
3343
+ fn(...args);
3344
+ } catch (e) {
3345
+ try {
3346
+ _console.error("a log function threw:", e);
3347
+ } catch (e2) {}
3348
+ } finally {
3349
+ __in_log_function__ = false;
3350
+ }
3351
+ }
3336
3352
  function log_error(format, ...args) {
3337
3353
  let msg = format_log(format, ...args);
3338
3354
  let hora = current_timestamp();
3339
3355
  if (f_error) {
3340
3356
  if (f_error === _console.error) {
3341
- if (console_wants("error", msg)) f_error("%c" + hora + " ERROR: " + String(msg), "color:red");
3357
+ if (console_wants("error", msg)) call_log_function(f_error, "%c" + hora + " ERROR: " + String(msg), "color:red");
3342
3358
  } else {
3343
3359
  if (console_wants("error", msg)) _console.error("%c" + hora + " ERROR: " + String(msg), "color:red");
3344
- f_error(`${hora} ERROR: ${String(msg)}`);
3360
+ call_log_function(f_error, `${hora} ERROR: ${String(msg)}`);
3345
3361
  }
3346
3362
  }
3347
3363
  emit_log_callback("error", msg, hora);
@@ -3351,10 +3367,10 @@ function log_warning(format, ...args) {
3351
3367
  let hora = current_timestamp();
3352
3368
  if (f_warning) {
3353
3369
  if (f_warning === _console.warn) {
3354
- if (console_wants("warning", msg)) f_warning("%c" + hora + " WARNING: " + String(msg), "color:yellow");
3370
+ if (console_wants("warning", msg)) call_log_function(f_warning, "%c" + hora + " WARNING: " + String(msg), "color:yellow");
3355
3371
  } else {
3356
3372
  if (console_wants("warning", msg)) _console.warn("%c" + hora + " WARNING: " + String(msg), "color:yellow");
3357
- f_warning(`${hora} WARNING: ${String(msg)}`);
3373
+ call_log_function(f_warning, `${hora} WARNING: ${String(msg)}`);
3358
3374
  }
3359
3375
  }
3360
3376
  emit_log_callback("warning", msg, hora);
@@ -3363,7 +3379,7 @@ function log_info(format, ...args) {
3363
3379
  let msg = format_log(format, ...args);
3364
3380
  let hora = current_timestamp();
3365
3381
  if (f_info) {
3366
- if (console_wants("info", msg)) f_info("%c" + hora + " INFO: " + String(msg), "color:cyan");
3382
+ if (console_wants("info", msg)) call_log_function(f_info, "%c" + hora + " INFO: " + String(msg), "color:cyan");
3367
3383
  }
3368
3384
  emit_log_callback("info", msg, hora);
3369
3385
  }
@@ -3371,7 +3387,7 @@ function log_debug(format, ...args) {
3371
3387
  let msg = format_log(format, ...args);
3372
3388
  let hora = current_timestamp();
3373
3389
  if (f_debug) {
3374
- if (console_wants("debug", msg)) f_debug("%c" + hora + " DEBUG: " + String(msg), "color:silver");
3390
+ if (console_wants("debug", msg)) call_log_function(f_debug, "%c" + hora + " DEBUG: " + String(msg), "color:silver");
3375
3391
  }
3376
3392
  emit_log_callback("debug", msg, hora);
3377
3393
  }
@@ -3379,14 +3395,14 @@ function trace_msg(format, ...args) {
3379
3395
  let msg = format_log(format, ...args);
3380
3396
  let hora = current_timestamp();
3381
3397
  if (f_debug) {
3382
- if (console_wants("msg", msg)) f_debug("%c" + hora + " MSG: " + String(msg), "color:cyan");
3398
+ if (console_wants("msg", msg)) call_log_function(f_debug, "%c" + hora + " MSG: " + String(msg), "color:cyan");
3383
3399
  }
3384
3400
  emit_log_callback("msg", msg, hora);
3385
3401
  }
3386
3402
  function trace_json(jn, msg) {
3387
3403
  if (console_wants("json", msg)) {
3388
- if (msg) _console.warn("=====> " + msg);
3389
- _console.dir(jn);
3404
+ if (msg) call_log_function(_console.warn, "=====> " + log_string(msg));
3405
+ call_log_function(_console.dir, jn);
3390
3406
  }
3391
3407
  emit_log_callback("json", jn, current_timestamp());
3392
3408
  }