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

Add option for single-line logging of extra attributes #97

Closed
zdila opened this issue Feb 5, 2020 · 9 comments · Fixed by #158
Closed

Add option for single-line logging of extra attributes #97

zdila opened this issue Feb 5, 2020 · 9 comments · Fixed by #158

Comments

@zdila
Copy link

zdila commented Feb 5, 2020

Logs with multiple extra attributes now take too many lines. Personally I prefer buynan formatting.

Example:

logger.info({ id: 22246537, type: 'story' }, 'Saving item.');

Current output with pino-pretty -t -i hostname,pid:

[2020-02-05 13:32:31.528 +0000] INFO : Saving item.
    id: 22246537
    type: "story"

Preferred output:

[2020-02-05 13:32:31.528 +0000] INFO : Saving item. { id: 22246537, type: "story" }
@mcollina
Copy link
Member

mcollina commented Feb 5, 2020 via email

@zdila
Copy link
Author

zdila commented Feb 5, 2020

Thanks. I can try.

@ritlew
Copy link

ritlew commented Aug 3, 2020

Can someone point me to some files/functions to get started on this feature?

@jsumners
Copy link
Member

jsumners commented Aug 3, 2020

pino-pretty/index.js

Lines 122 to 146 in 852fdf7

if (line.length > 0) {
line += EOL
}
if (log.type === 'Error' && log.stack) {
const prettifiedErrorLog = prettifyErrorLog({
log,
errorLikeKeys: errorLikeObjectKeys,
errorProperties: errorProps,
ident: IDENT,
eol: EOL
})
line += prettifiedErrorLog
} else {
const skipKeys = [messageKey, levelKey, timestampKey].filter(key => typeof log[key] === 'string' || typeof log[key] === 'number')
const prettifiedObject = prettifyObject({
input: log,
skipKeys,
customPrettifiers,
errorLikeKeys: errorLikeObjectKeys,
eol: EOL,
ident: IDENT
})
line += prettifiedObject
}

@gr2m
Copy link
Contributor

gr2m commented Aug 11, 2020

Is anyone working on this? I'd prefer the inline attributes, too! I can work on a PR, but wonder if there is some prior work on this?

@jsumners
Copy link
Member

It does not seem anyone is working on this.

@gr2m
Copy link
Contributor

gr2m commented Aug 21, 2020

I'm looking into it today

@gr2m
Copy link
Contributor

gr2m commented Aug 21, 2020

@mcollina would you like me to add an option or just change the default behavior?

I think this change would be a breaking change, but I do prefer the single line output. Maybe we can introduce a new option multiline and set it to true by default for the current version (4.x) to retain the current behavior, then with 5.0.0 we would change the default for that option to false?

@mcollina
Copy link
Member

Let's add the option and then discuss the default. I kind of prefer single-line as well, but it's semver major.

LucasPickering referenced this issue in MarkForged/pino-pretty Feb 26, 2021
LucasPickering referenced this issue in MarkForged/pino-pretty Feb 26, 2021
LucasPickering referenced this issue in MarkForged/pino-pretty Mar 1, 2021
mcollina pushed a commit that referenced this issue Mar 2, 2021
* test: multiline option

* Add singleLine option with tests (#97)

Co-authored-by: Gregor Martynus <gregor@martynus.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants