22
22
import java .util .Collections ;
23
23
import java .util .List ;
24
24
import org .apache .commons .io .FileUtils ;
25
- import org .apache . commons . logging .Log ;
26
- import org .apache . commons . logging .LogFactory ;
25
+ import org .lesscss . logging .LessLogger ;
26
+ import org .lesscss . logging .LessLoggerFactory ;
27
27
import org .mozilla .javascript .Context ;
28
28
import org .mozilla .javascript .Function ;
29
29
import org .mozilla .javascript .JavaScriptException ;
59
59
public class LessCompiler {
60
60
61
61
private static final String COMPILE_STRING = "function doIt(input, compress) { var result; var parser = new less.Parser(); parser.parse(input, function(e, tree) { if (e instanceof Object) { throw e; } ; result = tree.toCSS({compress: compress}); }); return result; }" ;
62
-
63
- private static final Log log = LogFactory . getLog (LessCompiler .class );
64
-
62
+
63
+ private static final LessLogger logger = LessLoggerFactory . getLogger (LessCompiler .class );
64
+
65
65
private URL envJs = LessCompiler .class .getClassLoader ().getResource ("META-INF/env.rhino.js" );
66
66
private URL lessJs = LessCompiler .class .getClassLoader ().getResource ("META-INF/less.js" );
67
67
private List <URL > customJs = Collections .emptyList ();
@@ -221,6 +221,7 @@ public synchronized void init() {
221
221
global .init (cx );
222
222
223
223
scope = cx .initStandardObjects (global );
224
+ scope .put ("logger" , scope , Context .toObject (logger , scope ));
224
225
225
226
List <URL > jsUrls = new ArrayList <URL >(2 + customJs .size ());
226
227
jsUrls .add (envJs );
@@ -239,14 +240,14 @@ public synchronized void init() {
239
240
}
240
241
catch (Exception e ) {
241
242
String message = "Failed to initialize LESS compiler." ;
242
- log .error (message , e );
243
+ logger .error (message , e );
243
244
throw new IllegalStateException (message , e );
244
245
}finally {
245
246
Context .exit ();
246
247
}
247
248
248
- if (log .isDebugEnabled ()) {
249
- log .debug ("Finished initialization of LESS compiler in " + (System .currentTimeMillis () - start ) + " ms." );
249
+ if (logger .isDebugEnabled ()) {
250
+ logger .debug ("Finished initialization of LESS compiler in " + (System .currentTimeMillis () - start ) + " ms." );
250
251
}
251
252
}
252
253
@@ -269,8 +270,8 @@ public String compile(String input) throws LessException {
269
270
Context cx = Context .enter ();
270
271
Object result = doIt .call (cx , scope , null , new Object []{input , compress });
271
272
272
- if (log .isDebugEnabled ()) {
273
- log .debug ("Finished compilation of LESS source in " + (System .currentTimeMillis () - start ) + " ms." );
273
+ if (logger .isDebugEnabled ()) {
274
+ logger .debug ("Finished compilation of LESS source in " + (System .currentTimeMillis () - start ) + " ms." );
274
275
}
275
276
276
277
return result .toString ();
0 commit comments