datalust/pino-seq

Support for sqelf

Closed this issue ยท 3 comments

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

Thanks @andymac4182! That's interesting - a pino stream that writes CLEF to the console would open up some deployment options ๐Ÿค”

It would also be interesting to look at field mappings in the GELF input, and that solution would probably have a few more uses... Will give it some thought!

This should now be resolved by datalust/seq-input-gelf#104

:D woo hoo! I think I remember why I logged this ๐Ÿ˜›