[gedit-latex] More logging cleanups
- From: John Stowers <jstowers src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit-latex] More logging cleanups
- Date: Fri, 2 Sep 2011 00:42:59 +0000 (UTC)
commit f9f4b28b133a29ed5104b19baf4517b6b0d58790
Author: John Stowers <john stowers gmail com>
Date: Fri Sep 2 12:42:43 2011 +1200
More logging cleanups
latex/base/decorators.py | 21 +++++++++------------
latex/latex/model.py | 33 ++++++++++++---------------------
latex/tools/__init__.py | 22 ++++++++++------------
3 files changed, 31 insertions(+), 45 deletions(-)
---
diff --git a/latex/base/decorators.py b/latex/base/decorators.py
index 96795c1..d4f7bc9 100644
--- a/latex/base/decorators.py
+++ b/latex/base/decorators.py
@@ -25,7 +25,8 @@ These classes are 'attached' to the according Gedit objects. They form the
extension point.
"""
-from logging import getLogger
+import logging
+
from gi.repository import Gedit, Gtk, Gio
from config import EDITORS
@@ -33,6 +34,7 @@ from .file import File
# TODO: maybe create ActionDelegate for GeditWindowDecorator
+LOG = logging.getLogger(__name__)
class GeditTabDecorator(object):
"""
@@ -40,8 +42,6 @@ class GeditTabDecorator(object):
according to the current file extension
"""
- _log = getLogger("GeditTabDecorator")
-
def __init__(self, window_decorator, tab, init=False):
"""
Construct a GeditTabDecorator
@@ -72,7 +72,7 @@ class GeditTabDecorator(object):
self._text_buffer.connect("saved", self._on_save)
]
- self._log.debug("Created %s" % self)
+ LOG.debug("created %s" % self)
@property
def tab(self):
@@ -82,7 +82,7 @@ class GeditTabDecorator(object):
"""
A file has been loaded
"""
- self._log.debug("loaded")
+ LOG.debug("file loaded")
self._adjust_editor()
@@ -90,7 +90,7 @@ class GeditTabDecorator(object):
"""
The file has been saved
"""
- self._log.debug("saved")
+ LOG.debug("saved")
if not self._adjust_editor():
# if the editor has not changed
@@ -109,7 +109,7 @@ class GeditTabDecorator(object):
# this happends when the plugin is activated in a running Gedit
# and this decorator is created for the empty file
- self._log.debug("No file loaded")
+ LOG.debug("no file loaded")
if self._window_decorator.window.get_active_view() == self._text_view:
self._window_decorator.adjust(self)
@@ -120,7 +120,7 @@ class GeditTabDecorator(object):
if file == self._file: # FIXME: != doesn't work for File...
return False
else:
- self._log.debug("_adjust_editor: URI has changed")
+ LOG.debug("adjust_editor: URI has changed")
self._file = file
@@ -165,7 +165,7 @@ class GeditTabDecorator(object):
#self._editor = editor_class(self, file)
else:
- self._log.warning("No editor class found for extension %s" % extension)
+ LOG.info("No editor class found for extension %s" % extension)
# tell WindowDecorator to adjust actions
# but only if this tab is the active tab
@@ -205,7 +205,4 @@ class GeditTabDecorator(object):
if not self._editor is None:
self._editor.destroy()
- def __del__(self):
- self._log.debug("Properly destroyed %s" % self)
-
# ex:ts=4:et:
diff --git a/latex/latex/model.py b/latex/latex/model.py
index 4c18b76..06706b3 100644
--- a/latex/latex/model.py
+++ b/latex/latex/model.py
@@ -25,10 +25,11 @@ The LaTeX language model used for code completion.
"""
import copy
-from logging import getLogger
+import logging
from ..base.resources import Resources
+LOG = logging.getLogger(__name__)
class Element(object):
"""
@@ -137,8 +138,6 @@ class LanguageModel(object):
REF_CMDS = set(("ref","eqref","pageref"))
- __log = getLogger("LanguageModel")
-
def __init__(self):
self.commands = {} # maps command names to Command elements
self.VERSION = LANGUAGE_MODEL_VERSION
@@ -149,8 +148,6 @@ class LanguageModel(object):
#some latex specific helpers.
self.__new_ref_commands = {}
- self.__log.debug("LanguageModel init")
-
def find_command(self, prefix):
"""
Find a command by a prefix. A prefix like 'be' would return the command '\begin'
@@ -173,18 +170,16 @@ class LanguageModel(object):
Attach child elements to a placeholder
"""
try:
- #self.__log.debug("fill_placeholder: name=%s, child_elements=%s" % (name, child_elements))
-
for placeholder in self.__placeholders[name]:
placeholder.children = child_elements
except KeyError:
- self.__log.error("fill_placeholder: placeholder '%s' not registered" % name)
+ LOG.info("fill_placeholder: placeholder '%s' not registered" % name)
def is_ref_command(self, cmd_name):
return (cmd_name in self.REF_CMDS) or (cmd_name in self.__new_ref_commands)
def set_newcommands(self, outlinenodes):
- self.__log.debug("Set newcommands")
+ LOG.debug("set newcommands")
#remove old state
self.__new_ref_commands = {}
@@ -196,7 +191,7 @@ class LanguageModel(object):
#if this is a redefinition of an existing node then use that node as
#the completion helper
if o.oldcmd and o.oldcmd in self.commands:
- self.__log.info("Detected redefined \\newcommand: %s -> %s" % (o.value, o.oldcmd))
+ LOG.info("Detected redefined \\newcommand: %s -> %s" % (o.value, o.oldcmd))
#copy the old command so we retain its argument completion but change
#the display name
old = copy.copy(self.commands[o.oldcmd])
@@ -226,15 +221,13 @@ class LanguageModelParser(sax.ContentHandler):
# TODO: this should be a simple state machine
- __log = getLogger("LanguageModelParser")
-
def parse(self, filename, language_model):
self.__language_model = language_model
self.__command = None
self.__argument = None
- self.__log.debug("Parsing %s" % filename)
+ LOG.debug("parsing %s" % filename)
sax.parse(filename, self)
@@ -289,8 +282,6 @@ class LanguageModelFactory(object):
of this object is returned. Otherwise the XML file must be parsed.
"""
- __log = getLogger("LanguageModelFactory")
-
def __new__(cls):
if not '_instance' in cls.__dict__:
cls._instance = object.__new__(cls)
@@ -302,10 +293,10 @@ class LanguageModelFactory(object):
pickled_object = self.__find_pickled_object()
if pickled_object:
- self.__log.debug("Pickled object loaded")
+ LOG.debug("language model: pickled object loaded")
self.language_model = pickled_object
else:
- self.__log.debug("No pickled object loaded")
+ LOG.debug("language model: no pickled object loaded")
pkl_filename = Resources().get_user_file("latex.pkl")
xml_filename = Resources().get_data_file("latex.xml")
@@ -314,7 +305,7 @@ class LanguageModelFactory(object):
parser.parse(xml_filename, self.language_model)
pickle.dump(self.language_model, open(pkl_filename, 'w'))
- self.__log.info("Pickling language model")
+ LOG.info("Pickling language model")
self._ready = True
@@ -324,16 +315,16 @@ class LanguageModelFactory(object):
if pkl_file.exists:
if xml_file.mtime > pkl_file.mtime:
- self.__log.debug("Pickled object and XML file have different modification times")
+ LOG.debug("Pickled object and XML file have different modification times")
else:
try:
obj = pickle.load(open(pkl_file.path))
if obj.VERSION == LANGUAGE_MODEL_VERSION:
return obj
else:
- self.__log.info("Language model obsolete")
+ LOG.info("Language model obsolete")
except:
- self.__log.info("Invalid language model", exc_info=True)
+ LOG.info("Invalid language model", exc_info=True)
return None
diff --git a/latex/tools/__init__.py b/latex/tools/__init__.py
index 8b0a473..bd992d7 100644
--- a/latex/tools/__init__.py
+++ b/latex/tools/__init__.py
@@ -25,11 +25,14 @@ A tool is what we called a 'build profile' before. 'Tool' is more generic.
It can be used for cleaning up, converting files, for building PDFs etc.
"""
-from logging import getLogger
+import logging
+
from gi.repository import Gtk, Gedit
+
from ..base.resources import Resources
from ..base.action import Action
+LOG = logging.getLogger(__name__)
class Tool(object):
"""
@@ -93,8 +96,6 @@ class ToolAction(Action):
This hooks Tools in the UI. A ToolAction is instantiated for each registered Tool.
"""
- _log = getLogger("ToolAction")
-
def __init__(self, tool):
self._tool = tool
self._runner = ToolRunner()
@@ -116,20 +117,20 @@ class ToolAction(Action):
return self._tool.description
def activate(self, context):
- self._log.debug("activate: %s" % self._tool)
+ LOG.debug("tool activate: %s" % self._tool)
if context.active_editor:
doc = Gedit.App.get_default().get_active_window().get_active_document()
self.saving_id = doc.connect("saved",self.run_tool,context,doc)
context._window_decorator.save_file()
else:
- self._log.error("No active editor")
+ LOG.error("tool activate: no active editor")
def run_tool(self, document, other, context, doc):
tool_view = context.find_view(None, "ToolView")
self._runner.run(context.active_editor.file, self._tool, tool_view)
- self._log.debug("activate: " + str(context.active_editor.file))
+ LOG.debug("run tool on: %s" % context.active_editor.file)
# destroy the save listener, or else we get a compile on any save
doc.disconnect(self.saving_id)
@@ -146,8 +147,6 @@ class ToolRunner(Process):
This runs a Tool in a subprocess
"""
- _log = getLogger("ToolRunner")
-
def run(self, file, tool, issue_handler):
"""
@param file: a File object
@@ -206,19 +205,18 @@ class ToolRunner(Process):
def _on_stdout(self, text):
"""
"""
- self._log.error("_stdout: " + text)
+ LOG.debug("tool stdout: " + text)
self._stdout_text += text
def _on_stderr(self, text):
"""
"""
- self._log.debug("_stderr: " + text)
+ LOG.debug("tool stderr: " + text)
self._stderr_text += text
def _on_abort(self):
"""
"""
- self._log.debug("_abort")
# disable abort
self._issue_handler.set_abort_enabled(False, None)
# mark Tool and all Jobs as aborted
@@ -230,7 +228,7 @@ class ToolRunner(Process):
def _on_exit(self, condition):
"""
"""
- self._log.debug("_exit")
+ LOG.debug("tool exit")
assert self._job
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]