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

mask format for winston #1667

Merged
merged 3 commits into from
Sep 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions server/server.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import path from 'path';
import fetch from 'node-fetch';
import express from 'express';
import Mustache from 'mustache';
import httpProxyMiddleware, { responseInterceptor } from 'http-proxy-middleware';
Expand All @@ -20,7 +19,6 @@ const {
GIT_COMMIT = '?',
LOGIN_URL = 'http://localhost:8080/ditt-nav-arbeidsgiver-api/local/selvbetjening-login?redirect=http://localhost:3000/min-side-arbeidsgiver',
NAIS_CLUSTER_NAME = 'local',
PROXY_LOG_LEVEL = 'info',
MILJO = 'local',
} = process.env;

Expand All @@ -29,9 +27,16 @@ const log_events_counter = new Prometheus.Counter({
help: 'Antall log events fordelt på level',
labelNames: ['level'],
});

const maskFormat = format((info) => ({
...info,
message: info.message.replace(/\d{9,}/g, (match) => '*'.repeat(match.length)),
}));

// proxy calls to log.<level> https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy/Proxy/get
const log = new Proxy(
createLogger({
format: maskFormat(),
transports: [
new transports.Console({
timestamp: true,
Expand Down Expand Up @@ -117,7 +122,6 @@ const main = async () => {
);
} else {
const proxyOptions = {
logLevel: PROXY_LOG_LEVEL,
logger: log,
on: {
error: (err, req, res) => {
Expand Down
Loading