Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Text formatters truncate long strings and arrays #30

Closed
NfNitLoop opened this issue Feb 11, 2025 · 3 comments
Closed

Text formatters truncate long strings and arrays #30

NfNitLoop opened this issue Feb 11, 2025 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@NfNitLoop
Copy link

NfNitLoop commented Feb 11, 2025

I'm trying to log errors like this:

try {
   parse(bigXmlText)
} catch (e) {
    log.error("Error parsing XML: {xml}", {xml: bigXmlText})
    throw e
}

In Deno (v2.1.8), the big string gets rendered as a string literal, which breaks each line up into "{the line}\n" +

… but eventually it gets truncated with something like: ... 44575 more characters.

This also exhibits the error:

log.error(l => l`Error parsing XML: {$xml}`)

But just concatenating up-front avoids the issue:

log.error(`Error parsing XML: {$xml}`)

Up-front string concatenation isn't ideal, in case we want to disable a given log level. (If this were, say, debug level.)

@dahlia dahlia self-assigned this Feb 11, 2025
@dahlia dahlia added the bug Something isn't working label Feb 11, 2025
@dahlia dahlia changed the title defaultConsoleFormatter truncates long strings Text formatters truncates long strings Feb 11, 2025
@dahlia dahlia changed the title Text formatters truncates long strings Text formatters truncate long strings and arrays Feb 11, 2025
@dahlia
Copy link
Owner

dahlia commented Feb 11, 2025

Unfortunately, the truncation is processed by console.debug() and friends, which is built in the JavaScript runtime, hence we can't fix it. However, if you use other sinks than a console sink like a stream sink, you can work around this limitation.

@dahlia
Copy link
Owner

dahlia commented Feb 11, 2025

Turns out LogTape's built-in text formatters also behave in the similar way, so I'll fix it.

@dahlia
Copy link
Owner

dahlia commented Feb 11, 2025

Okay, now built-in text formatters no more truncate long strings and arrays. The fix was just shipped in v0.6.5, v0.7.2, and v0.8.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants