Code Monkey home page Code Monkey logo

pino-seq's People

Contributors

andymac4182 avatar balazsorban44 avatar dependabot[bot] avatar ewisuri avatar larenelg avatar liammclennan avatar nblumhardt avatar ngbrown avatar simihartstein avatar spragalas avatar tsimbalar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

pino-seq's Issues

pino-seq does not log errors along with an object

Since pino-seq does not have issues section I'm submitting this issue here. The project owner of pino-seq is @simihartstein.

Please see comments below:

import pino from 'pino';
import pinoToSeq from 'pino-seq';
const seqStream = pinoToSeq.createStream({
  serverUrl: 'http://localhost:5341',
});

const log = pino({ level: 'info'}, seqStream);
const err = new Error('Some error occurred.');

log.error(err); // works OK, but can't add additional meta data

log.error({ err }); // does not log any error info

log.error({ err, meta: 'aaa' }); // does not log any error info, only adds meta

// The only way I found to log error info with additional meta data is this:
log.error({ stack: err.stack, type: err.name, meta: 'aaa' }, err.message);

Note that the log.error({ err }) syntax is recommended by pino author but it doesn't work with pino-seq. This could be related to an issue with seq-logging that is used by pino-seq.

Fail gracefully, if connection to seq fails

Hi!

We use pino-seq together with pino in our Next.js app to log errors to Seq. Today, an error occurred in our Seq server, which made the connection between our app and Seq fail with the following error:

2020-11-19T07:41:47.743700409Z events.js:306 2020-11-19T07:41:47.743785314Z throw err;
// Unhandled 'error' event 2020-11-19T07:41:47.743803315Z ^ 2020-11-19T07:41:47.743807616Z
2020-11-19T07:41:47.743811616Z Error [ERR_UNHANDLED_ERROR]: Unhandled error.
('HTTP log shipping failed: 502') 2020-11-19T07:41:47.743815916Z at PinoSeqStream.emit (events.js:304:17)
2020-11-19T07:41:47.743819816Z at emitErrorNT (internal/streams/destroy.js:92:8) 
2020-11-19T07:41:47.743823717Z at emitErrorAndCloseNT (internal/streams/destroy.js:60:3) 
2020-11-19T07:41:47.743827917Z at processTicksAndRejections (internal/process/task_queues.js:84:21) 
{
 2020-11-19T07:41:47.743831817Z code: 'ERR_UNHANDLED_ERROR',
2020-11-19T07:41:47.743835517Z context: 'HTTP log shipping failed: 502' 2020-11-19T07:41:47.743839318Z } 2020-11-19T07:41:47.763250218Z error Command failed with exit code 1.
2020-11-19T07:41:47.763348224Z info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

This crashed our whole Next.js app.

After some digging, I see that the onError method will always call this.destroy, implemented here:

this.destroy(e);

So users cannot remove this. I was wondering if it was a deliberate choice, and if so, what is the explanation? Would it be possible to make the onError totally overrideable such that connection errors to Seq will not crash our entire app?

My current solution was to override the destroy method of the stream like so:

  const stream = pinoToSeq.createStream({
    apiKey: process.env.SEQ_API_KEY,
    serverUrl: process.env.SEQ_SERVER_URL,
  })

  /**
   * HACK: https://nodejs.org/api/stream.html#stream_writable_destroy_error
   * should not be overriden, but pino-seq wants to destroy if connection to seq fails.
   */
  stream.destroy = console.error

but the Node.js docs tells me I should not do that.

README: Updating default branch of local clones to `main` from 17 Jun, 2020

If you have a fork or local clone from before 17 June 2020, you will need to run the following commands to update your forked/cloned repo.

git checkout master
git branch -m master main
git fetch
git branch --unset-upstream
//if fork: git push -u origin main
git branch -u origin/main
git symbolic-ref refs/remotes/origin/HEAD refs/remotes/origin/main

Support for sqelf

Hi,

I am looking at setting this up for an application and using gelf as a way to capture all logs from the container and capture the pino logs along with them. Using pino by default it logged a blank message template with a property of msg and the rest of the properties from the log line as properties of the log message.

After copying PinoSeqStream into my app and updating it to write to console and use the CLEF property names matching https://github.com/datalust/sqelf/blob/6b9682dda3735294057f654e0ca6ddfafc480db7/sqelf/src/process/clef.rs#L28-L57 I started to get all the right logs and properties.

Should we look at a writable as part of this library.

Unfortunately some messages are written to console by other libraries that I don't have control over in json format that don't get read correctly.

image

This might be a potentially better fix to offer configuration or a more lax set of options in https://github.com/datalust/sqelf

class PinoSeqStream extends stream.Writable {
  constructor() {
    super();
  }

  _write(message, _enc, cb) {
    if (message) {
      try {
        const eventCopy = JSON.parse(message);

        const { time, level, msg, err, error, stack, ...props } = eventCopy;

        // Get the properties from the error
        const { message: errMessage, stack: errStack, ...errorProps } = err || error || {};

        const forSeq = {
          "@t": new Date(time),
          "@l": LEVEL_NAMES[level],
          "@mt": msg || errMessage,
          "@x": stack || errStack,
          ...errorProps,
          ...props
        };

        try {
          console.log(JSON.stringify(forSeq));
        } catch (errorMessage) {
          console.error(errorMessage);
        }
      } catch (err) {
        const msg = String(message);
        console.error(msg);
      }
    }
    cb();
  }
}

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.