[gedit-latex] More logging cleanups



commit 16bd50a34478919faa8f7a80800f7664a71325ae
Author: John Stowers <john stowers gmail com>
Date:   Fri Sep 2 23:33:35 2011 +1200

    More logging cleanups

 latex/base/editor.py   |   30 +++++++++++++-----------------
 latex/bibtex/editor.py |   28 ++++++++++------------------
 latex/latex/editor.py  |   38 +++++++++++++-------------------------
 3 files changed, 36 insertions(+), 60 deletions(-)
---
diff --git a/latex/base/editor.py b/latex/base/editor.py
index 237061c..3717196 100644
--- a/latex/base/editor.py
+++ b/latex/base/editor.py
@@ -20,8 +20,8 @@
 
 import re
 import time
-from uuid import uuid1
-from logging import getLogger
+import logging
+import uuid
 
 from gi.repository import GObject, Gtk, Gdk
 
@@ -29,6 +29,8 @@ from .completion import CompletionDistributor
 from .templates import TemplateDelegate
 from . import Template
 
+LOG = logging.getLogger(__name__)
+
 class Editor(object):
     """
     The base class for editors. This manages
@@ -38,8 +40,6 @@ class Editor(object):
      - drag'n'drop support
     """
 
-    __log = getLogger("Editor")
-
     class Marker(object):
         """
         Markers refer to and highlight a range of text in the TextBuffer decorated by
@@ -145,7 +145,7 @@ class Editor(object):
         @param info: an integer ID for the drag
         @param timestamp: the time of the drag event
         """
-        self.__log.debug("drag-data-received")
+        LOG.debug("drag-data-received")
 
         files = []
         match = False
@@ -186,7 +186,7 @@ class Editor(object):
             x, y = text_view.window_to_buffer_coords(Gtk.TextWindowType.WIDGET, x, y)
             it = text_view.get_iter_at_location(x, y)
 
-            self.__log.debug("Right button pressed at offset %s" % it.get_offset())
+            LOG.debug("Right button pressed at offset %s" % it.get_offset())
 
             #
             # find Marker at this position
@@ -195,17 +195,17 @@ class Editor(object):
                 for mark in it.get_marks():
                     name = mark.get_name()
 
-                    self.__log.debug("Found TextMark '%s' at offset %s" % (name, it.get_offset()))
+                    LOG.debug("Found TextMark '%s' at offset %s" % (name, it.get_offset()))
 
                     if name:
                         if name in self._markers.keys():
                             marker = self._markers[name]
                             return self.on_marker_activated(marker, event)
                         else:
-                            self.__log.warning("No marker found for TextMark '%s'" % name)
+                            LOG.warning("No marker found for TextMark '%s'" % name)
                     else:
                         # FIXME: this is not safe - use another symbol for right boundaries!
-                        self.__log.debug("Unnamed TextMark found, outside of any Markers")
+                        LOG.debug("Unnamed TextMark found, outside of any Markers")
                         return
 
                 # move left by one char and continue
@@ -312,7 +312,7 @@ class Editor(object):
         """
         This may be overridden to catch special types like LaTeXSource
         """
-        self.__log.debug("insert(%s)" % source)
+        LOG.debug("insert(%s)" % source)
 
         if type(source) is Template:
             self._template_delegate.insert(source)
@@ -428,13 +428,13 @@ class Editor(object):
 
         # check offsets
         if start_offset < 0:
-            self.__log.error("create_marker(): start offset out of range (%s < 0)" % start_offset)
+            LOG.error("create_marker(): start offset out of range (%s < 0)" % start_offset)
             return
 
         buffer_end_offset = self._text_buffer.get_end_iter().get_offset()
 
         if end_offset > buffer_end_offset:
-            self.__log.error("create_marker(): end offset out of range (%s > %s)" % (end_offset, buffer_end_offset))
+            LOG.error("create_marker(): end offset out of range (%s > %s)" % (end_offset, buffer_end_offset))
 
         type_record = self._marker_types[marker_type]
 
@@ -457,7 +457,7 @@ class Editor(object):
             return None
         else:
             # create unique marker id
-            id = str(uuid1())
+            id = str(uuid.uuid1())
 
             # create Marker object and put into map
             left_mark = self._text_buffer.create_mark(id, left, True)
@@ -573,7 +573,6 @@ class Editor(object):
         """
         The edited file has been closed or saved as another file
         """
-        self.__log.debug("destroy")
 
         # disconnect signal handlers
         for handler in self.__view_signal_handlers:
@@ -607,7 +606,4 @@ class Editor(object):
         # unreference the window context
         del self._window_context
 
-    def __del__(self):
-        self._log.debug("Properly destroyed %s" % self)
-
 # ex:ts=4:et:
diff --git a/latex/bibtex/editor.py b/latex/bibtex/editor.py
index 0d84cc1..6c20757 100644
--- a/latex/bibtex/editor.py
+++ b/latex/bibtex/editor.py
@@ -22,7 +22,10 @@
 bibtex.editor
 """
 
-from logging import getLogger
+BENCHMARK = True
+
+import logging
+if BENCHMARK: import time
 
 from ..base.editor import Editor
 from ..preferences import Preferences
@@ -35,12 +38,7 @@ from parser import BibTeXParser
 from completion import BibTeXCompletionHandler
 from validator import BibTeXValidator
 
-
-BENCHMARK = True
-
-if BENCHMARK:
-    import time
-
+LOG = logging.getLogger(__name__)
 
 class ParseJob(Job):
     def _run(self, arguments):
@@ -52,7 +50,6 @@ class ParseJob(Job):
 
 class BibTeXEditor(Editor, IIssueHandler, JobChangeListener):
 
-    _log = getLogger("BibTeXEditor")
     extensions = [".bib"]
 
     @property
@@ -65,7 +62,7 @@ class BibTeXEditor(Editor, IIssueHandler, JobChangeListener):
         self._parse_job = None
 
     def init(self, file, context):
-        self._log.debug("init(%s)" % file)
+        LOG.debug("init(%s)" % file)
 
         self._preferences = Preferences()
 
@@ -136,7 +133,7 @@ class BibTeXEditor(Editor, IIssueHandler, JobChangeListener):
     def __parse(self):
         """
         """
-        self._log.debug("__parse")
+        LOG.debug("__parse")
 
         content = self.content
 
@@ -156,9 +153,9 @@ class BibTeXEditor(Editor, IIssueHandler, JobChangeListener):
         self._document = self._parser.parse(content, self._file, self)
 
         if BENCHMARK:
-            self._log.info("BibTeXParser.parse: %f" % (time.clock() - t))
+            LOG.info("BibTeXParser.parse: %f" % (time.clock() - t))
 
-        self._log.debug("Parsed %s bytes of content" % len(content))
+        LOG.debug("Parsed %s bytes of content" % len(content))
 
         # validate
         if BENCHMARK:
@@ -168,7 +165,7 @@ class BibTeXEditor(Editor, IIssueHandler, JobChangeListener):
 
         # 0.11
         if BENCHMARK:
-            self._log.info("BibTeXValidator.validate: %f" % (time.clock() - t))
+            LOG.info("BibTeXValidator.validate: %f" % (time.clock() - t))
 
         self._outline_view.set_outline(self._document)
 
@@ -206,9 +203,4 @@ class BibTeXEditor(Editor, IIssueHandler, JobChangeListener):
 
         Editor.destroy(self)
 
-    def __del__(self):
-        self._log.debug("Properly destroyed %s" % self)
-
-
-
 # ex:ts=4:et:
diff --git a/latex/latex/editor.py b/latex/latex/editor.py
index 3312348..90668cb 100644
--- a/latex/latex/editor.py
+++ b/latex/latex/editor.py
@@ -24,13 +24,11 @@ latex.editor
 
 BENCHMARK = True
 
-from copy import deepcopy
+import logging
+if BENCHMARK: import time
 
 from gi.repository import Gtk
 from gi.repository import Gdk
-from logging import getLogger
-
-if BENCHMARK: import time
 
 from ..base.editor import Editor
 from ..base.file import File
@@ -48,11 +46,10 @@ from dialogs import ChooseMasterDialog
 from . import LaTeXSource
 from ..preferences import Preferences, DocumentPreferences
 
+LOG = logging.getLogger(__name__)
 
 class LaTeXEditor(Editor, IIssueHandler):
 
-    _log = getLogger("LaTeXEditor")
-
     extensions = Preferences().get("latex-extensions").split(",")
 
     dnd_extensions = [".png", ".pdf", ".bib", ".tex"]
@@ -67,7 +64,7 @@ class LaTeXEditor(Editor, IIssueHandler):
         @param file: base.File
         @param context: base.WindowContext
         """
-        self._log.debug("init(%s)" % file)
+        LOG.debug("init(%s)" % file)
 
         self._file = file
         self._context = context
@@ -115,7 +112,7 @@ class LaTeXEditor(Editor, IIssueHandler):
 
         # TODO: we need to insert the source at the drop location - so pass it here
 
-        self._log.debug("drag_drop: %s" % files)
+        LOG.debug("drag_drop: %s" % files)
 
 #        if len(files) == 1:
 #            file = files[0]
@@ -167,7 +164,7 @@ class LaTeXEditor(Editor, IIssueHandler):
         self.__parse()    # ensure up-to-date document model
 
         if not self._document_is_master:
-            self._log.debug("ensure_packages: document is not a master")
+            LOG.debug("ensure_packages: document is not a master")
 
             # find the packages that haven't already been mentioned
             info_packages = [p for p in packages if not p in self._ensured_packages]
@@ -236,7 +233,7 @@ class LaTeXEditor(Editor, IIssueHandler):
             # content has changed so document model may be dirty
             self._change_reference = self.current_timestamp
 
-            self._log.debug("Parsing document...")
+            LOG.debug("Parsing document...")
 
             # reset highlight
             self.remove_markers("latex-error")
@@ -256,12 +253,9 @@ class LaTeXEditor(Editor, IIssueHandler):
             # update document preferences
             self._preferences.parse_content(self.content)
 
-            if BENCHMARK: self._log.info("LaTeXParser.parse: %f" % (time.clock() - t))
+            if BENCHMARK: LOG.info("LaTeXParser.parse: %f" % (time.clock() - t))
 
-            # create a copy that won't be expanded (e.g. for spell check)
-            #self._local_document = deepcopy(self._document)
-
-            self._log.debug("Parsed %s bytes of content" % len(self.content))
+            LOG.debug("Parsed %s bytes of content" % len(self.content))
 
             # FIXME: the LaTeXChooseMasterAction enabled state has to be updated on tab change, too!
 
@@ -283,7 +277,7 @@ class LaTeXEditor(Editor, IIssueHandler):
                 # validate
                 self._validator.validate(self._document, self._outline, self, self._preferences)
             else:
-                self._log.debug("Document is not a master")
+                LOG.debug("Document is not a master")
 
                 self._context.set_action_enabled("LaTeXChooseMasterAction", True)
                 self._document_is_master = False
@@ -322,9 +316,7 @@ class LaTeXEditor(Editor, IIssueHandler):
             # pass neighbor files to completion
             self.__update_neighbors()
 
-            self._log.debug("Parsing finished")
-
-            #print self._document.xml
+            LOG.debug("Parsing finished")
 
     def choose_master_file(self):
         master_filename = ChooseMasterDialog().run(self._file.dirname)
@@ -344,10 +336,10 @@ class LaTeXEditor(Editor, IIssueHandler):
         path = self._preferences.get("master-filename")
         if path != None:
             if File.is_absolute(path):
-                self._log.debug("Path is absolute")
+                LOG.debug("master path is absolute")
                 return File(path)
             else:
-                self._log.debug("Path is relative")
+                LOG.debug("master path is relative")
                 return File.create_from_relative_path(path, self._file.dirname)
         else:
             # master filename not found, ask user
@@ -407,8 +399,4 @@ class LaTeXEditor(Editor, IIssueHandler):
 
         Editor.destroy(self)
 
-    def __del__(self):
-        self._log.debug("Properly destroyed %s" % self)
-
-
 # ex:ts=4:et:



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]