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

Logging multiple lines with a single call. Not possible? #18

Open
webJose opened this issue Aug 19, 2022 · 5 comments
Open

Logging multiple lines with a single call. Not possible? #18

webJose opened this issue Aug 19, 2022 · 5 comments
Assignees
Labels

Comments

@webJose
Copy link

webJose commented Aug 19, 2022

Hello, me again.

I have a simple task that eludes me, and I don't know if the reason is this package or a limitation in cosole, or what.

I want to output using log.warn() a multi-line string. Especifically, the stack trace of an error object. I want it output in different lines, but all I can get is a single line with \n embeeded in it.

Is there a wait to output multiple lined-values from this package? If so, may I trouble you for the how?

Thank you.

@medikoo
Copy link
Owner

medikoo commented Aug 22, 2022

@webJose this library doesn't limit in any way multi-lline output, you may confirm with log.warn(new Error().stack) (and log-node writer) that multiple lines will be outputted.

@webJose
Copy link
Author

webJose commented Aug 22, 2022

Hi again. The problem comes when a fomatter is specified:

log.warn('%s', new Error().stack);

@medikoo
Copy link
Owner

medikoo commented Aug 22, 2022

@webJose indeed. It's actually on purpose, to meaningfully isolate arbitrary string input (it follows what Node.js does with utils.inspect). Still if not desired you can escape that behavior, see last point in documentation of formatter that log-node relies on: https://github.com/medikoo/cli-sprintf-format#cli-dedicated-sprintf-formatter

@webJose
Copy link
Author

webJose commented Aug 22, 2022

Ah, yes %#s does the trick, but loses the coloring. Any way to retain coloring?

@medikoo
Copy link
Owner

medikoo commented Aug 22, 2022

In this case, string is treated as raw text (as if it's part of the first string argument), so eventual extra coloring, if needed should be added manually

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants