Repository: mkdocs/mkdocs

Issue:
`mkdocs serve` doesn't recover from build errors
For example, add a new page to the `pages` setting before you create the file, you then need to manually restart the serve command.



Discussion:

Resolving patch:
diff --git a/mkdocs/build.py b/mkdocs/build.py
--- a/mkdocs/build.py
+++ b/mkdocs/build.py
@@ -9,6 +9,9 @@
 import json
 import markdown
 import os
+import logging
+
+log = logging.getLogger('mkdocs')
 
 
 def convert_markdown(markdown_source, site_navigation=None, extensions=(), strict=False):
@@ -159,7 +162,10 @@ def build_pages(config, dump_json=False):
     for page in site_navigation.walk_pages():
         # Read the input file
         input_path = os.path.join(config['docs_dir'], page.input_path)
-        input_content = open(input_path, 'r').read()
+        try:
+            input_content = open(input_path, 'r').read()
+        except IOError:
+            log.error('file not found: %s' % input_path)
         if PY2:
             input_content = input_content.decode('utf-8')
 
diff --git a/mkdocs/config.py b/mkdocs/config.py
--- a/mkdocs/config.py
+++ b/mkdocs/config.py
@@ -4,9 +4,12 @@
 from mkdocs.compat import urlparse
 from mkdocs.exceptions import ConfigurationError
 
+import logging
 import os
 import yaml
 
+log = logging.getLogger(__name__)
+
 DEFAULT_CONFIG = {
     'site_name': None,
     'pages': None,
diff --git a/mkdocs/main.py b/mkdocs/main.py
--- a/mkdocs/main.py
+++ b/mkdocs/main.py
@@ -2,6 +2,7 @@
 # coding: utf-8
 from __future__ import print_function
 
+import logging
 import sys
 
 from mkdocs import __version__
@@ -13,6 +14,16 @@
 from mkdocs.serve import serve
 
 
+def configure_logging(options):
+    '''When a --verbose flag is passed, increase the verbosity of mkdocs'''
+    logger = logging.getLogger('mkdocs')
+    logger.addHandler(logging.StreamHandler())
+    if 'verbose' in options:
+        logger.setLevel(logging.DEBUG)
+    else:
+        logger.setLevel(logging.WARNING)
+
+
 def arg_to_option(arg):
     """
     Convert command line arguments into two-tuples of config key/value pairs.
@@ -28,6 +39,7 @@ def main(cmd, args, options=None):
     """
     Build the documentation, and optionally start the devserver.
     """
+    configure_logging(options)
     clean_site_dir = 'clean' in options
     if cmd == 'serve':
         config = load_config(options=options)


Test patch:
diff --git a/mkdocs/test.py b/mkdocs/test.py
--- a/mkdocs/test.py
+++ b/mkdocs/test.py
@@ -5,6 +5,7 @@
 from mkdocs import build, main, nav, toc, utils, config
 from mkdocs.compat import PY2, zip
 from mkdocs.exceptions import ConfigurationError, MarkdownNotFound
+import logging
 import markdown
 import mock
 import os
@@ -40,6 +41,16 @@ def test_arg_to_option(self):
         self.assertEqual('use_directory_urls', arg)
         self.assertEqual(True, option)
 
+    def test_configure_logging(self):
+        """
+        Check that logging is configured correctly
+        """
+        logger = logging.getLogger('mkdocs')
+        main.configure_logging({})
+        self.assertEqual(logging.WARNING, logger.level)
+        main.configure_logging({'verbose': True})
+        self.assertEqual(logging.DEBUG, logger.level)
+
 
 class ConfigTests(unittest.TestCase):
     def test_missing_config_file(self):