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

CLI revamp #386

Merged
merged 13 commits into from
Apr 13, 2018
Merged

CLI revamp #386

merged 13 commits into from
Apr 13, 2018

Conversation

jsumners
Copy link
Member

@jsumners jsumners commented Apr 5, 2018

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 the master branch.

This PR:

  1. Removes the CLI completely and reduces core to just a logger
  2. Introduces the concept of Pino prettifier modules

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 an asMetaWrapper(destStream) method attached to it which returns a metadata API compatible stream object. This allows for users to do:

const log = require('pino')({
  prettyPrint: {
    someFooPrettifierOption: 'and-value'
  },
  prettifier: 'foo-prettifier'
})

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.

grbr and others added 5 commits April 3, 2018 13:42
pino.js Outdated
var prettyModule = opts.prettifier || 'pino-pretty'
try {
prettyFactory = require(prettyModule)
return prettyFactory(opts).asMetaWrapper(process.stdout)
Copy link
Member

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.

Copy link
Member Author

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)
Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense.

@davidmarkclements
Copy link
Member

davidmarkclements commented Apr 5, 2018

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:

  • a minimal CLI tool under the pino command name that does very minimal prettifying
  • OR a gatekeeping/signposting CLI under the pino command name that lists available prettifiers and installs on demand
  • OR a mixture of both

@mcollina
Copy link
Member

mcollina commented Apr 5, 2018

a minimal CLI tool under the pino command name that does very minimal prettifying

I'm -1 to that.

I think we can just ship a pino executable with pino-pretty

@jsumners
Copy link
Member Author

jsumners commented Apr 5, 2018

@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 prettyPrint option is to reduce the breakage. I just opted to make it a bit more robust and turn it into a full fledged API for generic prettifiers. This is basically a "reporters" feature like with tap or https://github.com/nuxt/consola#reporters .

Also, users have to actually read the documentation to learn how to do this. And we know how well they do that 😆

@davidmarkclements
Copy link
Member

we just got people used to the idea of piping to the pino command...

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.

@mcollina
Copy link
Member

mcollina commented Apr 5, 2018

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.

@jsumners
Copy link
Member Author

jsumners commented Apr 5, 2018

@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?

@davidmarkclements
Copy link
Member

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.
For instance, with pino-pretty we would achieve this like so:

npm i -g pino-pretty
node app.js | pino

Something to that effect, prioritizing command line based prettifying

@davidmarkclements
Copy link
Member

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)

@davidmarkclements
Copy link
Member

@mcollina based on my follow up, does my prior comment make any more sense?

@jsumners
Copy link
Member Author

jsumners commented Apr 5, 2018

@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
Copy link
Member

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?

Copy link
Member

@davidmarkclements davidmarkclements Apr 5, 2018

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"

Copy link
Member Author

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
Copy link
Member

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?

Copy link
Member Author

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:
Copy link
Member

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!)

Copy link
Member

@davidmarkclements davidmarkclements left a 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",
Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops. Fixed.

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. It's moved.

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@mcollina mcollina left a 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".

@jsumners
Copy link
Member Author

jsumners commented Apr 5, 2018

pino bin added. Result:

% node example.js|pino
`pino` cli is deprecated. Use `pino-pretty` cli instead.

@jsumners jsumners added this to the v5.0.0 milestone Apr 6, 2018
bin.js Outdated
@@ -0,0 +1,3 @@
#!/usr/bin/env node
console.error('`pino` cli is deprecated. Use `pino-pretty` cli instead.')
Copy link
Member

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.

@jsumners
Copy link
Member Author

jsumners commented Apr 6, 2018

@davidmarkclements are you satisfied with the state of this PR?

@lrlna
Copy link

lrlna commented Apr 10, 2018

oooh cool, i've had people asking for a programmatic interface on pino-colada, this will be useful! I am going to try this branch out with my module too ^__^

pino.js Outdated
}
try {
var prettyFactory = require('pino-pretty')
return prettyFactory(opts).asMetaWrapper(process.stdout)
Copy link
Member

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.

Copy link
Member Author

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).

@jsumners
Copy link
Member Author

The latest commit moves asMetaWrapper into Pino as an internal API and updates the doc/pretty.md accordingly. How does this look @mcollina and @davidmarkclements ?

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jsumners
Copy link
Member Author

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.

@jsumners jsumners merged commit 145e724 into next-major Apr 13, 2018
@jsumners jsumners deleted the cli-revamp branch April 13, 2018 12:11
@github-actions
Copy link

github-actions bot commented Feb 7, 2022

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants