5
5
from __future__ import absolute_import , with_statement
6
6
7
7
import collections
8
+ import logging
8
9
import os
9
10
import os .path
10
11
@@ -21,6 +22,54 @@ class SassMiddleware(object):
21
22
requested it finds a matched SASS/SCSS source file and then compiled
22
23
it into CSS.
23
24
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
+
24
73
:param app: the WSGI application to wrap
25
74
:type app: :class:`collections.Callable`
26
75
:param manifests: build settings. the same format to
@@ -36,6 +85,10 @@ class SassMiddleware(object):
36
85
It creates also source map files with filenames followed by
37
86
:file:`.map` suffix.
38
87
88
+ .. versionadded:: 0.8.0
89
+ It logs syntax errors if exist during compilation to
90
+ ``sassutils.wsgi.SassMiddleware`` logger with level ``ERROR``.
91
+
39
92
"""
40
93
41
94
def __init__ (self , app , manifests , package_dir = {},
@@ -80,6 +133,8 @@ def __call__(self, environ, start_response):
80
133
except (IOError , OSError ):
81
134
break
82
135
except CompileError as e :
136
+ logger = logging .getLogger (__name__ + '.SassMiddleware' )
137
+ logger .error (str (e ))
83
138
start_response (
84
139
self .error_status ,
85
140
[('Content-Type' , 'text/css; charset=utf-8' )]
0 commit comments