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