Samsung / ONE-vscode

Visual Studio Code Extension of ONE compiler toolchain
Apache License 2.0
48 stars 50 forks source link

Redact log #1609

Open dayo09 opened 1 year ago

dayo09 commented 1 year ago

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.

dayo09 commented 1 year ago

I tried to apply pino to vscode Logger, but it seems that our logger need to be streamified for that.

I simply added Regex replace step to redact.

https://github.com/Samsung/ONE-vscode/pull/1610