55from __future__ import absolute_import , with_statement
66
77import collections
8+ import logging
89import os
910import os .path
1011
@@ -21,6 +22,54 @@ class SassMiddleware(object):
2122 requested it finds a matched SASS/SCSS source file and then compiled
2223 it into CSS.
2324
25+ It shows syntax errors in three ways:
26+
27+ Heading comment
28+ The result CSS includes detailed error message in the heading
29+ CSS comment e.g.:
30+
31+ .. code-block:: css
32+
33+ /*
34+ Error: invalid property name
35+ */
36+
37+ Red text in ``body:before``
38+ The result CSS draws detailed error message in ``:before``
39+ pseudo-class of ``body`` element e.g.::
40+
41+ .. code-block:: css
42+
43+ /*
44+ body:before {
45+ content: 'Error: invalid property name';
46+ color: maroon;
47+ background-color: white;
48+ }
49+ */
50+
51+ In most cases you could be aware of syntax error by refreshing your
52+ working document because it will removes all other styles and leaves
53+ only a red text.
54+
55+ :mod:`logging`
56+ It logs syntax errors if exist during compilation to
57+ ``sassutils.wsgi.SassMiddleware`` logger with level ``ERROR``.
58+
59+ To enable this::
60+
61+ from logging import Formatter, StreamHandler, getLogger
62+ logger = getLogger('sassutils.wsgi.SassMiddleware')
63+ handler = StreamHandler(level=logging.ERROR)
64+ formatter = Formatter(fmt='*' * 80 + '\n %(message)s\n ' + '*' * 80)
65+ handler.setFormatter(formatter)
66+ logger.addHandler(handler)
67+
68+ Or simply::
69+
70+ import logging
71+ logging.basicConfig()
72+
2473 :param app: the WSGI application to wrap
2574 :type app: :class:`collections.Callable`
2675 :param manifests: build settings. the same format to
@@ -36,6 +85,10 @@ class SassMiddleware(object):
3685 It creates also source map files with filenames followed by
3786 :file:`.map` suffix.
3887
88+ .. versionadded:: 0.8.0
89+ It logs syntax errors if exist during compilation to
90+ ``sassutils.wsgi.SassMiddleware`` logger with level ``ERROR``.
91+
3992 """
4093
4194 def __init__ (self , app , manifests , package_dir = {},
@@ -80,6 +133,8 @@ def __call__(self, environ, start_response):
80133 except (IOError , OSError ):
81134 break
82135 except CompileError as e :
136+ logger = logging .getLogger (__name__ + '.SassMiddleware' )
137+ logger .error (str (e ))
83138 start_response (
84139 self .error_status ,
85140 [('Content-Type' , 'text/css; charset=utf-8' )]
0 commit comments