@yuneta/gobj-js 7.26.16 → 7.26.17

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,
@@ -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,24 @@
3337
3339
  } else output = args.map((arg) => typeof arg === "object" ? log_stringify(arg) : log_string(arg)).join(" ");
3338
3340
  return output;
3339
3341
  }
3342
+ function call_log_function(fn, ...args) {
3343
+ try {
3344
+ fn(...args);
3345
+ } catch (e) {
3346
+ try {
3347
+ _console.error("a log function threw:", e);
3348
+ } catch (e2) {}
3349
+ }
3350
+ }
3340
3351
  function log_error(format, ...args) {
3341
3352
  let msg = format_log(format, ...args);
3342
3353
  let hora = current_timestamp();
3343
3354
  if (f_error) {
3344
3355
  if (f_error === _console.error) {
3345
- if (console_wants("error", msg)) f_error("%c" + hora + " ERROR: " + String(msg), "color:red");
3356
+ if (console_wants("error", msg)) call_log_function(f_error, "%c" + hora + " ERROR: " + String(msg), "color:red");
3346
3357
  } else {
3347
3358
  if (console_wants("error", msg)) _console.error("%c" + hora + " ERROR: " + String(msg), "color:red");
3348
- f_error(`${hora} ERROR: ${String(msg)}`);
3359
+ call_log_function(f_error, `${hora} ERROR: ${String(msg)}`);
3349
3360
  }
3350
3361
  }
3351
3362
  emit_log_callback("error", msg, hora);
@@ -3355,10 +3366,10 @@
3355
3366
  let hora = current_timestamp();
3356
3367
  if (f_warning) {
3357
3368
  if (f_warning === _console.warn) {
3358
- if (console_wants("warning", msg)) f_warning("%c" + hora + " WARNING: " + String(msg), "color:yellow");
3369
+ if (console_wants("warning", msg)) call_log_function(f_warning, "%c" + hora + " WARNING: " + String(msg), "color:yellow");
3359
3370
  } else {
3360
3371
  if (console_wants("warning", msg)) _console.warn("%c" + hora + " WARNING: " + String(msg), "color:yellow");
3361
- f_warning(`${hora} WARNING: ${String(msg)}`);
3372
+ call_log_function(f_warning, `${hora} WARNING: ${String(msg)}`);
3362
3373
  }
3363
3374
  }
3364
3375
  emit_log_callback("warning", msg, hora);
@@ -3367,7 +3378,7 @@
3367
3378
  let msg = format_log(format, ...args);
3368
3379
  let hora = current_timestamp();
3369
3380
  if (f_info) {
3370
- if (console_wants("info", msg)) f_info("%c" + hora + " INFO: " + String(msg), "color:cyan");
3381
+ if (console_wants("info", msg)) call_log_function(f_info, "%c" + hora + " INFO: " + String(msg), "color:cyan");
3371
3382
  }
3372
3383
  emit_log_callback("info", msg, hora);
3373
3384
  }
@@ -3375,7 +3386,7 @@
3375
3386
  let msg = format_log(format, ...args);
3376
3387
  let hora = current_timestamp();
3377
3388
  if (f_debug) {
3378
- if (console_wants("debug", msg)) f_debug("%c" + hora + " DEBUG: " + String(msg), "color:silver");
3389
+ if (console_wants("debug", msg)) call_log_function(f_debug, "%c" + hora + " DEBUG: " + String(msg), "color:silver");
3379
3390
  }
3380
3391
  emit_log_callback("debug", msg, hora);
3381
3392
  }
@@ -3383,14 +3394,14 @@
3383
3394
  let msg = format_log(format, ...args);
3384
3395
  let hora = current_timestamp();
3385
3396
  if (f_debug) {
3386
- if (console_wants("msg", msg)) f_debug("%c" + hora + " MSG: " + String(msg), "color:cyan");
3397
+ if (console_wants("msg", msg)) call_log_function(f_debug, "%c" + hora + " MSG: " + String(msg), "color:cyan");
3387
3398
  }
3388
3399
  emit_log_callback("msg", msg, hora);
3389
3400
  }
3390
3401
  function trace_json(jn, msg) {
3391
3402
  if (console_wants("json", msg)) {
3392
- if (msg) _console.warn("=====> " + msg);
3393
- _console.dir(jn);
3403
+ if (msg) call_log_function(_console.warn, "=====> " + log_string(msg));
3404
+ call_log_function(_console.dir, jn);
3394
3405
  }
3395
3406
  emit_log_callback("json", jn, current_timestamp());
3396
3407
  }