diff --git a/plugins/EventLogging/__init__.py b/plugins/EventLogging/__init__.py index fe8ecfb91..6037fbfc8 100644 --- a/plugins/EventLogging/__init__.py +++ b/plugins/EventLogging/__init__.py @@ -25,6 +25,16 @@ Adds a tab with log of selected events. Event messages come from libtorrent alerts. If you want those strings translated to your locale, you'll have to report the issue with libtorrent, not deluge. + +Regarding the log files, the logs are saved in a log +directory within the deluge config directory. Event +messages for specific torrents are saved to individual +log files named the same as the associated .torrent +file. Event messages not specific to any torrent are +saved to logs named after the events +(eg peer_messages.log). +Event messages in the log files also include a timestamp. +The user is responsible to cleanout the logs. """) def deluge_init(deluge_path): @@ -105,7 +115,9 @@ class EventLogging: self.manager.connect_event(self.manager.constants['EVENT_BLOCK_FINISHED'], self.tab_log.handle_event) if self.config.get("enable_other"): self.manager.connect_event(self.manager.constants['EVENT_OTHER'], self.tab_log.handle_event) - self.tab_log.prepare_log_store() + if self.config.get("enable_log_files"): + self.tab_log.enable_log_files() + self.tab_log.prepare_log_store() def unload(self): self.config.save(self.config_file) @@ -140,7 +152,7 @@ class EventLogging: if self.config.get("enable_block_finished"): self.manager.disconnect_event(self.manager.constants['EVENT_BLOCK_FINISHED'], self.tab_log.handle_event) if self.config.get("enable_other"): - self.manager.connect_event(self.manager.constants['EVENT_OTHER'], self.tab_log.handle_event) + self.manager.disconnect_event(self.manager.constants['EVENT_OTHER'], self.tab_log.handle_event) self.tab_log.clear_log_store() numPages = self.parentNotebook.get_n_pages() for page in xrange(numPages): @@ -233,6 +245,11 @@ class EventLogging: self.manager.disconnect_event(self.manager.constants['EVENT_OTHER'], self.tab_log.handle_event) else: self.manager.connect_event(self.manager.constants['EVENT_OTHER'], self.tab_log.handle_event) + if widget == self.glade.get_widget("chk_log_files"): + if value: + self.tab_log.enable_log_files() + else: + self.tab_log.disable_log_files() def configure(self): try: @@ -252,6 +269,7 @@ class EventLogging: self.glade.get_widget("chk_block_downloading").set_active(self.config.get("enable_block_downloading")) self.glade.get_widget("chk_block_finished").set_active(self.config.get("enable_block_finished")) self.glade.get_widget("chk_other").set_active(self.config.get("enable_other")) + self.glade.get_widget("chk_log_files").set_active(self.config.get("enable_log_files")) except: self.glade.get_widget("chk_finished").set_active(False) self.glade.get_widget("chk_peer_error").set_active(False) @@ -269,6 +287,7 @@ class EventLogging: self.glade.get_widget("chk_block_downloading").set_active(False) self.glade.get_widget("chk_block_finished").set_active(False) self.glade.get_widget("chk_other").set_active(False) + self.glade.get_widget("chk_log_files").set_active(False) self.dialog.show() response = self.dialog.run() self.dialog.hide() @@ -289,3 +308,4 @@ class EventLogging: self.config.set("enable_block_downloading", self.glade.get_widget("chk_block_downloading").get_active()) self.config.set("enable_block_finished", self.glade.get_widget("chk_block_finished").get_active()) self.config.set("enable_other", self.glade.get_widget("chk_other").get_active()) + self.config.set("enable_log_files", self.glade.get_widget("chk_log_files").get_active()) diff --git a/plugins/EventLogging/event_logging_preferences.glade b/plugins/EventLogging/event_logging_preferences.glade index 538ecea18..1ed9dc2a0 100644 --- a/plugins/EventLogging/event_logging_preferences.glade +++ b/plugins/EventLogging/event_logging_preferences.glade @@ -16,7 +16,7 @@ True - 17 + 19 True @@ -263,6 +263,31 @@ 17 + + + True + Log files + + + 17 + 18 + + + + + True + True + Enable log files + True + 0 + True + + + + 18 + 19 + + False diff --git a/plugins/EventLogging/tab_log.py b/plugins/EventLogging/tab_log.py index a42dae013..42bb90d0e 100644 --- a/plugins/EventLogging/tab_log.py +++ b/plugins/EventLogging/tab_log.py @@ -1,10 +1,19 @@ import gtk +import xdg.BaseDirectory +import os +import time + +CONFIG_DIR = xdg.BaseDirectory.save_config_path('deluge') class LogManager(object): def __init__(self, viewport, manager): + self.log_files = False self.viewport = viewport self.vbox = None self.manager = manager + self.logdir = os.path.join(CONFIG_DIR, 'logs') + if not os.path.isdir(self.logdir): + os.mkdir(self.logdir) def clear_log_store(self): if not self.vbox is None: @@ -15,64 +24,163 @@ class LogManager(object): self.vbox = gtk.VBox() self.viewport.add(self.vbox) self.vbox.show_all() + + def enable_log_files(self): + self.log_files = True + + def disable_log_files(self): + self.log_files = False def handle_event(self, event): event_message = None if event['event_type'] is self.manager.constants['EVENT_FINISHED']: + torrent = self.manager.unique_IDs[event['unique_ID']].filename.replace(os.path.join(CONFIG_DIR, 'torrentfiles/'), '') event_message = _("Torrent finished") + " {"+ _("event message: ") + event['message'] + ", "\ - + _("torrent: ") + self.manager.unique_IDs[event['unique_ID']].filename + "}" + + _("torrent: ") + torrent + "}" + if self.log_files: + log = os.path.join(self.logdir, torrent.replace('.torrent', '.log')) + logfile = open(log, "a") + logfile.write(time.asctime(time.localtime()) + ", " +event_message + '\n') + logfile.close() if event['event_type'] is self.manager.constants['EVENT_PEER_ERROR']: event_message = _("Peer message") + " {" + _("event message: ") + event['message'] + ", " + _("ip address: ")\ + event['ip'] + ", " + _("client: ") + event['client_ID'] + "}" + if self.log_files: + log = os.path.join(self.logdir, 'peer_messages.log') + logfile = open(log, "a") + logfile.write(time.asctime(time.localtime()) + ", " +event_message + '\n') + logfile.close() if event['event_type'] is self.manager.constants['EVENT_INVALID_REQUEST']: event_message = _("Invalid request") + " {" + _("event message: ") + event['message'] + ", " + _("client: ")\ + event['client_ID'] + "}" + if self.log_files: + log = os.path.join(self.logdir, 'invalid_requests.log') + logfile = open(log, "a") + logfile.write(time.asctime(time.localtime()) + ", " +event_message + '\n') + logfile.close() if event['event_type'] is self.manager.constants['EVENT_FILE_ERROR']: + torrent = self.manager.unique_IDs[event['unique_ID']].filename.replace(os.path.join(CONFIG_DIR, 'torrentfiles/'), '') event_message = _("File error") + " {" + _("event message: ") + event['message'] + ", " + _("torrent: ")\ - + self.manager.unique_IDs[event['unique_ID']].filename + "}" + + torrent + "}" + if self.log_files: + log = os.path.join(self.logdir, torrent.replace('.torrent', '.log')) + logfile = open(log, "a") + logfile.write(time.asctime(time.localtime()) + ", " +event_message + '\n') + logfile.close() if event['event_type'] is self.manager.constants['EVENT_HASH_FAILED_ERROR']: + torrent = self.manager.unique_IDs[event['unique_ID']].filename.replace(os.path.join(CONFIG_DIR, 'torrentfiles/'), '') event_message = _("Hash failed error") + " {" + _("event message: ") + event['message'] + ", "\ - + _("torrent: ") + self.manager.unique_IDs[event['unique_ID']].filename + ", "\ + + _("torrent: ") + torrent + ", "\ + _("piece index: ") + str(event['piece_index']) + "}" + if self.log_files: + log = os.path.join(self.logdir, torrent.replace('.torrent', '.log')) + logfile = open(log, "a") + logfile.write(time.asctime(time.localtime()) + ", " +event_message + '\n') + logfile.close() if event['event_type'] is self.manager.constants['EVENT_PEER_BAN_ERROR']: + torrent = self.manager.unique_IDs[event['unique_ID']].filename.replace(os.path.join(CONFIG_DIR, 'torrentfiles/'), '') event_message = _("Peer ban error") + " {" + _("event message: ") + event['message'] + ", " + _("ip address: ")\ - + event['ip'] + ", " + _("torrent: ") + self.manager.unique_IDs[event['unique_ID']].filename + "}" + + event['ip'] + ", " + _("torrent: ") + torrent + "}" + if self.log_files: + log = os.path.join(self.logdir, torrent.replace('.torrent', '.log')) + logfile = open(log, "a") + logfile.write(time.asctime(time.localtime()) + ", " +event_message + '\n') + logfile.close() if event['event_type'] is self.manager.constants['EVENT_FASTRESUME_REJECTED_ERROR']: + torrent = self.manager.unique_IDs[event['unique_ID']].filename.replace(os.path.join(CONFIG_DIR, 'torrentfiles/'), '') event_message = _("Fastresume rejected error") + event['message'] + ", "\ - + _("torrent: ") + self.manager.unique_IDs[event['unique_ID']].filename + "}" + + _("torrent: ") + torrent + "}" + if self.log_files: + log = os.path.join(self.logdir, torrent.replace('.torrent', '.log')) + logfile = open(log, "a") + logfile.write(time.asctime(time.localtime()) + ", " +event_message + '\n') + logfile.close() if event['event_type'] is self.manager.constants['EVENT_TRACKER_ANNOUNCE']: + torrent = self.manager.unique_IDs[event['unique_ID']].filename.replace(os.path.join(CONFIG_DIR, 'torrentfiles/'), '') event_message = _("Tracker announce") + " {" + _("event message: ") + event['message'] + ", "\ - + _("torrent: ") + self.manager.unique_IDs[event['unique_ID']].filename + "}" + + _("torrent: ") + torrent + "}" + if self.log_files: + log = os.path.join(self.logdir, torrent.replace('.torrent', '.log')) + logfile = open(log, "a") + logfile.write(time.asctime(time.localtime()) + ", " +event_message + '\n') + logfile.close() if event['event_type'] is self.manager.constants['EVENT_TRACKER_REPLY']: + torrent = self.manager.unique_IDs[event['unique_ID']].filename.replace(os.path.join(CONFIG_DIR, 'torrentfiles/'), '') event_message = _("Tracker reply") + " {" + _("event message: ") + event['message'] + ", "\ - + _("torrent: ") + self.manager.unique_IDs[event['unique_ID']].filename + "}" + + _("torrent: ") + torrent + "}" + if self.log_files: + log = os.path.join(self.logdir, torrent.replace('.torrent', '.log')) + logfile = open(log, "a") + logfile.write(time.asctime(time.localtime()) + ", " +event_message + '\n') + logfile.close() if event['event_type'] is self.manager.constants['EVENT_TRACKER_ALERT']: + torrent = self.manager.unique_IDs[event['unique_ID']].filename.replace(os.path.join(CONFIG_DIR, 'torrentfiles/'), '') event_message = _("Tracker alert") + " {" + _("event message: ") + event['message'] + ", "\ - + _("torrent: ") + self.manager.unique_IDs[event['unique_ID']].filename + ", "\ + + _("torrent: ") + torrent + ", "\ + _("status code: ") + str(event['status_code']) + ", " + _("Times in a row: ")\ + str(event['times_in_row']) + "}" + if self.log_files: + log = os.path.join(self.logdir, torrent.replace('.torrent', '.log')) + logfile = open(log, "a") + logfile.write(time.asctime(time.localtime()) + ", " +event_message + '\n') + logfile.close() if event['event_type'] is self.manager.constants['EVENT_TRACKER_WARNING']: + torrent = self.manager.unique_IDs[event['unique_ID']].filename.replace(os.path.join(CONFIG_DIR, 'torrentfiles/'), '') event_message = _("Tracker warning") + " {" + _("event message: ") + event['message'] + ", "\ - + _("torrent: ") + self.manager.unique_IDs[event['unique_ID']].filename + "}" + + _("torrent: ") + torrent + "}" + if self.log_files: + log = os.path.join(self.logdir, torrent.replace('.torrent', '.log')) + logfile = open(log, "a") + logfile.write(time.asctime(time.localtime()) + ", " +event_message + '\n') + logfile.close() if event['event_type'] is self.manager.constants['EVENT_STORAGE_MOVED']: + torrent = self.manager.unique_IDs[event['unique_ID']].filename.replace(os.path.join(CONFIG_DIR, 'torrentfiles/'), '') event_message = _("Storage moved") + " {" + _("event message: ") + event['message'] + ", "\ - + _("torrent: ") + self.manager.unique_IDs[event['unique_ID']].filename + "}" + + _("torrent: ") + torrent + "}" + if self.log_files: + log = os.path.join(self.logdir, torrent.replace('.torrent', '.log')) + logfile = open(log, "a") + logfile.write(time.asctime(time.localtime()) + ", " +event_message + '\n') + logfile.close() if event['event_type'] is self.manager.constants['EVENT_PIECE_FINISHED']: + torrent = self.manager.unique_IDs[event['unique_ID']].filename.replace(os.path.join(CONFIG_DIR, 'torrentfiles/'), '') event_message = _("Piece finished") + " {" + _("event message: ") + event['message'] + ", "\ - + _("torrent: ") + self.manager.unique_IDs[event['unique_ID']].filename + ", "\ + + _("torrent: ") + torrent + ", "\ + _("piece index: ") + str(event['piece_index']) + "}" + if self.log_files: + log = os.path.join(self.logdir, torrent.replace('.torrent', '.log')) + logfile = open(log, "a") + logfile.write(time.asctime(time.localtime()) + ", " +event_message + '\n') + logfile.close() if event['event_type'] is self.manager.constants['EVENT_BLOCK_DOWNLOADING']: + torrent = self.manager.unique_IDs[event['unique_ID']].filename.replace(os.path.join(CONFIG_DIR, 'torrentfiles/'), '') event_message = _("Block downloading") + " {" + _("event message: ") + event['message'] + ", "\ - + _("torrent: ") + self.manager.unique_IDs[event['unique_ID']].filename + ", "\ + + _("torrent: ") + torrent + ", "\ + _("piece index: ") + str(event['piece_index']) + ", " + _("block index: ")\ + str(event['block_index']) + ", " + _("peer speed: ") + event['peer_speed'] + "}" + if self.log_files: + log = os.path.join(self.logdir, torrent.replace('.torrent', '.log')) + logfile = open(log, "a") + logfile.write(time.asctime(time.localtime()) + ", " +event_message + '\n') + logfile.close() if event['event_type'] is self.manager.constants['EVENT_BLOCK_FINISHED']: + torrent = self.manager.unique_IDs[event['unique_ID']].filename.replace(os.path.join(CONFIG_DIR, 'torrentfiles/'), '') event_message = _("Block finished") + " {" + _("event message: ") + event['message'] + ", "\ - + _("torrent: ") + self.manager.unique_IDs[event['unique_ID']].filename + ", "\ + + _("torrent: ") + torrent + ", "\ + _("piece index: ") + str(event['piece_index']) + ", " + _("block index: ")\ + str(event['block_index']) + "}" + if self.log_files: + log = os.path.join(self.logdir, torrent.replace('.torrent', '.log')) + logfile = open(log, "a") + logfile.write(time.asctime(time.localtime()) + ", " +event_message + '\n') + logfile.close() if event['event_type'] is self.manager.constants['EVENT_OTHER']: event_message = _("Other") + " {" + _("event message: ") + event['message'] + "}" + if self.log_files: + log = os.path.join(self.logdir, 'other.log') + logfile = open(log, "a") + logfile.write(time.asctime(time.localtime()) + ", " +event_message + '\n') + logfile.close() if not event_message is None: label = gtk.Label() label.set_text(event_message)