Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redact log #1609

Open
dayo09 opened this issue Jul 20, 2023 · 1 comment
Open

Redact log #1609

dayo09 opened this issue Jul 20, 2023 · 1 comment

Comments

@dayo09
Copy link
Contributor

dayo09 commented Jul 20, 2023

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 dayo09 changed the title Print token as asterisks Redact log Jul 20, 2023
@dayo09
Copy link
Contributor Author

dayo09 commented Jul 20, 2023

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.

#1610

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant