@parade/utils

Pino out-of-process transport which takes Pino logs and maps them to Stackdriver logs, e.g.

Usage no npm install needed!

<script type="module">
  import paradeUtils from 'https://cdn.skypack.dev/@parade/utils';
</script>

README

@parade/utils

pino-stackdriver

Pino out-of-process transport which takes Pino logs and maps them to Stackdriver logs, e.g.

node ./server.js | ./node_modules/@parade/utils/src/pino-stackdriver/pino-stackdriver.js

express-verror-middleware

Express error middleware which picks off and sends status and code from a VError and returns a standard JSON response body, e.g.

NOTE: The message and stack traces are masked in production, apps should use 'code' for programmatic error handling.

import express from 'express';
import VError from 'verror';
import { verrorMiddleware } from '@parade/utils';

const app = express();

app.use((req, res, next) => {
  const cause = new Error('Uh oh');
  next(
    new VError(
      { cause, info: { status: 401, code: 'UNAUTHORIZED' } },
      'Failed request'
    )
  );
});

app.use(verrorMiddleware());

app.listen(6060);

// curl http://localhost:6060

// NODE_ENV !== 'production'
// {
//     errors: [{
//         code: 'UNAUTHORIZED',
//         message: 'Failed request: Uh oh',
//         stack: 'VError etc. etc.' // Includes nested verror stack traces
//     }]
// }

// NODE_ENV === 'production'
// {
//     errors: [{
//         code: 'UNAUTHORIZED',
//         message: 'Something went wrong',
//     }]
// }

logger

Light wrapper around Pino logger to simplify the API. https://github.com/pinojs/pino/issues/579

import { createLogger } from '@parade/utils';

const logger = createLogger({
  name: 'orders',
});

logger.info('A simple log message');
logger.info({ foo: 'bar' }, 'A simple log message with meta');
logger.info({ foo: 'bar' }); // message is always optional
logger.info(
  {
    err: new Error('Something went wrong'),
    foo: 'bar',
  },
  '`meta.err` will serialize `Error` objects, including stack traces'
);
logger.info(
  {
    req: new ClientRequest('https://paradeworld.com'),
    foo: 'bar',
  },
  '`meta.req` will serialize `ClientRequest` objects'
);
logger.info(
  {
    res: new ServerResponse(),
    foo: 'bar',
  },
  '`meta.res` will serialize `ServerResponse` objects'
);
logger.info(new Error(), '`Error` objects can be passed in directly');
logger.info(
  new ClientRequest('https://paradeworld.com'),
  '`ClientRequest` objects can be passed in directly'
);
logger.info(
  new ServerResponse(),
  '`ServerResponse` objects can be passed in directly'
);