Giter Club home page Giter Club logo

Comments (8)

mcollina avatar mcollina commented on September 13, 2024

from pino-pretty.

smeijer avatar smeijer commented on September 13, 2024
  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": "[email protected]",
      "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": "[email protected]",
      "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": "[email protected]",
      "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.

from pino-pretty.

davidmarkclements avatar davidmarkclements commented on September 13, 2024

from pino-pretty.

smeijer avatar smeijer commented on September 13, 2024

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.

from pino-pretty.

smeijer avatar smeijer commented on September 13, 2024

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,
});

from pino-pretty.

mcollina avatar mcollina commented on September 13, 2024

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?

from pino-pretty.

voxpelli avatar voxpelli commented on September 13, 2024

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

from pino-pretty.

mcollina avatar mcollina commented on September 13, 2024

Would you like to send.a PR?

from pino-pretty.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.