Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/simenandre/pino-cloud-logging
Pino configuration for Google Cloud Platform. Enabled structured logging!
https://github.com/simenandre/pino-cloud-logging
google-cloud-platform logging pino typescript
Last synced: about 1 month ago
JSON representation
Pino configuration for Google Cloud Platform. Enabled structured logging!
- Host: GitHub
- URL: https://github.com/simenandre/pino-cloud-logging
- Owner: simenandre
- License: apache-2.0
- Created: 2022-06-13T18:43:57.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-10-29T00:02:07.000Z (2 months ago)
- Last Synced: 2024-11-28T13:53:14.345Z (about 1 month ago)
- Topics: google-cloud-platform, logging, pino, typescript
- Language: TypeScript
- Homepage:
- Size: 201 KB
- Stars: 15
- Watchers: 2
- Forks: 0
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# 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][].[simple configuration]: src/main.ts
[pino]: https://github.com/pinojs/pino
[structured logging]: https://cloud.google.com/logging/docs/structured-logging## Quickstart
```bash
yarn add pino-cloud-logging
```When you initialize your Pino logging instance, you'll use our `gcpLogOptions`.
```typescript
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:
```typescript
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:
```typescript
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.```typescript
gcpLogOptions(
{
/* ... */
},
{ mixin: () => ({ insertId: randomUUID() }) },
);
```Or even provide context from OpenTelemetry.
```typescript
import { context, getSpan } from '@opentelemetry/api';
gcpLogOptions(
{
/* ... */
},
{ mixin: () => getSpan(context.active())?.context() ?? {} },
);
```