Make log messages distinguishable from other extensions

log statement in Log.debug is commented out by default. It makes sense
to make this configurable by the user later on.
master
Frank Ploss 9 years ago
parent 0d0b75cc77
commit 2c2e970f5b

@ -23,6 +23,7 @@ const Gtk = imports.gi.Gtk;
const Main = imports.ui.main; const Main = imports.ui.main;
const Me = imports.misc.extensionUtils.getCurrentExtension(); const Me = imports.misc.extensionUtils.getCurrentExtension();
const Log = Me.imports.log.Log;
const TorButton = Me.imports.ui.tor_button.TorButton; const TorButton = Me.imports.ui.tor_button.TorButton;
const TorControlClient = Me.imports.tor_control_client.TorControlClient; const TorControlClient = Me.imports.tor_control_client.TorControlClient;
@ -42,6 +43,7 @@ function enable() {
torButton = new TorButton(torControlClient); torButton = new TorButton(torControlClient);
Main.panel.addToStatusArea(torButton.Name, torButton); Main.panel.addToStatusArea(torButton.Name, torButton);
torControlClient.openConnection(); torControlClient.openConnection();
Log.debug('Enabled Tor extension');
} }
function disable() { function disable() {
@ -50,4 +52,6 @@ function disable() {
if (torButton !== null) if (torButton !== null)
torButton.destroy(); torButton.destroy();
Log.debug('Disabled Tor extension');
} }

@ -0,0 +1,9 @@
const Log = {
warn: function(message) {
log('[tor control] ' + message);
},
debug: function(message) {
//log('[tor control] DEBUG: ' + message);
}
}

@ -24,6 +24,9 @@ const GLib = imports.gi.GLib;
const Lang = imports.lang; const Lang = imports.lang;
const Signals = imports.signals; const Signals = imports.signals;
const Me = imports.misc.extensionUtils.getCurrentExtension();
const Log = Me.imports.log.Log;
const TorConnectionError = new Lang.Class({ const TorConnectionError = new Lang.Class({
Name: 'TorConnectionError', Name: 'TorConnectionError',
@ -58,6 +61,7 @@ const TorControlClient = new Lang.Class({
}, },
openConnection: function() { openConnection: function() {
Log.debug('Trying to reconnect ...');
try { try {
this._connect(this._host, this._port); this._connect(this._host, this._port);
this._updateProtocolInfo(); this._updateProtocolInfo();
@ -65,10 +69,13 @@ const TorControlClient = new Lang.Class({
this._authenticate(); this._authenticate();
this.emit('changed-connection-state', 'ready'); this.emit('changed-connection-state', 'ready');
this.stopAutoRetry(); this.stopAutoRetry();
Log.debug('Connected to Tor control port');
} catch (e if e instanceof TorConnectionError) { } catch (e if e instanceof TorConnectionError) {
Log.debug('Could not connect to Tor control port');
this.closeConnection(e.message); this.closeConnection(e.message);
this.startAutoRetry(); this.startAutoRetry();
} catch (e if e instanceof TorProtocolError) { } catch (e if e instanceof TorProtocolError) {
Log.debug('Tor control protocol error: ' + e.message);
this.closeConnection(e.message); this.closeConnection(e.message);
this.startAutoRetry(); this.startAutoRetry();
} }
@ -92,16 +99,19 @@ const TorControlClient = new Lang.Class({
return; return;
this._autoRetryTimerId = GLib.timeout_add(GLib.PRIORITY_DEFAULT, 1000, Lang.bind(this, function() { this._autoRetryTimerId = GLib.timeout_add(GLib.PRIORITY_DEFAULT, 1000, Lang.bind(this, function() {
//log('Retrying to open connection ...');
this.openConnection(); this.openConnection();
return this._connection === null || !this._connection.is_connected(); return this._connection === null || !this._connection.is_connected();
})); }));
Log.debug('Started auto retry (timer id=' + this._autoRetryTimerId + ')');
}, },
stopAutoRetry: function() { stopAutoRetry: function() {
if (this._autoRetryTimerId === null) if (this._autoRetryTimerId === null)
return; return;
Log.debug('Stopping auto retry (timer id=' + this._autoRetryTimerId + ')');
GLib.source_remove(this._autoRetryTimerId); GLib.source_remove(this._autoRetryTimerId);
this._autoRetryTimerId = null; this._autoRetryTimerId = null;
}, },

Loading…
Cancel
Save