-
Notifications
You must be signed in to change notification settings - Fork 876
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
CLI revamp #386
CLI revamp #386
Conversation
pino.js
Outdated
var prettyModule = opts.prettifier || 'pino-pretty' | ||
try { | ||
prettyFactory = require(prettyModule) | ||
return prettyFactory(opts).asMetaWrapper(process.stdout) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we might as well include asMetaWrapper in here instead. I do not see a reason why a prettifier might not want that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand this statement. Can you reword to clarify?
pino.js
Outdated
var prettyFactory | ||
var prettyModule = opts.prettifier || 'pino-pretty' | ||
try { | ||
prettyFactory = require(prettyModule) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would not require a string, but rather support a function (the factory) or true. If true, we can then require.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense.
this is a great piece of work @jsumners I think we want to be careful not to implicitly direct users to opt for in-process prettifying unless they have no option but to do so I think we also need:
|
I'm -1 to that. I think we can just ship a |
@davidmarkclements I agree with @mcollina. The point here is that including the CLI in the core logger wasn't such a great plan. The reason for maintaining the Also, users have to actually read the documentation to learn how to do this. And we know how well they do that 😆 |
we just got people used to the idea of piping to the if we no longer bundle (and I'm not for bundling pino-pretty btw), then were setting up a learning flow where users will assume the right thing to do is use the programmatic API with pino-pretty or other prettifier. |
I do not understand. |
@davidmarkclements do you think re-wording https://github.com/pinojs/pino/blob/d7d52a1ce23be1096be3268346bed81b5d9d1b51/docs/pretty.md#example would solve the issue? If so, what should it say? |
I think we add a section right at the beginning, something to the effect of We never want to prettify in production. The best way to prettify is to do so in a separate process and pipe the log output to that process. This precludes any need to have separate development/production logger configurations, and familiarizes us with the concept of always processing log output in a separate process. The recommended way to prettify is to install a prettifier, and pipe output to it. npm i -g pino-pretty
Something to that effect, prioritizing command line based prettifying |
and probably put that in the main readme as well, then for programatic usage link to the pretty doc (which also enforces command line piping) |
@mcollina based on my follow up, does my prior comment make any more sense? |
@davidmarkclements I just pushed up a change that, without even having read your suggestion 🙂, includes a primary example of piping. Give it a review. Also, feel free to push up your ideas to this branch. |
module like [`pino-pretty`][pp]: | ||
|
||
```sh | ||
$ cat app.log | pino-pretty |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are we going with pino-pretty
, or pino
since it's default prettifer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we add a line to the effect of "For almost all situations, this is the recommended way to log. The programmatic API is mostly for integration purposes of other CLI based prettifiers"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At the moment, pino-pretty
does not have a pino
bin definition. I'm rather hesitant to add one as well. I don't want to set a precedent that prettifier modules can define the pino
binary.
docs/pretty.md
Outdated
|
||
## Prettifier API | ||
|
||
Pino prettifier modules are extra modules that provide a CLI for parsing ndJSON |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this a consistent presentation? "ndJSON" – is that how we case it elsewhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose nd
should be capitalized. https://github.com/ndjson/ndjson-spec
docs/pretty.md
Outdated
|
||
## Example | ||
|
||
To use pretty printing in your project: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a caveat here would be good (e.g. BUT PIPE INSTEAD!)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
awesome, can we stick something in the readme, a very quick example of prettifying (purely in the CLI)
@@ -64,6 +61,7 @@ | |||
"fresh-require": "^1.0.3", | |||
"log": "^1.4.0", | |||
"loglevel": "^1.6.1", | |||
"pino-pretty": "^1.0.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can remove chalk from dependencies.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops. Fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto for split2
. But it still has to be a dev dependency, I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. It's moved.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should still provide a pino
bin and exit the process with an error, saying to install "pino-pretty".
% node example.js|pino
`pino` cli is deprecated. Use `pino-pretty` cli instead. |
bin.js
Outdated
@@ -0,0 +1,3 @@ | |||
#!/usr/bin/env node | |||
console.error('`pino` cli is deprecated. Use `pino-pretty` cli instead.') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't deprecated mean that something is still working but it's discouraged to use?
I'd change the message in here to 'pino' cli got removed. Use 'pino-pretty' cli instead.
A link to https://www.npmjs.com/package/pino-pretty could also be useful.
@davidmarkclements are you satisfied with the state of this PR? |
oooh cool, i've had people asking for a programmatic interface on |
pino.js
Outdated
} | ||
try { | ||
var prettyFactory = require('pino-pretty') | ||
return prettyFactory(opts).asMetaWrapper(process.stdout) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you move asMetaWrapper
in this repository? I don't think it would be needed at all in pino-pretty
itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I intend to when I get back to this later this week (maybe sometime today).
The latest commit moves |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
I think at this point @davidmarkclements issue has been addressed. If not, we can fix it before final v5.0.0 release. I'm merging this. |
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Here it is: the "revamp" of the CLI. Or rather, the complete removal of it. Notice that the target branch of this PR is the
next-major
branch not themaster
branch.This PR:
Prettifier Modules
A prettifier module is one like
pino-pretty
. Such modules export a factory function that accepts a configuration object. That function returns a formatter function that can accept an ndJSON log line or a Pino log object. That function also includes anasMetaWrapper(destStream)
method attached to it which returns a metadata API compatible stream object. This allows for users to do:This means people like @lrlna could update their awesome modules to be used directly in-process. 🎉
Semver Major 🚨🚨🚨 😱
I realize we would prefer not to issue a new major. But we have a few things queued up just waiting for us to be brave enough for a new major -- https://github.com/pinojs/pino/projects/1 . The majority of the recent issues deal with the prettifier and CLI. Those are not the problems Pino strives to solve. So by removing them from core and issuing a new major version we will be reducing Pino down to its purpose: generate logs. And I think the logger features are mature enough that v5.y.z will be with us for a long time: we just have to make sure the prettifier API is solid.