diff --git a/js/logging.js b/js/logging.js index 64c39343c..757472ee5 100644 --- a/js/logging.js +++ b/js/logging.js @@ -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() { diff --git a/js/models/conversations.js b/js/models/conversations.js index a1ffcfe42..c876fba74 100644 --- a/js/models/conversations.js +++ b/js/models/conversations.js @@ -51,6 +51,14 @@ }; }, + idForLogging: function() { + if (this.isPrivate()) { + return this.id; + } + + return 'group(' + this.id + ')'; + }, + handleMessageError: function(message, errors) { this.trigger('messageError', message, errors); }, @@ -195,7 +203,7 @@ }.bind(this)).catch(function(error) { console.log( 'getIdentityKeys error for conversation', - this.id, + this.idForLogging(), error && error.stack ? error.stack : error ); return lookup; @@ -207,7 +215,7 @@ }).catch(function(error) { console.log( 'getIdentityKeys error for group member', - contact.id, + contact.idForLogging(), error && error.stack ? error.stack : error ); }); @@ -230,7 +238,7 @@ if (this.get('decryptedOldIncomingKeyErrors')) { return Promise.resolve(); } - console.log('decryptOldIncomingKeyErrors start for', this.id); + console.log('decryptOldIncomingKeyErrors start for', this.idForLogging()); var messages = this.messageCollection.filter(function(message) { var errors = message.get('errors'); @@ -245,7 +253,7 @@ }); var markComplete = function() { - console.log('decryptOldIncomingKeyErrors complete for', this.id); + console.log('decryptOldIncomingKeyErrors complete for', this.idForLogging()); return new Promise(function(resolve) { this.save({decryptedOldIncomingKeyErrors: true}).always(resolve); }.bind(this)); @@ -414,7 +422,13 @@ }, addKeyChange: function(id) { - console.log('adding key change advisory for', this.id, id, this.get('timestamp')); + console.log( + 'adding key change advisory for', + this.idForLogging(), + id, + this.get('timestamp') + ); + var timestamp = Date.now(); var message = new Whisper.Message({ conversationId : this.id, @@ -437,7 +451,12 @@ var lastMessage = this.get('timestamp') || Date.now(); - console.log('adding verified change advisory for', this.id, id, lastMessage); + console.log( + 'adding verified change advisory for', + this.idForLogging(), + id, + lastMessage + ); var timestamp = Date.now(); var message = new Whisper.Message({ @@ -548,7 +567,10 @@ queueJob: function(callback) { var previous = this.pending || Promise.resolve(); - var taskWithTimeout = textsecure.createTaskWithTimeout(callback, 'conversation ' + this.id); + var taskWithTimeout = textsecure.createTaskWithTimeout( + callback, + 'conversation ' + this.idForLogging() + ); var current = this.pending = previous.then(taskWithTimeout, taskWithTimeout); @@ -564,7 +586,14 @@ sendMessage: function(body, attachments) { this.queueJob(function() { var now = Date.now(); - console.log('Sending message to conversation', this.id, 'with timestamp', now); + + console.log( + 'Sending message to conversation', + this.idForLogging(), + 'with timestamp', + now + ); + var message = this.messageCollection.add({ body : body, conversationId : this.id, diff --git a/js/views/conversation_view.js b/js/views/conversation_view.js index 93d7aeae9..55b4ee82a 100644 --- a/js/views/conversation_view.js +++ b/js/views/conversation_view.js @@ -228,7 +228,12 @@ }, unload: function(reason) { - console.log('unloading conversation', this.model.id, 'due to:', reason); + console.log( + 'unloading conversation', + this.model.idForLogging(), + 'due to:', + reason + ); this.timerMenu.remove(); this.fileInput.remove(); @@ -285,7 +290,13 @@ return; } - console.log('trimming conversation', this.model.id, 'of', models.length, 'old messages'); + console.log( + 'trimming conversation', + this.model.idForLogging(), + 'of', + models.length, + 'old messages' + ); this.model.messageCollection.remove(models); _.forEach(models, function(model) { @@ -430,7 +441,13 @@ var view = this.loadingScreen; if (view) { var openDelta = Date.now() - this.openStart; - console.log('Conversation', this.model.id, 'took', openDelta, 'milliseconds to load'); + console.log( + 'Conversation', + this.model.idForLogging(), + 'took', + openDelta, + 'milliseconds to load' + ); this.loadingScreen = null; view.remove(); }