log4js-node icon indicating copy to clipboard operation
log4js-node copied to clipboard

util.format options need

Open thegobot opened this issue 3 years ago • 1 comments

options to config... Can't change depth now

thegobot avatar Jan 15 '22 04:01 thegobot

@thegobot Would using JSON.stringify(myObject, null, 2) manually suffice?

Using your changes (hard-coded to depth=4)

const myObject = {"a":"a","b":{"c":"c","d":{"e":"e","f":{"g":"g","h":{"i":"i","j":{"k":"k"}}}}}};

const log4js = require("log4js");
const logger = log4js.getLogger();
logger.level = "debug";
logger.debug(myObject);
[2022-01-16T02:30:16.495] [DEBUG] default - {
  a: 'a',
  b: {
    c: 'c',
    d: { e: 'e', f: { g: 'g', h: { i: 'i', j: [Object] } } }
  }
}

Using original code

const myObject = {"a":"a","b":{"c":"c","d":{"e":"e","f":{"g":"g","h":{"i":"i","j":{"k":"k"}}}}}};

const log4js = require("log4js");
const logger = log4js.getLogger();
logger.level = "debug";
logger.debug(myObject);
logger.debug(JSON.stringify(myObject, null, 2));              // manual

const util = require("util");
logger.debug(util.formatWithOptions({ depth: 5 }, myObject)); // manual
[2022-01-16T02:24:44.084] [DEBUG] default - { a: 'a', b: { c: 'c', d: { e: 'e', f: [Object] } } }
[2022-01-16T02:23:54.991] [DEBUG] default - {
  "a": "a",
  "b": {
    "c": "c",
    "d": {
      "e": "e",
      "f": {
        "g": "g",
        "h": {
          "i": "i"
          "j": {
            "k": "k"
          }
        }
      }
    }
  }
}
[2022-01-16T21:31:13.805] [DEBUG] default - {
  a: 'a',
  b: {
    c: 'c',
    d: {
      e: 'e',
      f: { g: 'g', h: { i: 'i', j: { k: 'k' } } }
    }
  }
}

lamweili avatar Jan 15 '22 18:01 lamweili