Permalink
Browse files

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

  • Loading branch information...
1 parent becea84 commit f4361b24b2381a066af9272e22ff90831507fd8a @amolenaar amolenaar committed Feb 8, 2011
View
@@ -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
@@ -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
@@ -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
@@ -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):
@@ -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):
"""
@@ -6,15 +6,15 @@
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
from gaphor.diagram import DiagramItemMeta
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
@@ -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
@@ -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,20 +63,15 @@ 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)
try:
# 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):
@@ -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>
@@ -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')
@@ -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
@@ -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
@@ -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')
Oops, something went wrong.

0 comments on commit f4361b2

Please sign in to comment.