Quillion
Quillion

Reputation: 6476

Set logging level for Spring project

I am running spring-webmvc project using gradle, using command
./gradlew clean jettyRun

However whenever I run it I get spammed with debug messages such as (this is just an example)

16:21:13.507 [1407721353@qtp-1264231563-3] DEBUG org.springframework.web.servlet.view.BeanNameViewResolver - No matching bean found for view name 'page'
16:21:13.511 [1407721353@qtp-1264231563-3] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Returning cached instance of singleton bean 'freemarkerConfig'
16:21:13.514 [1407721353@qtp-1264231563-3] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Invoking afterPropertiesSet() on bean with name 'page'
16:21:13.515 [1407721353@qtp-1264231563-3] DEBUG freemarker.cache - TemplateLoader.findTemplateSource("page_en_US.ftl"): Not found
16:21:13.516 [1407721353@qtp-1264231563-3] DEBUG freemarker.cache - TemplateLoader.findTemplateSource("page_en.ftl"): Not found
16:21:13.517 [1407721353@qtp-1264231563-3] DEBUG freemarker.cache - TemplateLoader.findTemplateSource("page.ftl"): Not found
16:21:13.517 [1407721353@qtp-1264231563-3] DEBUG freemarker.cache - "page.ftl"("en_US", Cp1252, parsed) no source found.

Anyone know how I can make it not spam me with all these messages? I would like log level to be WARN instead of DEBUG.
I have tried shoving application.properties file with warn level defined everywhere as stated here it did not help.

EDIT

MY build.gradle file is

apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'jetty'
apply plugin: 'war'
apply plugin: 'org.springframework.boot'

repositories {
    mavenCentral()
}

dependencies {
    compile("org.springframework.boot:spring-boot-starter-web:1.5.1.RELEASE") {
        exclude module: "spring-boot-starter-tomcat"
    }
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-jetty', version: '1.5.1.RELEASE'
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-actuator', version: '1.5.1.RELEASE'
    compile group: 'org.springframework', name: 'spring-webmvc', version: '4.3.6.RELEASE'
    compile group: 'org.springframework', name: 'spring-context-support', version: '4.3.6.RELEASE'
    compile group: 'org.springframework', name: 'spring-orm', version: '4.3.6.RELEASE'
    compile group: 'javax.servlet', name: 'javax.servlet-api', version: '3.1.0'
    compile group: 'org.freemarker', name: 'freemarker', version: '2.3.23'
    compile group: 'mysql', name: 'mysql-connector-java', version: '6.0.5'
    compile group: 'org.hibernate', name: 'hibernate-core', version: '5.1.4.Final'
    compile group: 'commons-validator', name: 'commons-validator', version: '1.5.1'
    compile group: 'junit', name: 'junit', version: '4.12'
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: '1.5.1.RELEASE'
}

task wrapper(type: Wrapper) {
    gradleVersion = '2.2'
}

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:1.5.1.RELEASE")
    }
}

Note that although I have included bootstrap in there, I am not using it to run from command line,

Not to mention bootstrap log messages look like this

2017-02-21 16:53:11.256  INFO 6004 --- [           main] o.s.c.support.DefaultLifecycleProcessor  : Starting beans in phase 0
2017-02-21 16:53:11.379  INFO 6004 --- [           main] application                              : Initializing Spring FrameworkServlet 'dispatcherServlet'
2017-02-21 16:53:11.379  INFO 6004 --- [           main] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization started
2017-02-21 16:53:11.395  INFO 6004 --- [           main] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization completed in 16 ms
2017-02-21 16:53:11.415  INFO 6004 --- [           main] o.e.jetty.server.AbstractConnector       : Started ServerConnector@418f890f{HTTP/1.1,[http/1.1]}{0.0.0.0:8888}

Upvotes: 1

Views: 2842

Answers (1)

Monzurul Shimul
Monzurul Shimul

Reputation: 8386

Add logback.xml in your resources directory. make sure you have logback jar in your classpath.

logback.xml

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
    <!-- Log message format -->
    <encoder>
      <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
      </pattern>
    </encoder>
  </appender>

  <!-- Setting the root level of logging to INFO -->
  <root level="info">
    <appender-ref ref="STDOUT" />
  </root>
</configuration>

Upvotes: 2

Related Questions