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