Skip to content

Redact log #1609

@dayo09

Description

@dayo09

What?

Let's convert token printed on the console as asterisks for the sake of security.

(redact means to remove words or information from a text before it is printed or made available to the public)

How?

Use winston library (deprecated)

Use pino library (MIT license, published 2 months ago)

https://www.npmjs.com/package/pino

To use Pino in TypeScript, you can follow these steps:

  1. Install the Pino library and its corresponding types:
npm install pino @types/pino
  1. Import the necessary modules in your TypeScript file:
import pino from 'pino';
  1. Create a logger instance with the desired configuration:
const logger = pino({
  level: 'info', // Set the log level (e.g., info, error, debug)
  redact: ['token'], // Specify properties to redact (e.g., token)
  prettyPrint: true, // Enable pretty-printing of logs (optional)
});

In the above example, we're using the level option to set the log level. The redact option is used to specify properties to redact from log messages (e.g., "token"). You can customize these options based on your logging requirements.

  1. Use the logger instance to log your token:
const token = 'mySecretToken123';

logger.info({ token }, 'Received a token');

In this example, we're using the logger.info method to log the token. The token is passed as a property in the log object ({ token }).

Pino provides various features and options to further customize your logging experience. You can explore Pino's documentation (https://github.com/pinojs/pino) to learn more about its capabilities and how to adapt it to your specific use case.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions