summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorael-code <tommy.ael@gmail.com>2016-11-25 15:24:43 +0100
committerael-code <tommy.ael@gmail.com>2016-11-25 17:37:27 +0100
commit1ba63d936ce46582de2571de4b627cc0312280f4 (patch)
treeaf2cb3061cdd7ef34f51f47abcbce653753de21f
parent3c8086ece60c839eaaac868678415a5e85eb13db (diff)
downloadranger-1ba63d936ce46582de2571de4b627cc0312280f4.tar.gz
Update all the log calls
All the log calls that were using the old logging approach
(appending to FileManager.log queue) will now use the standard logging
library of python. Proper log levels have been choosed for each call
-rw-r--r--ranger/core/actions.py5
-rw-r--r--ranger/core/fm.py4
-rw-r--r--ranger/core/main.py9
-rw-r--r--ranger/ext/vcs/vcs.py7
4 files changed, 14 insertions, 11 deletions
diff --git a/ranger/core/actions.py b/ranger/core/actions.py
index 6d1824c2..97752f06 100644
--- a/ranger/core/actions.py
+++ b/ranger/core/actions.py
@@ -13,6 +13,7 @@ from inspect import cleandoc
 from stat import S_IEXEC
 from hashlib import sha1
 from sys import version_info
+from logging import getLogger
 
 import ranger
 from ranger.ext.direction import Direction
@@ -31,6 +32,8 @@ from ranger.core.linemode import DEFAULT_LINEMODE
 
 MACRO_FAIL = "<\x01\x01MACRO_HAS_NO_VALUE\x01\01>"
 
+log = getLogger(__name__)
+
 
 class _MacroTemplate(string.Template):
     """A template for substituting macros in commands"""
@@ -152,7 +155,7 @@ class Actions(FileManagerAware, SettingsAware):
         elif bad is True and ranger.arg.debug:
             raise Exception(str(text))
         text = str(text)
-        self.log.appendleft(text)
+        log.debug("Command notify invoked: [Bad: {0}, Text: '{1}']".format(bad, text))
         if self.ui and self.ui.is_on:
             self.ui.status.notify("  ".join(text.split("\n")),
                     duration=duration, bad=bad)
diff --git a/ranger/core/fm.py b/ranger/core/fm.py
index 719479eb..724d09d5 100644
--- a/ranger/core/fm.py
+++ b/ranger/core/fm.py
@@ -74,9 +74,9 @@ class FM(Actions, SignalDispatcher):
         self.hostname = socket.gethostname()
         self.home_path = os.path.expanduser('~')
 
-        self.log.appendleft('ranger {0} started! Process ID is {1}.'
+        log.info('ranger {0} started! Process ID is {1}'
                 .format(__version__, os.getpid()))
-        self.log.appendleft('Running on Python ' + sys.version.replace('\n', ''))
+        log.info('Running on Python ' + sys.version.replace('\n', ''))
 
         mimetypes.knownfiles.append(os.path.expanduser('~/.mime.types'))
         mimetypes.knownfiles.append(self.relpath('data/mime.types'))
diff --git a/ranger/core/main.py b/ranger/core/main.py
index d2f5c709..c0b2b14e 100644
--- a/ranger/core/main.py
+++ b/ranger/core/main.py
@@ -116,7 +116,7 @@ def main():
         if fm.username == 'root':
             fm.settings.preview_files = False
             fm.settings.use_preview_script = False
-            fm.log.appendleft("Running as root, disabling the file previews.")
+            log.info("Running as root, disabling the file previews.")
         if not arg.debug:
             from ranger.ext import curses_interrupt_handler
             curses_interrupt_handler.install_interrupt_handler()
@@ -319,10 +319,9 @@ def load_settings(fm, clean):
                     else:
                         module = importlib.import_module('plugins.' + plugin)
                         fm.commands.load_commands_from_module(module)
-                    fm.log.appendleft("Loaded plugin '%s'." % plugin)
-                except Exception:
-                    import traceback
-                    fm.log.extendleft(reversed(traceback.format_exc().splitlines()))
+                    log.info("Loaded plugin '%s'." % plugin)
+                except Exception as e:
+                    log.exception(e)
                     fm.notify("Error in plugin '%s'" % plugin, bad=True)
             ranger.fm = None
 
diff --git a/ranger/ext/vcs/vcs.py b/ranger/ext/vcs/vcs.py
index cfdc1e3b..9c2a8b5a 100644
--- a/ranger/ext/vcs/vcs.py
+++ b/ranger/ext/vcs/vcs.py
@@ -7,6 +7,7 @@ import os
 import subprocess
 import threading
 import time
+from logging import getLogger
 from ranger.ext.spawn import spawn
 
 # Python2 compatibility
@@ -19,6 +20,7 @@ try:
 except NameError:
     FileNotFoundError = OSError  # pylint: disable=redefined-builtin
 
+log = getLogger(__name__)
 
 class VcsError(Exception):
     """VCS exception"""
@@ -470,9 +472,8 @@ class VcsThread(threading.Thread):  # pylint: disable=too-many-instance-attribut
                             column.need_redraw = True
                     self.ui.status.need_redraw = True
                     self.ui.redraw()
-            except Exception:  # pylint: disable=broad-except
-                import traceback
-                self.ui.fm.log.extendleft(reversed(traceback.format_exc().splitlines()))
+            except Exception as e:  # pylint: disable=broad-except
+                log.exception(e)
                 self.ui.fm.notify('VCS Exception', bad=True)
 
     def pause(self):