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 support for ignore: * #82

Open
smeijer opened this issue Oct 21, 2019 · 8 comments
Open

add support for ignore: * #82

smeijer opened this issue Oct 21, 2019 · 8 comments

Comments

@smeijer
Copy link

smeijer commented Oct 21, 2019

Quite often I just want to print the message, not the data objects.

@mcollina
Copy link
Member

mcollina commented Oct 21, 2019 via email

@smeijer
Copy link
Author

smeijer commented Oct 21, 2019

  httpLogger.info(
    {
      method: req.method,
      path: req.url,
      referer: ref,
      user: req.user,
    },
    'http request %s: %s',
    req.method,
    req.url,
  );

This would output something like:

INFO  [18:29:08.552]: http request GET: /index.htm
    method: "GET"
    path: "/index.htm"
    referer: "http://localhost:3000/blog/ssfTKLgj58vc5fbYj/comment/ljrVbFMILabWQKV6o"
    user: {
      "id": "jWmre2l5sTAh3KfpQ",
      "username": "smeijer",
      "email": "john.doe@example.com",
      "ip_address": "127.0.0.1"
    }
INFO  [18:29:08.552]: http request GET: /favicon.ico
    method: "GET"
    path: "/favicon.ico"
    referer: "http://localhost:3000/blog/ssfTKLgj58vc5fbYj/comment/ljrVbFMILabWQKV6o"
    user: {
      "id": "jWmre2l5sTAh3KfpQ",
      "username": "smeijer",
      "email": "john.doe@example.com",
      "ip_address": "127.0.0.1"
    }
INFO  [18:29:08.552]: http request GET: /logo.png
    method: "GET"
    path: "/logo.png"
    referer: "http://localhost:3000/blog/ssfTKLgj58vc5fbYj/comment/ljrVbFMILabWQKV6o"
    user: {
      "id": "jWmre2l5sTAh3KfpQ",
      "username": "smeijer",
      "email": "john.doe@example.com",
      "ip_address": "127.0.0.1"
    }

Which is a bit much and hard to scan. We don't always need that detailed info in the console while developing. If I need the details, I'll make sure to hit a breakpoint. Simply logging the formatted message, would be more informative. I see the console more as a global overview of data streams. And use the debugger to dive into details.

So reducing that output to something like this (in NODE_ENV !== production), would be very helpful:

INFO  [18:29:08.552]: http request GET: /index.htm
INFO  [18:29:08.552]: http request GET: /favicon.ico
INFO  [18:29:08.552]: http request GET: /logo.png

Also, if info messages can be logged as a single line, errors would have less chance to be missed. I now get so much data at certain moments, that it's easy to miss the errors.

@davidmarkclements
Copy link
Member

davidmarkclements commented Oct 21, 2019 via email

@smeijer
Copy link
Author

smeijer commented Oct 22, 2019

I understand, and I agree.

But piping to pino-pretty is done willingly, correct? At least, I don't use pino-pretty on production. I only use it to format the messages during development, and than the suggestion I posted above would help.

@smeijer
Copy link
Author

smeijer commented Oct 22, 2019

Some additional context, an abstracted version of my logger configuration:

import pino from 'pino';
import noir from 'pino-noir';
import pico from 'picoid';

const base = {
  sid: pico(),
  hostname: process.env.HOST_NAME,
  appname: process.env.APP_NAME,
  instance: ~~process.env.INSTANCE_ID,
  release: process.env.VERSION,
};

const redact = noir([...], '***');

const prettyPrint = process.env.NODE_ENV === 'development'
  ? {
      colorize: true,
      levelFirst: true,
      translateTime: 'HH:MM:ss.l',
      ignore: 'sid,appname,instance,release,ns,headers',
    }
  : false;

const logger = pino({
  level: process.env.LOG_LEVEL || 'info',
  serializers: redact,
  base,
  prettyPrint,
});

@mcollina
Copy link
Member

Redaction is embedded in pino now, check out http://getpino.io/#/docs/redaction.

I’d be happy to support more customization to pino-pretty tbh, would you like to send a PR?

@voxpelli
Copy link

I'm +1 on this. Would be a great way to get an overview of the logs in a single terminal window, right now it can become quite few log lines if the log lines has quite many attributes

@mcollina
Copy link
Member

Would you like to send.a PR?

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

No branches or pull requests

4 participants