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