Skip to content

Commit

Permalink
Merge pull request #1667 from navikt/mask_format
Browse files Browse the repository at this point in the history
mask format for winston
  • Loading branch information
kenglxn authored Sep 1, 2023
2 parents 8c0af9f + 3e6160b commit 3d27437
Showing 1 changed file with 7 additions and 3 deletions.
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

0 comments on commit 3d27437

Please sign in to comment.