Redact group ids in logging
FREEBIE
This commit is contained in:
parent
4c48d12dc3
commit
314b29e426
3 changed files with 70 additions and 13 deletions
|
@ -5,6 +5,7 @@ const _ = require('lodash');
|
|||
|
||||
const ipc = electron.ipcRenderer;
|
||||
const PHONE_REGEX = /\+\d{7,12}(\d{3})/g;
|
||||
const GROUP_REGEX = /(group\()([^)]+)(\))/g;
|
||||
|
||||
// Default Bunyan levels: https://github.com/trentm/node-bunyan#levels
|
||||
// To make it easier to visually scan logs, we make all levels the same length
|
||||
|
@ -21,6 +22,16 @@ const LEVELS = {
|
|||
|
||||
// Backwards-compatible logging, simple strings and no level (defaulted to INFO)
|
||||
|
||||
function redactPhone(text) {
|
||||
return text.replace(PHONE_REGEX, "+[REDACTED]$1");
|
||||
}
|
||||
|
||||
function redactGroup(text) {
|
||||
return text.replace(GROUP_REGEX, function(match, before, id, after) {
|
||||
return before + '[REDACTED]' + id.slice(-3) + after;
|
||||
});
|
||||
}
|
||||
|
||||
function now() {
|
||||
const date = new Date();
|
||||
return date.toJSON();
|
||||
|
@ -32,7 +43,7 @@ function log() {
|
|||
const consoleArgs = ['INFO ', now()].concat(args);
|
||||
console._log.apply(console, consoleArgs);
|
||||
|
||||
const str = args.join(' ').replace(PHONE_REGEX, "+[REDACTED]$1");
|
||||
const str = redactGroup(redactPhone(args.join(' ')));
|
||||
ipc.send('log-info', str);
|
||||
}
|
||||
|
||||
|
@ -62,7 +73,7 @@ function formatLine(entry) {
|
|||
}
|
||||
|
||||
function format(entries) {
|
||||
return entries.map(formatLine).join('\n');
|
||||
return redactGroup(redactPhone(entries.map(formatLine).join('\n')));
|
||||
}
|
||||
|
||||
function fetch() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue