@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.
@@ -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,
@@ -3289,7 +3285,7 @@ var gobjJs = (function(exports) {
3289
3285
  ************************************************************/
3290
3286
  function log_stringify(v) {
3291
3287
  try {
3292
- return JSON.stringify(v);
3288
+ return JSON.stringify(v, (k, x) => typeof x === "bigint" ? x.toString() : x);
3293
3289
  } catch (e) {
3294
3290
  try {
3295
3291
  return String(v);
@@ -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,29 @@ 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
+ var __in_log_function__ = false;
3341
+ function call_log_function(fn, ...args) {
3342
+ if (__in_log_function__) return;
3343
+ __in_log_function__ = true;
3344
+ try {
3345
+ fn(...args);
3346
+ } catch (e) {
3347
+ try {
3348
+ _console.error("a log function threw:", e);
3349
+ } catch (e2) {}
3350
+ } finally {
3351
+ __in_log_function__ = false;
3352
+ }
3353
+ }
3338
3354
  function log_error(format, ...args) {
3339
3355
  let msg = format_log(format, ...args);
3340
3356
  let hora = current_timestamp();
3341
3357
  if (f_error) {
3342
3358
  if (f_error === _console.error) {
3343
- if (console_wants("error", msg)) f_error("%c" + hora + " ERROR: " + String(msg), "color:red");
3359
+ if (console_wants("error", msg)) call_log_function(f_error, "%c" + hora + " ERROR: " + String(msg), "color:red");
3344
3360
  } else {
3345
3361
  if (console_wants("error", msg)) _console.error("%c" + hora + " ERROR: " + String(msg), "color:red");
3346
- f_error(`${hora} ERROR: ${String(msg)}`);
3362
+ call_log_function(f_error, `${hora} ERROR: ${String(msg)}`);
3347
3363
  }
3348
3364
  }
3349
3365
  emit_log_callback("error", msg, hora);
@@ -3353,10 +3369,10 @@ var gobjJs = (function(exports) {
3353
3369
  let hora = current_timestamp();
3354
3370
  if (f_warning) {
3355
3371
  if (f_warning === _console.warn) {
3356
- if (console_wants("warning", msg)) f_warning("%c" + hora + " WARNING: " + String(msg), "color:yellow");
3372
+ if (console_wants("warning", msg)) call_log_function(f_warning, "%c" + hora + " WARNING: " + String(msg), "color:yellow");
3357
3373
  } else {
3358
3374
  if (console_wants("warning", msg)) _console.warn("%c" + hora + " WARNING: " + String(msg), "color:yellow");
3359
- f_warning(`${hora} WARNING: ${String(msg)}`);
3375
+ call_log_function(f_warning, `${hora} WARNING: ${String(msg)}`);
3360
3376
  }
3361
3377
  }
3362
3378
  emit_log_callback("warning", msg, hora);
@@ -3365,7 +3381,7 @@ var gobjJs = (function(exports) {
3365
3381
  let msg = format_log(format, ...args);
3366
3382
  let hora = current_timestamp();
3367
3383
  if (f_info) {
3368
- if (console_wants("info", msg)) f_info("%c" + hora + " INFO: " + String(msg), "color:cyan");
3384
+ if (console_wants("info", msg)) call_log_function(f_info, "%c" + hora + " INFO: " + String(msg), "color:cyan");
3369
3385
  }
3370
3386
  emit_log_callback("info", msg, hora);
3371
3387
  }
@@ -3373,7 +3389,7 @@ var gobjJs = (function(exports) {
3373
3389
  let msg = format_log(format, ...args);
3374
3390
  let hora = current_timestamp();
3375
3391
  if (f_debug) {
3376
- if (console_wants("debug", msg)) f_debug("%c" + hora + " DEBUG: " + String(msg), "color:silver");
3392
+ if (console_wants("debug", msg)) call_log_function(f_debug, "%c" + hora + " DEBUG: " + String(msg), "color:silver");
3377
3393
  }
3378
3394
  emit_log_callback("debug", msg, hora);
3379
3395
  }
@@ -3381,14 +3397,14 @@ var gobjJs = (function(exports) {
3381
3397
  let msg = format_log(format, ...args);
3382
3398
  let hora = current_timestamp();
3383
3399
  if (f_debug) {
3384
- if (console_wants("msg", msg)) f_debug("%c" + hora + " MSG: " + String(msg), "color:cyan");
3400
+ if (console_wants("msg", msg)) call_log_function(f_debug, "%c" + hora + " MSG: " + String(msg), "color:cyan");
3385
3401
  }
3386
3402
  emit_log_callback("msg", msg, hora);
3387
3403
  }
3388
3404
  function trace_json(jn, msg) {
3389
3405
  if (console_wants("json", msg)) {
3390
- if (msg) _console.warn("=====> " + msg);
3391
- _console.dir(jn);
3406
+ if (msg) call_log_function(_console.warn, "=====> " + log_string(msg));
3407
+ call_log_function(_console.dir, jn);
3392
3408
  }
3393
3409
  emit_log_callback("json", jn, current_timestamp());
3394
3410
  }