← Back to team overview

configglue team mailing list archive

[Merge] lp:~ricardokirkner/configglue/1012766-custom-logger into lp:configglue

 

Ricardo Kirkner has proposed merging lp:~ricardokirkner/configglue/1012766-custom-logger into lp:configglue.

Requested reviews:
  Configglue developers (configglue)

For more details, see:
https://code.launchpad.net/~ricardokirkner/configglue/1012766-custom-logger/+merge/110536

Use custom logger instead of root logger
-- 
https://code.launchpad.net/~ricardokirkner/configglue/1012766-custom-logger/+merge/110536
Your team Configglue developers is requested to review the proposed merge of lp:~ricardokirkner/configglue/1012766-custom-logger into lp:configglue.
=== modified file 'configglue/parser.py'
--- configglue/parser.py	2011-07-30 14:32:21 +0000
+++ configglue/parser.py	2012-06-15 14:32:17 +0000
@@ -30,8 +30,6 @@
     NoSectionError,
 )
 
-from configglue.schema import DictOption
-
 
 __all__ = [
     'SchemaValidationError',
@@ -40,6 +38,8 @@
 
 CONFIG_FILE_ENCODING = 'utf-8'
 
+logger = logging.getLogger(__name__)
+
 
 class SchemaValidationError(Exception):
     """Exception class raised for any schema validation error."""
@@ -247,7 +247,7 @@
             try:
                 fp = codecs.open(path, 'r', CONFIG_FILE_ENCODING)
             except IOError:
-                logging.warn(
+                logger.warn(
                     'File {0} could not be read. Skipping.'.format(path))
                 continue
             self._read(fp, path, already_read=already_read)

=== modified file 'configglue/tests/test_parser.py'
--- configglue/tests/test_parser.py	2011-07-30 14:32:21 +0000
+++ configglue/tests/test_parser.py	2012-06-15 14:32:17 +0000
@@ -15,7 +15,6 @@
 #
 ###############################################################################
 
-import logging
 import os
 import shutil
 import tempfile
@@ -69,16 +68,9 @@
         os.write(fd, '[__main__]\nfoo=bar\n')
         os.close(fd)
 
-        # disable logging output during test
-        self.level = logging.getLogger().level
-        logging.disable('ERROR')
-
     def tearDown(self):
         os.remove(self.name)
 
-        # re-enable original logging level
-        logging.getLogger().setLevel(self.level)
-
     def test_basic_include(self):
         config = StringIO('[__main__]\nincludes=%s' % self.name)
         parser = SchemaConfigParser(self.schema)
@@ -94,7 +86,7 @@
         expected_location = self.name
         self.assertEqual(expected_location, location)
 
-    @patch('configglue.parser.logging.warn')
+    @patch('configglue.parser.logger.warn')
     @patch('configglue.parser.codecs.open')
     def test_read_ioerror(self, mock_open, mock_warn):
         mock_open.side_effect = IOError

=== modified file 'doc/topics/index.rst'
--- doc/topics/index.rst	2011-07-09 19:37:20 +0000
+++ doc/topics/index.rst	2012-06-15 14:32:17 +0000
@@ -12,4 +12,5 @@
    command-line
    environment-variables
    base-app
+   logging
 

=== added file 'doc/topics/logging.rst'
--- doc/topics/logging.rst	1970-01-01 00:00:00 +0000
+++ doc/topics/logging.rst	2012-06-15 14:32:17 +0000
@@ -0,0 +1,35 @@
+=======
+Logging
+=======
+
+configglue uses its own loggers to allow library users to define the desired
+verbosity.
+
+Existing loggers exposed by configglue are:
+
+  * configglue.parser
+
+To enable logging you need to configure the system like
+::
+
+    logging.dictConfig({
+        'loggers': {
+            'configglue.parser': {
+                'handlers': ['console'],
+                'level': 'WARNING',
+                },
+            },
+        'handlers': {
+            'console': {
+                'formatter': 'simple',
+                'class': 'logging.handlers.StreamHandler',
+                'level': 'WARNING'
+                'args': (sys.stdout,)
+                },
+            },
+        'formatters': {
+            'simple': {
+                'format': '%(levelname)s %(message)s'
+                }
+            },
+        })


Follow ups