Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Removed gaphor.misc.logger module. Use logging directly.

  • Loading branch information...
commit f4361b24b2381a066af9272e22ff90831507fd8a 1 parent becea84
@amolenaar amolenaar authored
View
36 gaphor/__init__.py
@@ -9,13 +9,15 @@
__all__ = [ 'main' ]
from optparse import OptionParser
+import logging
import pygtk
-from gaphor.misc.logger import Logger
from gaphor.application import Application
pygtk.require('2.0')
+LOG_FORMAT = '%(name)s %(levelname)s %(message)s'
+
def launch(model=None):
"""Start the main application by initiating and running Application.
@@ -55,25 +57,31 @@ def main():
parser = OptionParser()
parser.add_option('-p',\
- '--profile',\
+ '--profiler',\
action='store_true',\
- help='Run in profile')
-
- parser.add_option('-l',\
- '--logging',\
- default='INFO',\
- help='Logging level')
-
+ help='Run in profiler')
+ parser.add_option('-q', "--quiet",
+ dest='quiet', help='Quiet output',
+ default=False, action='store_true')
+ parser.add_option('-v', '--verbose',
+ dest='verbose', help='Verbose output',
+ default=False, action="store_true")
+
options, args = parser.parse_args()
- Logger.log_level = Logger.level_map[options.logging]
-
+ if options.verbose:
+ logging.basicConfig(level=logging.DEBUG, format=LOG_FORMAT)
+ elif options.quiet:
+ logging.basicConfig(level=logging.WARNING, format=LOG_FORMAT)
+ else:
+ logging.basicConfig(level=logging.INFO, format=LOG_FORMAT)
+
try:
- model = args[1]
+ model = args[0]
except IndexError:
model = None
- if options.profile:
+ if options.profiler:
import cProfile
import pstats
@@ -91,6 +99,6 @@ def main():
# TODO: Remove this.
import __builtin__
-__builtin__.__dict__['log'] = Logger()
+__builtin__.__dict__['log'] = logging.getLogger('Gaphor')
# vim:sw=4:et:ai
View
5 gaphor/adapters/connectors.py
@@ -6,16 +6,17 @@
"""
from zope import interface, component
+from logging import getLogger
from gaphas import geometry
-from gaphor.misc.logger import Logger
from gaphor import UML
from gaphor.core import inject
from gaphor.diagram.interfaces import IConnect
from gaphor.diagram import items
-logger = Logger(name='CONNECTOR')
+logger = getLogger('Connector')
+
class AbstractConnect(object):
"""
View
4 gaphor/application.py
@@ -12,11 +12,11 @@
import pkg_resources
from zope import component
-from gaphor.misc.logger import Logger
+from logging import getLogger
from gaphor.interfaces import IService, IEventFilter
from gaphor.event import ServiceInitializedEvent, ServiceShutdownEvent
-logger = Logger()
+logger = getLogger('Application')
class NotInitializedError(Exception):
pass
View
2  gaphor/diagram/compartment.py
@@ -332,7 +332,7 @@ def update_stereotypes_attrs(self):
self._create_stereotype_compartment(obj)
log.debug('Showing stereotypes attributes enabled')
else:
- log.trace('Showing stereotypes attributes disabled')
+ log.debug('Showing stereotypes attributes disabled')
def save(self, save_func):
View
4 gaphor/diagram/connector.py
@@ -100,14 +100,14 @@ class and `InterfaceItem` class in assembly connector mode.
interfaces are connectable elements.
"""
-from gaphor.misc.logger import Logger
+from logging import getLogger
from gaphor import UML
from gaphor.diagram.diagramline import NamedLine
from gaphor.diagram.style import ALIGN_CENTER, ALIGN_BOTTOM
from operator import attrgetter
-logger = Logger(name='CONNECTOR')
+logger = getLogger('Connector')
class ConnectorItem(NamedLine):
"""
View
4 gaphor/diagram/diagramitem.py
@@ -6,7 +6,7 @@
from zope import component
from gaphas.state import observed, reversible_property
-from gaphor.misc.logger import Logger
+from logging import getLogger
from gaphor import UML
from gaphor.services.elementdispatcher import EventWatcher
from gaphor.core import inject
@@ -14,7 +14,7 @@
from gaphor.diagram.textelement import EditableTextSupport
from gaphor.diagram.style import ALIGN_CENTER, ALIGN_TOP
-logger = Logger(name='DIAGRAM')
+logger = getLogger('Diagram')
class StereotypeSupport(object):
"""
View
61 gaphor/misc/logger.py
@@ -1,61 +0,0 @@
-"""Logger is a simple entry point for writing log messages.
-
-It wraps the logging module and adds some basic configuration."""
-
-import logging
-
-logging.basicConfig(level=logging.DEBUG,
- format='%(name)s %(levelname)s %(message)s')
-
-class Logger(object):
- TRACE = 0
- DEBUG = logging.DEBUG
- INFO = logging.INFO
- WARNING = logging.WARNING
- ERROR = logging.ERROR
- CRITICAL = logging.CRITICAL
-
- level_map = dict(TRACE = 0,\
- DEBUG = logging.DEBUG,\
- INFO = logging.INFO,\
- WARNING = logging.WARNING,\
- ERROR = logging.ERROR,\
- CRITICAL = logging.CRITICAL)
-
- level = logging.DEBUG
-
- def __init__(self, name='GAPHOR'):
- self.logger = logging.getLogger(name)
- self.log_level = self.level
-
- def set_log_level(self, level):
- self.logger.setLevel(level)
-
- def get_log_level(self, level):
- return self.logger.getEffectiveLevel()
-
- log_level = property(get_log_level, set_log_level, None, 'Log level')
-
- def log(self, level, message, exc=None):
- self.logger.log(level, message, exc_info=exc)
-
- def trace(self, message, exc=None):
- self.log(Logger.TRACE, message, exc)
-
- def debug(self, message, exc=None):
- self.log(Logger.DEBUG, message, exc)
-
- def info(self, message, exc=None):
- self.log(Logger.INFO, message, exc)
-
- def warning(self, message, exc=None):
- self.log(Logger.WARNING, message, exc)
-
- def error(self, message, exc=None):
- self.log(Logger.ERROR, message, exc)
-
- def critical(self, message, exc=None):
- self.log(Logger.CRITICAL, message, exc)
-
-
-# vim:sw=4
View
16 gaphor/services/actionmanager.py
@@ -4,7 +4,7 @@
import gtk
from zope import interface, component
-from gaphor.misc.logger import Logger
+from logging import getLogger
from gaphor.core import inject
from gaphor.interfaces import IService, IActionProvider
from gaphor.event import ServiceInitializedEvent, ActionExecuted
@@ -15,7 +15,7 @@ class ActionManager(object):
"""
interface.implements(IService)
- logger = Logger(name='ACTIONMANAGER')
+ logger = getLogger('ActionManager')
component_registry = inject('component_registry')
@@ -42,8 +42,7 @@ def shutdown(self):
def execute(self, action_id, active=None):
- self.logger.info('Executing action')
- self.logger.debug('Action ID is %s' % action_id)
+ self.logger.debug('Executing action, action_id is %s' % action_id)
a = self.get_action(action_id)
if a:
@@ -64,8 +63,7 @@ def get_action(self, action_id):
def register_action_provider(self, action_provider):
- self.logger.info('Registering action provider')
- self.logger.debug('Action provider is %s' % action_provider)
+ self.logger.debug('Registering action provider %s' % action_provider)
action_provider = IActionProvider(action_provider)
@@ -73,11 +71,7 @@ def register_action_provider(self, action_provider):
# Check if the action provider is not already registered
action_provider.__ui_merge_id
except AttributeError:
-
- self.logger.debug('Registering actions for %s' % action_provider)
-
assert action_provider.action_group
-
self.ui_manager.insert_action_group(action_provider.action_group, -1)
try:
@@ -91,7 +85,7 @@ def register_action_provider(self, action_provider):
@component.adapter(ServiceInitializedEvent)
def _service_initialized_handler(self, event):
- self.logger.info('Handling ServiceInitializedEvent')
+ self.logger.debug('Handling ServiceInitializedEvent')
self.logger.debug('Service is %s' % event.service)
if IActionProvider.providedBy(event.service):
View
4 gaphor/services/diagramexportmanager.py
@@ -7,7 +7,7 @@
from zope import interface, component
-from gaphor.misc.logger import Logger
+from logging import getLogger
from gaphor.core import _, inject, action, build_action_group
from gaphor.interfaces import IService, IActionProvider
from gaphor.ui.filedialog import FileDialog
@@ -27,7 +27,7 @@ class DiagramExportManager(object):
main_window = inject('main_window')
properties = inject('properties')
- logger = Logger(name='EXPORTMANAGER')
+ logger = getLogger('ExportManager')
menu_xml = """
<ui>
View
6 gaphor/services/elementdispatcher.py
@@ -3,7 +3,7 @@
from zope import interface, component
-from gaphor.misc.logger import Logger
+from logging import getLogger
from gaphor.core import inject
from gaphor.interfaces import IService
from gaphor.UML.interfaces import IElementChangeEvent, IModelFactoryEvent
@@ -18,7 +18,7 @@ class EventWatcher(object):
"""
element_dispatcher = inject('element_dispatcher')
- logger = Logger(name='EVENTWATCHER')
+ logger = getLogger('EventWatcher')
def __init__(self, element, default_handler=None):
super(EventWatcher, self).__init__()
@@ -111,7 +111,7 @@ class ElementDispatcher(object):
"""
interface.implements(IService)
- logger = Logger(name='ELEMENTDISPATCHER')
+ logger = getLogger('ElementDispatcher')
component_registry = inject('component_registry')
View
8 gaphor/services/filemanager.py
@@ -9,7 +9,7 @@
from gaphor.core import _, inject, action, build_action_group
from gaphor.storage import storage, verify
from gaphor import UML
-from gaphor.misc.logger import Logger
+from logging import getLogger
from gaphor.misc.gidlethread import GIdleThread, Queue, QueueEmpty
from gaphor.misc.xmlwriter import XMLWriter
from gaphor.ui.statuswindow import StatusWindow
@@ -41,7 +41,7 @@ class FileManager(object):
element_factory = inject('element_factory')
main_window = inject('main_window')
properties = inject('properties')
- logger = Logger(name='FILEMANAGER')
+ logger = getLogger('FileManager')
menu_xml = """
<ui>
@@ -214,8 +214,8 @@ def load(self, filename):
worker.wait()
if worker.error:
- self.logger.error('Error loading file')
- self.logger.error(worker.error)
+ self.logger.error('Error loading file: ', exc_info=worker.exc_info)
+ #self.logger.error(worker.error)
self.filename = filename
View
4 gaphor/services/properties.py
@@ -7,7 +7,7 @@
from zope import interface
from gaphor.core import inject
-from gaphor.misc.logger import Logger
+from logging import getLogger
from gaphor.interfaces import IService
from gaphas.decorators import async
from gaphor.misc import get_user_data_dir
@@ -44,7 +44,7 @@ class Properties(object):
component_registry = inject('component_registry')
- logger = Logger(name='PROPERTIES')
+ logger = getLogger('Properties')
def __init__(self, backend=None):
"""Constructor. Initialize the Gaphor application object, the
View
4 gaphor/services/propertydispatcher.py
@@ -3,7 +3,7 @@
from zope import interface, component
-from gaphor.misc.logger import Logger
+from logging import getLogger
from gaphor.core import inject
from gaphor.interfaces import IService
from gaphor.UML.interfaces import IElementChangeEvent
@@ -20,7 +20,7 @@ class PropertyDispatcher(object):
"""
interface.implements(IService)
- logger = Logger(name='PROPERTYDISPATCHER')
+ logger = getLogger('PropertyDispatcher')
component_registry = inject('component_registry')
View
42 gaphor/services/sanitizerservice.py
@@ -6,7 +6,7 @@
from zope import interface
from zope import component
-from gaphor.misc.logger import Logger
+from logging import getLogger
from gaphor import UML
from gaphor.UML.interfaces import IAssociationDeleteEvent, IAssociationSetEvent
from gaphor.interfaces import IService
@@ -20,7 +20,7 @@ class SanitizerService(object):
"""
interface.implements(IService)
- logger = Logger(name='SANITIZER')
+ logger = getLogger('Sanitizer')
component_registry = inject('component_registry')
element_factory = inject('element_factory')
@@ -49,10 +49,10 @@ def _unlink_on_presentation_delete(self, event):
subject or the deleted item was the only item currently linked.
"""
- self.logger.info('Handling IAssociationDeleteEvent')
- self.logger.debug('Property is %s' % event.property.name)
- self.logger.debug('Element is %s' % event.element)
- self.logger.debug('Old value is %s' % event.old_value)
+ self.logger.debug('Handling IAssociationDeleteEvent')
+ #self.logger.debug('Property is %s' % event.property.name)
+ #self.logger.debug('Element is %s' % event.element)
+ #self.logger.debug('Old value is %s' % event.old_value)
if event.property is UML.Element.presentation:
old_presentation = event.old_value
@@ -61,9 +61,9 @@ def _unlink_on_presentation_delete(self, event):
def perform_unlink_for_instances(self, st, meta):
- self.logger.info('Performing unlink for instances')
- self.logger.debug('Stereotype is %s' % st)
- self.logger.debug('Meta is %s' % meta)
+ self.logger.debug('Performing unlink for instances')
+ #self.logger.debug('Stereotype is %s' % st)
+ #self.logger.debug('Meta is %s' % meta)
inst = UML.model.find_instances(self.element_factory, st)
@@ -79,10 +79,10 @@ def _unlink_on_extension_delete(self, event):
Remove applied stereotypes when extension is deleted.
"""
- self.logger.info('Handling IAssociationDeleteEvent')
- self.logger.debug('Property is %s' % event.property.name)
- self.logger.debug('Element is %s' % event.element)
- self.logger.debug('Old value is %s' % event.old_value)
+ self.logger.debug('Handling IAssociationDeleteEvent')
+ #self.logger.debug('Property is %s' % event.property.name)
+ #self.logger.debug('Element is %s' % event.element)
+ #self.logger.debug('Old value is %s' % event.old_value)
if isinstance(event.element, UML.Extension) and \
event.property is UML.Association.memberEnd and \
@@ -99,10 +99,10 @@ def _unlink_on_extension_delete(self, event):
@component.adapter(IAssociationSetEvent)
def _disconnect_extension_end(self, event):
- self.logger.info('Handling IAssociationSetEvent')
- self.logger.debug('Property is %s' % event.property.name)
- self.logger.debug('Element is %s' % event.element)
- self.logger.debug('Old value is %s' % event.old_value)
+ self.logger.debug('Handling IAssociationSetEvent')
+ #self.logger.debug('Property is %s' % event.property.name)
+ #self.logger.debug('Element is %s' % event.element)
+ #self.logger.debug('Old value is %s' % event.old_value)
if event.property is UML.ExtensionEnd.type and event.old_value:
ext = event.element
@@ -120,10 +120,10 @@ def _unlink_on_stereotype_delete(self, event):
Remove applied stereotypes when stereotype is deleted.
"""
- self.logger.info('Handling IAssociationDeleteEvent')
- self.logger.debug('Property is %s' % event.property)
- self.logger.debug('Element is %s' % event.element)
- self.logger.debug('Old value is %s' % event.old_value)
+ self.logger.debug('Handling IAssociationDeleteEvent')
+ #self.logger.debug('Property is %s' % event.property)
+ #self.logger.debug('Element is %s' % event.element)
+ #self.logger.debug('Old value is %s' % event.old_value)
if event.property is UML.InstanceSpecification.classifier:
if isinstance(event.old_value, UML.Stereotype):
View
4 gaphor/services/serviceregistry.py
@@ -7,14 +7,14 @@
from zope import interface, component
-from gaphor.misc.logger import Logger
+from logging import getLogger
from gaphor.interfaces import IService
from gaphor.core import inject
class ServiceRegistry(object):
component_registry = inject('component_registry')
- logger = Logger(name='SERVICEREGISTRY')
+ logger = getLogger('ServiceRegistry')
def __init__(self):
self._uninitialized_services = {}
View
4 gaphor/services/undomanager.py
@@ -17,7 +17,7 @@
from gaphas import state
from gaphor.core import inject
-from gaphor.misc.logger import Logger
+from logging import getLogger
from gaphor.interfaces import IService, IServiceEvent, IActionProvider
from gaphor.event import TransactionBegin, TransactionCommit, TransactionRollback
from gaphor.transaction import Transaction, transactional
@@ -107,7 +107,7 @@ class UndoManager(object):
component_registry = inject('component_registry')
- logger = Logger(name='UNDOMANAGER')
+ logger = getLogger('UndoManager')
def __init__(self):
self._undo_stack = []
View
18 gaphor/storage/storage.py
@@ -334,7 +334,7 @@ def load_generator(filename, factory):
#elements = parser.parse(filename)
#yield 100
except Exception, e:
- log.error('File could no be parsed', e)
+ log.error('File could no be parsed', exc_info=True)
raise
try:
@@ -363,7 +363,7 @@ def load_generator(filename, factory):
gc.collect()
yield 100
except Exception, e:
- log.info('file %s could not be loaded' % filename, e)
+ log.info('file %s could not be loaded' % filename)
raise
def version_lower_than(gaphor_version, version):
@@ -523,7 +523,7 @@ def create_slot(key, val):
log.info('Special case: UML metamodel "%s %s"' % (key, val))
create_slot(key, val)
except Exception, e:
- log.warning('Unable to process tagged value "%s" as key=value pair' % tv, e)
+ log.warning('Unable to process tagged value "%s" as key=value pair' % tv, exc_info=True)
def find(messages, attr):
occurrences = set(getattr(m, attr) for m in messages
@@ -648,7 +648,7 @@ def version_0_14_0(elements, factory, gaphor_version):
et.references['appliedStereotype'] = applied
except Exception, e:
- log.error('Error while updating stereotypes', e)
+ log.error('Error while updating stereotypes', exc_info=True)
def version_0_9_0(elements, factory, gaphor_version):
@@ -672,7 +672,7 @@ def version_0_9_0(elements, factory, gaphor_version):
del elem.values['color']
except Exception, e:
- log.error('Error while updating from DiaCanvas2', e)
+ log.error('Error while updating from DiaCanvas2', exc_info=True)
def version_0_7_2(elements, factory, gaphor_version):
"""
@@ -701,7 +701,7 @@ def version_0_7_2(elements, factory, gaphor_version):
tvlist.append(newtv.id)
elem.references['taggedValue'] = tvlist
except Exception, e:
- log.error('Error while updating taggedValues', e)
+ log.error('Error while updating taggedValues', exc_info=True)
def version_0_7_1(elements, factory, gaphor_version):
@@ -737,7 +737,7 @@ def fix(end1, end2):
fix(end1, end2)
fix(end2, end1)
except Exception, e:
- log.error('Error while updating Association', e)
+ log.error('Error while updating Association', exc_info=True)
def version_0_6_2(elements, factory, gaphor_version):
@@ -757,7 +757,7 @@ def version_0_6_2(elements, factory, gaphor_version):
elif p.type == 'InterfaceItem':
p.values['drawing-style'] = '2'
except Exception, e:
- log.error('Error while updating InterfaceItems', e)
+ log.error('Error while updating InterfaceItems', exc_info=True)
def version_0_5_2(elements, factory, gaphor_version):
@@ -776,7 +776,7 @@ def version_0_5_2(elements, factory, gaphor_version):
a.memberEnd[0].aggregation = agg2
a.memberEnd[1].aggregation = agg1
except Exception, e:
- log.error('Error while updating Association', e)
+ log.error('Error while updating Association', exc_info=True)
# vim: sw=4:et:ai
View
7 gaphor/ui/mainwindow.py
@@ -4,6 +4,7 @@
import os.path
import gobject, gtk
+from logging import getLogger
import pkg_resources
from zope import interface, component
@@ -30,7 +31,8 @@
from gaphor.services.filemanager import FileManagerStateChanged
from gaphor.services.undomanager import UndoManagerStateChanged
from gaphor.ui.accelmap import load_accel_map, save_accel_map
-from gaphor.misc.logger import Logger
+
+logger = getLogger(name='MainWindow')
ICONS = (
'gaphor-24x24.png',
@@ -63,7 +65,6 @@ class MainWindow(object):
"""
interface.implements(IService, IActionProvider)
- logger = Logger(name='MAINWINDOW')
component_registry = inject('component_registry')
properties = inject('properties')
@@ -323,7 +324,7 @@ def open(self):
def _factory(name):
comp = self.component_registry.get_utility(IUIComponent, name)
- self.logger.debug('open comp %s', comp)
+ logger.debug('open component %s' % str(comp))
return comp.open()
filename = pkg_resources.resource_filename('gaphor.ui', 'layout.xml')
Please sign in to comment.
Something went wrong with that request. Please try again.