Skip to content
This repository has been archived by the owner on Apr 10, 2024. It is now read-only.
/ pino-noel Public archive

πŸ»β€β„οΈπŸŒ² Pino transport that roughly matches what I like to see in my logs. Comes with a JSON and pretty-formatted output.

License

Notifications You must be signed in to change notification settings

AugustArchive/pino-noel

Repository files navigation

πŸ»β€β„οΈπŸŒ² @augu/pino-transport

Noel's opinionated logging transport for Pino

@augu/pino-transport is an opinionated logging transport for the Pino logging library. This was made to not repeat what this library entails. If you like it, then install it with:

default formatter json formatter

$ npm i @augu/pino-transport
$ yarn add @augu/pino-transport
$ pnpm i @augu/pino-transport

Limitations

  • The library expects you to use msg instead anything set in the name options for pino().

Usage

import pino from 'pino';

const log = pino({
    transports: [
        {
            target: '@augu/pino-transport',
            options: {
                json: true
            }
        }
    ]
});

log.info('Hello, world!');

Custom Transports

You can create custom transports that the transport will transform the logs to. You will need to create a second file that will be serialized to the proper value instead of a plain object; related issue (pinojs/pino#262)

// transport.js
import noelPino, { BaseFormatter, type LogRecord } from '@augu/pino-transport';

class MyFormatter extends BaseFormatter {
    override transform(record: LogRecord) {
        return record.msg;
    }
}

export default (options) =>
    noelPino({
        ...options,
        transport: new MyFormatter()
    });

// main.js
import pino from 'pino';

const log = pino({
    transport: {
        target: './transport.js'
    }
});

log.info('Hello, world!');
// => "Hello, world!" is printed instead

Pino Serializers

This library also comes with custom serializers that I recommend setting in the serializers option when creating a root Pino logger since it will work better with the Default and Json formatters.

import { serializers } from '@augu/pino-transport';
import pino from 'pino';

const log = pino({
    serializers: {
        err: serializers.createErrorSerializer(),
        req: serializers.request,
        res: serializers.response
    }
});

log.info({ err: new Error('woof') }, 'waff');

In 1.3.0, the library provides a createSerializers method to create serializers type-safely:

import { createSerializers } from '@augu/pino-transport';
import pino from 'pino';

const log = pino({
    serializers: createSerializers({
        // Enables the request serializer for `request` from the log record.
        request: false,

        // Enables the response serializer for `response` from the log record.
        response: false,

        // Enables the error serializer for `error` from the log record.
        error: true,

        // List of easier-to-write names when passing in from the log
        // record.
        allow: {
            req: false,
            res: false,
            err: true
        }
    })
});

log.info({ err: new Error('woof') }, 'waff');

License

@augu/pino-transport is released under the MIT License with love by Noel!

About

πŸ»β€β„οΈπŸŒ² Pino transport that roughly matches what I like to see in my logs. Comes with a JSON and pretty-formatted output.

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •