Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dotlesscss does not show errors

Tags:

dotless

There's something wrong with my css because no styles are being added to my website after compilation.

How do I get dotlesscss to show errors? Regular .less shows you a nice message that's very handy.

like image 871
Johan Alkstål Avatar asked Jan 19 '23 10:01

Johan Alkstål


2 Answers

You can do this very easily with web.config. In your dotless configuration section, add the following: logger="dotless.Core.Loggers.AspResponseLogger". This will make dotless output the errors instead of blank css.

I've included the following as an example. ("..." represents existing stuff in your web.config). In my example below cache is set to false. This is useful for debugging purposes. It should probably be set to true under normal circumstances.

<configuration>    
     <configSections>
           ...
          <section name="dotless" type="dotless.Core.configuration.DotlessConfigurationSectionHandler,dotless.Core" />
      </configSections>

      <dotless minifyCss="false" cache="false" 
            logger="dotless.Core.Loggers.AspResponseLogger" />
       ...    
</configuration>    
like image 163
tony722 Avatar answered Mar 24 '23 01:03

tony722


I just faced this today in my RequestReduce project. I was getting blank less -> css transforms because there were parse errors that appeared to be going into the ether. Thanks to this related answer How can I output errors when using .less programmatically? I was able to work out a solution where I could write the errors to the response stream. You have to create a Logger derriving from dotless.Core.Loggers.ILogger:

public class LessLogger : ILogger
{
    public void Log(LogLevel level, string message)
    {
    }

    public void Info(string message)
    {
    }

    public void Debug(string message)
    {
    }

    public void Warn(string message)
    {
    }

    public void Error(string message)
    {
        Response.Write(message);
    }

    public HttpResponseBase Response { get; set; }
}

You pass this into the Configuration sent to the EngineFactory:

            var engine = new EngineFactory(new DotlessConfiguration
                                               {
                                                   CacheEnabled = false,
                                                   Logger = typeof (LessLogger)
                                               }
                ).GetEngine();

For unit testing purposes I wanted to pass in my HttpResponseBase that would write the error. This is where I felt things getting ugly with some nasty casting to get a reference to my logger:

            ((LessLogger)((LessEngine)((ParameterDecorator)engine).Underlying).Logger).Response = response;

I hope this helps you out.

like image 20
Matt Wrock Avatar answered Mar 24 '23 01:03

Matt Wrock