Giter Club home page Giter Club logo

Comments (6)

mcollina avatar mcollina commented on September 28, 2024 1

@dtothefp side note, you should really not use bind, it is super slow. Wrap the other call inside a function.

from pino.

dtothefp avatar dtothefp commented on September 28, 2024

I hacked around this by creating multiple Pino instances. Seems sloppy, wondering if there is a better way?

const serializers = pino.stdSerializers;
const name = APP_NAME;

if (LOG_ENV === 'development' || NODE_ENV === 'development') {
  const pretty = pino.pretty();

  pretty.pipe(process.stdout);

  logger = pino({
    name,
    level: 'info',
    serializers
  }, pretty);
} else {
  const noop = arg => arg;
  const streams = [
    {
      level: 'warn',
      path: path.join(LOG_DIRECTORY, `${APP_NAME}-warn.log`)
    },
    {
      level: 'error',
      path: path.join(LOG_DIRECTORY, `${APP_NAME}-error.log`)
    }
  ];

  logger = streams.reduce((acc, data) => {
    const {level, path: logPath} = data;
    const writeStream = fs.createWriteStream(logPath, {
      flags: 'a',
      encoding: 'utf8'
    });
    const inst = pino({
      name,
      level,
      serializers
    }, writeStream);

    acc[level] = inst[level].bind(inst);

    return acc;
  }, {});

  logger.info = noop;
}

from pino.

davidmarkclements avatar davidmarkclements commented on September 28, 2024

Hi @dtothefp

The "pino way" is to avoid any in-process overhead - only having one output stream is entirely deliberate - any other log processing should be done out-of-process

So what we'd need is

node app.js | pino-split-by-log-type 

This ties into https://github.com/mcollina/pino#how-to-use-transports-with-pino

Currently, we don't have pino-split-by-log-type, but if you're up for building it, here's some transports you can take inspiration from

Let me know if you'd like to build it, and I'll support you (just open issues on your own repo and cc me (and Matteo) and we'll give feedback etc)

from pino.

dtothefp avatar dtothefp commented on September 28, 2024

@davidmarkclements thanks for the tips, if I get some time I will definitely try to work on this

from pino.

dtothefp avatar dtothefp commented on September 28, 2024

@mcollina good call, didn't know bind was slower

from pino.

github-actions avatar github-actions commented on September 28, 2024

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

from pino.

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.