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