pino-cloud-logging

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pino-cloud-logging

This package provides a [simple configuration][] to use with [Pino][] to make it adhere to Google Cloud Logging [structured logging][].

1.0.6
latest
Version published
Weekly downloads
9.1K
-18.42%
Maintainers
1
Weekly downloads
 
Created

Use Pino with Google Cloud Logging

This package provides a simple configuration to use with Pino to make it adhere to Google Cloud Logging structured logging.

Quickstart

yarn add pino-cloud-logging

When you initialize your Pino logging instance, you'll use our gcpLogOptions.

import Pino from 'pino';
import { gcpLogOptions } from 'pino-cloud-logging';

const logger = Pino(gcpLogOptions());

logger.info('Hello 👋');

You can extend the configuration provided by this package like this:

gcpLogOptions({
  level: 'INFO',
  // Options can be found here:
  // https://github.com/pinojs/pino/blob/master/docs/api.md#options
});

You can also provide some of the default context like this:

gcpLogOptions(
  {
    /* ... */
  },
  { serviceName: 'hello-world', version: '2020-01-01' },
);

If you want to provide insertId (or any other runtime data), you can add those with the mixin function.

gcpLogOptions(
  {
    /* ... */
  },
  { mixin: () => ({ insertId: randomUUID() }) },
);

Or even provide context from OpenTelemetry.

import { context, getSpan } from '@opentelemetry/api';
gcpLogOptions(
  {
    /* ... */
  },
  { mixin: () => getSpan(context.active())?.context() ?? {} },
);

FAQs

Package last updated on 03 Sep 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts