[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnue] r9940 - in trunk/gnue-common/src: apps base
From: |
reinhard |
Subject: |
[gnue] r9940 - in trunk/gnue-common/src: apps base |
Date: |
Tue, 6 Oct 2009 10:23:34 -0500 (CDT) |
Author: reinhard
Date: 2009-10-06 10:23:33 -0500 (Tue, 06 Oct 2009)
New Revision: 9940
Removed:
trunk/gnue-common/src/apps/GImportLogger.py
Modified:
trunk/gnue-common/src/apps/GDebug.py
trunk/gnue-common/src/base/__init__.py
trunk/gnue-common/src/base/log.py
trunk/gnue-common/src/base/plugin.py
Log:
Made import logging a general feature of GNUe.
Modified: trunk/gnue-common/src/apps/GDebug.py
===================================================================
--- trunk/gnue-common/src/apps/GDebug.py 2009-10-06 14:49:43 UTC (rev
9939)
+++ trunk/gnue-common/src/apps/GDebug.py 2009-10-06 15:23:33 UTC (rev
9940)
@@ -28,10 +28,6 @@
messages to a file.
"""
-import sys, os
-if '--debug-imports' in sys.argv or os.environ.has_key('GNUE_DEBUG_IMPORT'):
- from gnue.common.apps import GImportLogger
-
import __builtin__
import inspect
import os
Deleted: trunk/gnue-common/src/apps/GImportLogger.py
===================================================================
--- trunk/gnue-common/src/apps/GImportLogger.py 2009-10-06 14:49:43 UTC (rev
9939)
+++ trunk/gnue-common/src/apps/GImportLogger.py 2009-10-06 15:23:33 UTC (rev
9940)
@@ -1,75 +0,0 @@
-# GNU Enterprise Common Library - Application Services - Debugging support
-#
-# Copyright 2001-2009 Free Software Foundation
-#
-# This file is part of GNU Enterprise
-#
-# GNU Enterprise is free software; you can redistribute it
-# and/or modify it under the terms of the GNU General Public
-# License as published by the Free Software Foundation; either
-# version 2, or (at your option) any later version.
-#
-# GNU Enterprise is distributed in the hope that it will be
-# useful, but WITHOUT ANY WARRANTY; without even the implied
-# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
-# PURPOSE. See the GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public
-# License along with program; see the file COPYING. If not,
-# write to the Free Software Foundation, Inc., 59 Temple Place
-# - Suite 330, Boston, MA 02111-1307, USA.
-#
-# $Id$
-#
-"""
-Importing this module causes all modules imported after this
-to be printed to stdout
-"""
-
-import ihooks
-
-_import_indent = 0
-
-# =============================================================================
-# Hook into filesystem and interpreter
-# =============================================================================
-
-class MyHooks(ihooks.Hooks):
- """
- Hook class for filesystem and interpreter
- """
- pass
-
-
-# =============================================================================
-# Module loader class
-# =============================================================================
-
-class GImportLogger(ihooks.ModuleLoader):
- """
- Module loader class which prints all loaded modules to stdout
- """
-
- # -------------------------------------------------------------------------
- # Load a given module
- # -------------------------------------------------------------------------
-
- def load_module(self, name, stuff):
- """
- Load the module 'name'
-
- @returns: the loaded module
- """
-
- global _import_indent
-
- print "." * _import_indent + "Importing %s..." % name
-
- _import_indent += 1
-
- module = ihooks.ModuleLoader.load_module(self, name, stuff)
-
- _import_indent -= 1
- return module
-
-ihooks.ModuleImporter(GImportLogger(MyHooks())).install()
Modified: trunk/gnue-common/src/base/__init__.py
===================================================================
--- trunk/gnue-common/src/base/__init__.py 2009-10-06 14:49:43 UTC (rev
9939)
+++ trunk/gnue-common/src/base/__init__.py 2009-10-06 15:23:33 UTC (rev
9940)
@@ -32,3 +32,6 @@
# These modules add functions to the builtin namespace.
from gnue.common.lib import checktype
from gnue.common.base import i18n
+
+# Initialize logging
+from gnue.common.base import log
Modified: trunk/gnue-common/src/base/log.py
===================================================================
--- trunk/gnue-common/src/base/log.py 2009-10-06 14:49:43 UTC (rev 9939)
+++ trunk/gnue-common/src/base/log.py 2009-10-06 15:23:33 UTC (rev 9940)
@@ -94,6 +94,7 @@
an exception.
"""
+import ihooks
import inspect
import logging
import logging.config
@@ -462,6 +463,10 @@
inspect.currentframe().f_back)), *args, **kwargs)
+# =============================================================================
+# Explicit logging
+# =============================================================================
+
# -----------------------------------------------------------------------------
# Explicit logging to standard logger
# -----------------------------------------------------------------------------
@@ -668,6 +673,10 @@
return True
+# =============================================================================
+# Logger class
+# =============================================================================
+
# -----------------------------------------------------------------------------
# Derivate from standard Logger class to output correct caller information
# -----------------------------------------------------------------------------
@@ -709,24 +718,63 @@
exc_info, *vargs)
+# =============================================================================
+# Import logging
+# =============================================================================
+
+_IMPORT_INDENT = 0
+
+
# -----------------------------------------------------------------------------
+# Module loader class
+# -----------------------------------------------------------------------------
+
+class __ImportLogger(ihooks.ModuleLoader):
+
+ def load_module(self, name, stuff):
+
+ global _IMPORT_INDENT
+
+ debug_n('gnue.import', " " * _IMPORT_INDENT + name)
+ _IMPORT_INDENT += 1
+ module = ihooks.ModuleLoader.load_module(self, name, stuff)
+ _IMPORT_INDENT -= 1
+ return module
+
+
+# =============================================================================
# Module initialization
+# =============================================================================
+
# -----------------------------------------------------------------------------
+# Initialize general logging
+# -----------------------------------------------------------------------------
-# Use our own Logger class.
-logging.setLoggerClass(Logger)
+def __init_logging():
+ # Use our own Logger class.
+ logging.setLoggerClass(Logger)
-# Add level for deprecation warnings.
-logging.addLevelName(31, 'DEPRECATED')
+ # Add level for deprecation warnings.
+ logging.addLevelName(31, 'DEPRECATED')
-# Configure logging through configuration files, or use standard configuration
-# if no configuration files available.
-_CONFIG_FILES = utils.config_files('log')
-if _CONFIG_FILES:
- logging.config.fileConfig(_CONFIG_FILES)
-else:
- logging.basicConfig()
- logging.getLogger().setLevel(logging.DEBUG)
+ # Configure logging through configuration files, or use standard
configuration
+ # if no configuration files available.
+ config_files = utils.config_files('log')
+ if config_files:
+ logging.config.fileConfig(config_files)
+ else:
+ logging.basicConfig()
+ logging.getLogger().setLevel(logging.DEBUG)
-# Use our exception hook
-sys.excepthook = excepthook
+ # Use our exception hook.
+ sys.excepthook = excepthook
+
+ # Activate import logging.
+ ihooks.ModuleImporter(__ImportLogger(ihooks.Hooks())).install()
+
+
+# -----------------------------------------------------------------------------
+# Module init code
+# -----------------------------------------------------------------------------
+
+__init_logging()
Modified: trunk/gnue-common/src/base/plugin.py
===================================================================
--- trunk/gnue-common/src/base/plugin.py 2009-10-06 14:49:43 UTC (rev
9939)
+++ trunk/gnue-common/src/base/plugin.py 2009-10-06 15:23:33 UTC (rev
9940)
@@ -193,7 +193,7 @@
def __modules(package, want_packages):
- # package.__file__ is a directory if GImportLogger is in use. This makes it
+ # package.__file__ is a directory if ImportLogger is in use. This makes it
# necessary to 'simulate' a package, otherwise stepping down subpackages
# won't work.
if os.path.isdir(package.__file__):
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnue] r9940 - in trunk/gnue-common/src: apps base,
reinhard <=