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