Skip to content

Pattern format for call stack using padding/truncation not working #955

@lheberlie

Description

@lheberlie

Thank you so much for enabling the call stack in the core branch.

Problem: I am having issues getting the padding and truncation working with %f, %l, and %o. When using truncation with %l and %o, there are fatal errors, however when using padding/truncation with %f there are no errors but it doesn't seem to be applying the padding/trunction.

Here is my log4js.config.json file.

{
  "appenders": {
    "console-appender": {
      "type": "console",
      "layout": {
        "type": "pattern",
        "pattern": "%[[%p]%] - %18.100f{2} | %7.12l:%7.12o - %[%m%]"
      }
    }
  },
  "categories": {
    "default": {
      "appenders": ["console-appender"],
      "enableCallStack": true,
      "level": "info"
    }
  }
}

Error:

/node_modules/log4js/lib/layouts.js:272
      return toTruncate.substring(0, len);
                        ^

TypeError: toTruncate.substring is not a function
    at truncate (/node_modules/log4js/lib/layouts.js:272:25)
    at truncateAndPad (/node_modules/log4js/lib/layouts.js:300:19)
    at /node_modules/log4js/lib/layouts.js:326:28
    at /node_modules/log4js/lib/appenders/console.js:6:16
    at /node_modules/log4js/lib/log4js.js:42:5
    at Array.forEach (<anonymous>)
    at sendLogEventToAppender (/node_modules/log4js/lib/log4js.js:41:21)
    at /node_modules/log4js/lib/clustering.js:23:26
    at Array.forEach (<anonymous>)
    at sendToListeners (/node_modules/log4js/lib/clustering.js:23:13)
    at Object.send (/node_modules/log4js/lib/clustering.js:89:7)
    at Logger._log (/node_modules/log4js/lib/logger.js:90:16)
    at Logger.log (/node_modules/log4js/lib/logger.js:73:12)
    at Logger.<computed> [as info] (/node_modules/log4js/lib/logger.js:124:10)
    at Object.<anonymous> (/bin/create-sample-code-thumbnails.js:108:10)

Additional details:

When I remove the truncation from %l and %o the code will work but it doesn't seem to be formatting correctly.

Resulting output

[INFO] - sample-code-helper/screenshot-helper.js | 631:16 - screenshot-helper - converting screenshots to thumbnails - end
[INFO] - sample-code-helper/screenshot-helper.js | 633:16 - screenshot-helper - screenshot time: 0 minutes, 37 seconds
[INFO] - sample-code-helper/screenshot-helper.js | 638:16 - screenshot-helper - end
[INFO] - bin/create-sample-code-thumbnails.js | 114:14 - create-thumbnails - end
[INFO] - sample-code-helper/screenshot-helper.js | 594:22 - screenshot-helper - created samples code screenshots archive: /build-screenshots/zips/4.14.zip
[INFO] - sample-code-helper/screenshot-helper.js | 598:22 - screenshot-helper - 4 screenshots in archive file in /build-screenshots/4.14

Desired output

[INFO] - sample-code-helper/screenshot-helper.js | 631:16 - screenshot-helper - converting screenshots to thumbnails - end
[INFO] - sample-code-helper/screenshot-helper.js | 633:16 - screenshot-helper - screenshot time: 0 minutes, 37 seconds
[INFO] - sample-code-helper/screenshot-helper.js | 638:16 - screenshot-helper - end
[INFO] -    bin/create-sample-code-thumbnails.js | 114:14 - create-thumbnails - end
[INFO] - sample-code-helper/screenshot-helper.js | 594:22 - screenshot-helper - created samples code screenshots archive: /build-screenshots/zips/4.14.zip
[INFO] - sample-code-helper/screenshot-helper.js | 598:22 - screenshot-helper - 4 screenshots in archive file in /build-screenshots/4.14

Thanks so much for this enhancement.

Related issue: add line number support #879

cc: @victor0801x @nomiddlename

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions