title: How to log from Spring MVC
body: <p>I am trying to log from a controller in Spring MVC but nothing appears. I am using SLF4J with logback. I managed to log from a main class, but after making it a web application it does not log.</p>
  
  <p>I thought it would work since SL4JF and Logback is in the classpath.</p>
  
  <pre><code>@Controller
  @RequestMapping(value = "/cars")
  public class CarController {
  
      private Logger logger = LoggerFactory.getLogger(CarController.class);
  
      @RequestMapping(method = RequestMethod.GET)
      @ResponseBody
      public Map&lt;String, String&gt; newCar() {
          logger.info("new car");
          // more code
          return map;
      }
  }
  </code></pre>
  
  <p>logback.xml</p>
  
  <pre><code>&lt;configuration scan="true"&gt;
      &lt;property name="LOG_DIR" value="/My/User/Desktop"/&gt;
  
      &lt;!--Loggers--&gt;
      &lt;logger name="my.company" level="DEBUG"/&gt;
  
      &lt;!--Root logger--&gt;
      &lt;root level="debug"&gt;
          &lt;appender-ref ref="STDOUT"/&gt;
          &lt;appender-ref ref="FILE_ROLLER"/&gt;
      &lt;/root&gt;
  
      &lt;!--Appenders--&gt;
      &lt;appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"&gt;
          &lt;encoder&gt;
              &lt;pattern&gt;%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n&lt;/pattern&gt;
          &lt;/encoder&gt;
      &lt;/appender&gt;
  
      &lt;appender name="FILE_ROLLER" class="ch.qos.logback.core.rolling.RollingFileAppender"&gt;
          &lt;file&gt;${LOG_DIR}/mylog.log&lt;/file&gt;
          &lt;rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"&gt;
              &lt;fileNamePattern&gt;mylog.%d{yyyy-mm-dd}.log&lt;/fileNamePattern&gt;
              &lt;maxHistory&gt;30&lt;/maxHistory&gt;
          &lt;/rollingPolicy&gt;
  
          &lt;encoder&gt;
              &lt;pattern&gt;%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n&lt;/pattern&gt;
          &lt;/encoder&gt;
      &lt;/appender&gt;
  &lt;/configuration&gt;
  </code></pre>