Browse Source

Restructure verbosity logging for the report tool

The verbose level has been removed. The rationale is that debug level
messages will not be visible in the console by default. For the purpose
of specialised verbose logging, an entry in the config should be added,
similar to `DEBUG_MSGPACK`.
Lennart Grahl 6 years ago
parent
commit
e74d7dcc19
7 changed files with 56 additions and 37 deletions
  1. 1 1
      src/app.ts
  2. 17 9
      src/config.ts
  3. 1 1
      src/directives/compose_area.ts
  4. 1 1
      src/services/push.ts
  5. 1 1
      src/services/timeout.ts
  6. 17 17
      src/services/webclient.ts
  7. 18 7
      src/threema.d.ts

+ 1 - 1
src/app.ts

@@ -152,7 +152,7 @@ angular.module('3ema', [
     function($log: ng.ILogService, CONFIG: threema.Config, browserService: BrowserService) {
     function($log: ng.ILogService, CONFIG: threema.Config, browserService: BrowserService) {
         // For Safari (when in DEBUG mode), monkey-patch $log to show timestamps.
         // For Safari (when in DEBUG mode), monkey-patch $log to show timestamps.
 
 
-        if (!(CONFIG.VERBOSE_DEBUGGING && browserService.getBrowser().isSafari(false))) {
+        if (!browserService.getBrowser().isSafari(false)) {
             return;
             return;
         }
         }
 
 

+ 17 - 9
src/config.ts

@@ -22,7 +22,6 @@ export default {
     SALTYRTC_HOST_SUFFIX: '.threema.ch',
     SALTYRTC_HOST_SUFFIX: '.threema.ch',
     SALTYRTC_PORT: 443,
     SALTYRTC_PORT: 443,
     SALTYRTC_SERVER_KEY: 'b1337fc8402f7db8ea639e05ed05d65463e24809792f91eca29e88101b4a2171',
     SALTYRTC_SERVER_KEY: 'b1337fc8402f7db8ea639e05ed05d65463e24809792f91eca29e88101b4a2171',
-    SALTYRTC_LOG_LEVEL: 'warn',
 
 
     // ICE
     // ICE
     ICE_SERVERS: [{
     ICE_SERVERS: [{
@@ -38,13 +37,22 @@ export default {
     // Push
     // Push
     PUSH_URL: 'https://push-web.threema.ch/push',
     PUSH_URL: 'https://push-web.threema.ch/push',
 
 
-    // Very verbose logging that potentially affects performance and may also
-    // contain sensitive information.
-    VERBOSE_DEBUGGING: false,
-    // Logs all incoming and outgoing protocol messages.
-    MSG_DEBUGGING: false,
-    // Logs URLs to visualise MsgPack messages for all incoming and outgoing
-    // protocol messages.
-    MSGPACK_DEBUGGING: false,
+    // Console log level
+    CONSOLE_LOG_LEVEL: 'info',
+    // Compose area log level
+    COMPOSE_AREA_LOG_LEVEL: 'warn',
+    // SaltyRTC log level
+    SALTYRTC_LOG_LEVEL: 'warn',
+    // Toggles logging verbose timer-related information.
+    DEBUG_TIMER: false,
+    // Toggles logging all chunks and messages exchanged by or associated with
+    // the app remote protocol. May also enable additional debug facilities of
+    // the app remote protocol.
+    // Note: Affects performance and contains sensitive information.
+    DEBUG_ARP: false,
+    // Toggles URL logging to visualise MsgPack messages for all incoming and
+    // outgoing protocol messages.
+    // Note: Affects performance and contains sensitive information.
+    DEBUG_MSGPACK: false,
 
 
 } as threema.Config;
 } as threema.Config;

+ 1 - 1
src/directives/compose_area.ts

@@ -93,7 +93,7 @@ export default [
                 const fileInput = select('input.file-input') as JQuery<HTMLInputElement>;
                 const fileInput = select('input.file-input') as JQuery<HTMLInputElement>;
 
 
                 // Initialize compose area lib
                 // Initialize compose area lib
-                const composeArea = ComposeArea.bind_to(composeDiv[0], CONFIG.VERBOSE_DEBUGGING ? 'debug' : 'warn');
+                const composeArea = ComposeArea.bind_to(composeDiv[0], CONFIG.COMPOSE_AREA_LOG_LEVEL);
                 if (scope.onInit) {
                 if (scope.onInit) {
                     scope.onInit(composeArea);
                     scope.onInit(composeArea);
                 }
                 }

+ 1 - 1
src/services/push.ts

@@ -194,7 +194,7 @@ export class PushSession {
 
 
             // Send push
             // Send push
             this.$log.debug(this.logTag, `Sending push ${this.tries}/${this.config.triesMax} (ttl=${timeToLive})`);
             this.$log.debug(this.logTag, `Sending push ${this.tries}/${this.config.triesMax} (ttl=${timeToLive})`);
-            if (this.service.config.VERBOSE_DEBUGGING) {
+            if (this.service.config.DEBUG_ARP) {
                 this.$log.debug(this.logTag, 'Push data:', `${data}`);
                 this.$log.debug(this.logTag, 'Push data:', `${data}`);
             }
             }
             try {
             try {

+ 1 - 1
src/services/timeout.ts

@@ -39,7 +39,7 @@ export class TimeoutService {
      * Log a message on debug log level, but only if the `DEBUG` flag is enabled.
      * Log a message on debug log level, but only if the `DEBUG` flag is enabled.
      */
      */
     private logDebug(msg: string): void {
     private logDebug(msg: string): void {
-        if (this.config.VERBOSE_DEBUGGING) {
+        if (this.config.DEBUG_TIMER) {
             this.$log.debug(this.logTag, msg);
             this.$log.debug(this.logTag, msg);
         }
         }
     }
     }

+ 17 - 17
src/services/webclient.ts

@@ -460,7 +460,7 @@ export class WebClientService {
         this.webrtcTask = new saltyrtcTaskWebrtc.WebRTCTask(true, maxPacketSize, this.config.SALTYRTC_LOG_LEVEL);
         this.webrtcTask = new saltyrtcTaskWebrtc.WebRTCTask(true, maxPacketSize, this.config.SALTYRTC_LOG_LEVEL);
 
 
         // Create Relayed Data task instance
         // Create Relayed Data task instance
-        this.relayedDataTask = new saltyrtcTaskRelayedData.RelayedDataTask(this.config.VERBOSE_DEBUGGING);
+        this.relayedDataTask = new saltyrtcTaskRelayedData.RelayedDataTask(this.config.SALTYRTC_LOG_LEVEL === 'debug');
 
 
         // Create new keystore if necessary
         // Create new keystore if necessary
         if (!keyStore) {
         if (!keyStore) {
@@ -498,7 +498,7 @@ export class WebClientService {
             builder = builder.withTrustedPeerKey(flags.peerTrustedKey);
             builder = builder.withTrustedPeerKey(flags.peerTrustedKey);
         }
         }
         this.salty = builder.asInitiator();
         this.salty = builder.asInitiator();
-        if (this.config.VERBOSE_DEBUGGING) {
+        if (this.config.DEBUG_ARP) {
             this.$log.debug('Public key:', this.salty.permanentKeyHex);
             this.$log.debug('Public key:', this.salty.permanentKeyHex);
             this.$log.debug('Auth token:', this.salty.authTokenHex);
             this.$log.debug('Auth token:', this.salty.authTokenHex);
         }
         }
@@ -708,7 +708,7 @@ export class WebClientService {
         }
         }
         this.$log.debug(`Chunk cache pruned, acknowledged: ${result.acknowledged}, left: ${result.left}, size: ` +
         this.$log.debug(`Chunk cache pruned, acknowledged: ${result.acknowledged}, left: ${result.left}, size: ` +
             `${size} -> ${this.previousChunkCache.byteLength}`);
             `${size} -> ${this.previousChunkCache.byteLength}`);
-        if (this.config.MSG_DEBUGGING) {
+        if (this.config.DEBUG_ARP) {
             this.$log.debug(`Chunks that require acknowledgement: ${this.previousChunkCache.chunks.length}`);
             this.$log.debug(`Chunks that require acknowledgement: ${this.previousChunkCache.chunks.length}`);
         }
         }
 
 
@@ -855,7 +855,7 @@ export class WebClientService {
             this.pcHelper = new PeerConnectionHelper(this.$log, this.$q, this.$timeout,
             this.pcHelper = new PeerConnectionHelper(this.$log, this.$q, this.$timeout,
                 this.$rootScope, this.webrtcTask,
                 this.$rootScope, this.webrtcTask,
                 this.config.ICE_SERVERS,
                 this.config.ICE_SERVERS,
-                !this.config.VERBOSE_DEBUGGING);
+                !this.config.DEBUG_ARP);
 
 
             // On state changes in the PeerConnectionHelper class, let state service know about it
             // On state changes in the PeerConnectionHelper class, let state service know about it
             this.pcHelper.onConnectionStateChange = (state: threema.TaskConnectionState) => {
             this.pcHelper.onConnectionStateChange = (state: threema.TaskConnectionState) => {
@@ -2674,7 +2674,7 @@ export class WebClientService {
             this.$log.warn('Invalid messages response, unknown receiver type (' + type + ')');
             this.$log.warn('Invalid messages response, unknown receiver type (' + type + ')');
             return future.reject('invalidResponse');
             return future.reject('invalidResponse');
         }
         }
-        if (this.config.MSG_DEBUGGING) {
+        if (this.config.DEBUG_ARP) {
             this.logChatMessages(message.type, message.subType, type, id, 'new', data);
             this.logChatMessages(message.type, message.subType, type, id, 'new', data);
         }
         }
         const receiver: threema.BaseReceiver = {type: type, id: id};
         const receiver: threema.BaseReceiver = {type: type, id: id};
@@ -2871,7 +2871,7 @@ export class WebClientService {
             this.$log.warn(this.logTag, 'Invalid messages update, unknown receiver type (' + type + ')');
             this.$log.warn(this.logTag, 'Invalid messages update, unknown receiver type (' + type + ')');
             return future.reject('invalidResponse');
             return future.reject('invalidResponse');
         }
         }
-        if (this.config.MSG_DEBUGGING) {
+        if (this.config.DEBUG_ARP) {
             this.logChatMessages(message.type, message.subType, type, id, mode, data);
             this.logChatMessages(message.type, message.subType, type, id, mode, data);
         }
         }
         const receiver: threema.BaseReceiver = {type: type, id: id};
         const receiver: threema.BaseReceiver = {type: type, id: id};
@@ -2895,7 +2895,7 @@ export class WebClientService {
                     if (!this.messages.update(receiver, msg)) {
                     if (!this.messages.update(receiver, msg)) {
                         const log = `Received message update for unknown message (id ${msg.id})`;
                         const log = `Received message update for unknown message (id ${msg.id})`;
                         this.$log.error(this.logTag, log);
                         this.$log.error(this.logTag, log);
-                        if (this.config.VERBOSE_DEBUGGING) {
+                        if (this.config.DEBUG_ARP) {
                             this.messages.addStatusMessage(receiver, 'Warning: ' + log);
                             this.messages.addStatusMessage(receiver, 'Warning: ' + log);
                             notify = true;
                             notify = true;
                         }
                         }
@@ -3604,7 +3604,7 @@ export class WebClientService {
 
 
             // Create & store future
             // Create & store future
             const future: Future<any> = new Future();
             const future: Future<any> = new Future();
-            if (this.config.MSG_DEBUGGING) {
+            if (this.config.DEBUG_ARP) {
                 this.$log.debug(this.logTag, `Added wire message future: ${id} -> ${type}/${subType}`);
                 this.$log.debug(this.logTag, `Added wire message future: ${id} -> ${type}/${subType}`);
             }
             }
             this.wireMessageFutures.set(message.id, future);
             this.wireMessageFutures.set(message.id, future);
@@ -3710,7 +3710,7 @@ export class WebClientService {
         if (future !== undefined) {
         if (future !== undefined) {
             // Remove the future from the map
             // Remove the future from the map
             this.wireMessageFutures.delete(id);
             this.wireMessageFutures.delete(id);
-            if (this.config.MSG_DEBUGGING) {
+            if (this.config.DEBUG_ARP) {
                 this.$log.debug(this.logTag, `Removed wire message future: ${id} -> ` +
                 this.$log.debug(this.logTag, `Removed wire message future: ${id} -> ` +
                     `${message.type}/${message.subType}`);
                     `${message.type}/${message.subType}`);
             }
             }
@@ -3872,7 +3872,7 @@ export class WebClientService {
      */
      */
     private send(message: threema.WireMessage, retransmit: boolean): void {
     private send(message: threema.WireMessage, retransmit: boolean): void {
         this.$log.debug('Sending', message.type + '/' + message.subType, 'message');
         this.$log.debug('Sending', message.type + '/' + message.subType, 'message');
-        if (this.config.MSG_DEBUGGING) {
+        if (this.config.DEBUG_ARP) {
             this.$log.debug('[Message] Outgoing:', message.type, '/', message.subType, message);
             this.$log.debug('[Message] Outgoing:', message.type, '/', message.subType, message);
         }
         }
 
 
@@ -3884,7 +3884,7 @@ export class WebClientService {
                 {
                 {
                     // Send bytes through WebRTC DataChannel
                     // Send bytes through WebRTC DataChannel
                     const bytes: Uint8Array = this.msgpackEncode(message);
                     const bytes: Uint8Array = this.msgpackEncode(message);
-                    if (this.config.MSGPACK_DEBUGGING) {
+                    if (this.config.DEBUG_MSGPACK) {
                         this.$log.debug('Outgoing message payload: ' + msgpackVisualizer(bytes));
                         this.$log.debug('Outgoing message payload: ' + msgpackVisualizer(bytes));
                     }
                     }
                     this.secureDataChannel.send(bytes);
                     this.secureDataChannel.send(bytes);
@@ -3898,7 +3898,7 @@ export class WebClientService {
 
 
                     // Send bytes through e2e encrypted WebSocket
                     // Send bytes through e2e encrypted WebSocket
                     const bytes: Uint8Array = this.msgpackEncode(message);
                     const bytes: Uint8Array = this.msgpackEncode(message);
-                    if (this.config.MSGPACK_DEBUGGING) {
+                    if (this.config.DEBUG_MSGPACK) {
                         this.$log.debug('Outgoing message payload: ' + msgpackVisualizer(bytes));
                         this.$log.debug('Outgoing message payload: ' + msgpackVisualizer(bytes));
                     }
                     }
 
 
@@ -3958,7 +3958,7 @@ export class WebClientService {
 
 
         // Add to chunk cache
         // Add to chunk cache
         if (cache) {
         if (cache) {
-            if (this.config.VERBOSE_DEBUGGING && this.config.MSG_DEBUGGING) {
+            if (this.config.DEBUG_ARP) {
                 this.$log.debug(`[Chunk] Caching chunk (retransmit/push=${retransmit}:`, chunk);
                 this.$log.debug(`[Chunk] Caching chunk (retransmit/push=${retransmit}:`, chunk);
             }
             }
             try {
             try {
@@ -3972,7 +3972,7 @@ export class WebClientService {
 
 
         // Send if ready
         // Send if ready
         if (!shouldQueue) {
         if (!shouldQueue) {
-            if (this.config.VERBOSE_DEBUGGING && this.config.MSG_DEBUGGING) {
+            if (this.config.DEBUG_ARP) {
                 this.$log.debug(`[Chunk] Sending chunk (retransmit/push=${retransmit}:`, chunk);
                 this.$log.debug(`[Chunk] Sending chunk (retransmit/push=${retransmit}:`, chunk);
             }
             }
 
 
@@ -3991,7 +3991,7 @@ export class WebClientService {
      * Handle an incoming chunk from the underlying transport.
      * Handle an incoming chunk from the underlying transport.
      */
      */
     private receiveChunk(chunk: Uint8Array): void {
     private receiveChunk(chunk: Uint8Array): void {
-        if (this.config.VERBOSE_DEBUGGING && this.config.MSG_DEBUGGING) {
+        if (this.config.DEBUG_ARP) {
             this.$log.debug('[Chunk] Received chunk:', chunk);
             this.$log.debug('[Chunk] Received chunk:', chunk);
         }
         }
 
 
@@ -4022,7 +4022,7 @@ export class WebClientService {
      */
      */
     private handleIncomingMessageBytes(bytes: Uint8Array): void {
     private handleIncomingMessageBytes(bytes: Uint8Array): void {
         this.$log.debug('New incoming message (' + bytes.byteLength + ' bytes)');
         this.$log.debug('New incoming message (' + bytes.byteLength + ' bytes)');
-        if (this.config.MSGPACK_DEBUGGING) {
+        if (this.config.DEBUG_MSGPACK) {
             this.$log.debug('Incoming message payload: ' + msgpackVisualizer(bytes));
             this.$log.debug('Incoming message payload: ' + msgpackVisualizer(bytes));
         }
         }
 
 
@@ -4049,7 +4049,7 @@ export class WebClientService {
         }
         }
 
 
         // If desired, log message type / subtype
         // If desired, log message type / subtype
-        if (this.config.MSG_DEBUGGING) {
+        if (this.config.DEBUG_ARP) {
             // Deep copy message to prevent issues with JS debugger
             // Deep copy message to prevent issues with JS debugger
             const deepcopy = copyDeep(message);
             const deepcopy = copyDeep(message);
             this.$log.debug('[Message] Incoming:', message.type, '/', message.subType, deepcopy);
             this.$log.debug('[Message] Incoming:', message.type, '/', message.subType, deepcopy);

+ 18 - 7
src/threema.d.ts

@@ -637,25 +637,36 @@ declare namespace threema {
     }
     }
 
 
     interface Config {
     interface Config {
+        // General
         SELF_HOSTED: boolean;
         SELF_HOSTED: boolean;
-        PREV_PROTOCOL_LAST_VERSION: string | null;
         VERSION_MOUNTAIN: string;
         VERSION_MOUNTAIN: string;
         VERSION_MOUNTAIN_URL: string;
         VERSION_MOUNTAIN_URL: string;
         VERSION_MOUNTAIN_IMAGE_URL: string;
         VERSION_MOUNTAIN_IMAGE_URL: string;
         VERSION_MOUNTAIN_IMAGE_COPYRIGHT: string;
         VERSION_MOUNTAIN_IMAGE_COPYRIGHT: string;
         VERSION_MOUNTAIN_HEIGHT: number;
         VERSION_MOUNTAIN_HEIGHT: number;
+        PREV_PROTOCOL_LAST_VERSION: string | null;
         GIT_BRANCH: string;
         GIT_BRANCH: string;
-        SALTYRTC_PORT: number;
-        SALTYRTC_SERVER_KEY: string | null;
+
+        // SaltyRTC
         SALTYRTC_HOST: string | null;
         SALTYRTC_HOST: string | null;
         SALTYRTC_HOST_PREFIX: string | null;
         SALTYRTC_HOST_PREFIX: string | null;
         SALTYRTC_HOST_SUFFIX: string | null;
         SALTYRTC_HOST_SUFFIX: string | null;
-        SALTYRTC_LOG_LEVEL: saltyrtc.LogLevel;
+        SALTYRTC_PORT: number;
+        SALTYRTC_SERVER_KEY: string | null;
+
+        // ICE
         ICE_SERVERS: RTCIceServer[];
         ICE_SERVERS: RTCIceServer[];
+
+        // Push
         PUSH_URL: string;
         PUSH_URL: string;
-        VERBOSE_DEBUGGING: boolean;
-        MSG_DEBUGGING: boolean;
-        MSGPACK_DEBUGGING: boolean;
+
+        // Logging/debugging
+        CONSOLE_LOG_LEVEL: LogLevel;
+        COMPOSE_AREA_LOG_LEVEL: LogLevel;
+        SALTYRTC_LOG_LEVEL: saltyrtc.LogLevel;
+        DEBUG_TIMER: boolean,
+        DEBUG_ARP: boolean;
+        DEBUG_MSGPACK: boolean;
     }
     }
 
 
     interface InitialConversationData {
     interface InitialConversationData {