Skip to content

Commit fd757cb

Browse files
author
Dave Syer
committed
Add logging.level to application.properties
E.g. logging.level.org.springframework: DEBUG logging.level.org.hibernate: WARN Fixed gh-788
1 parent cc61d92 commit fd757cb

File tree

21 files changed

+116
-55
lines changed

21 files changed

+116
-55
lines changed

spring-boot-cli/src/it/java/org/springframework/boot/cli/JarCommandIT.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,12 @@ public void noSources() throws Exception {
6262
@Test
6363
public void jarCreationWithGrabResolver() throws Exception {
6464
File jar = new File("target/test-app.jar");
65-
Invocation invocation = this.cli.invoke("jar", jar.getAbsolutePath(),
65+
Invocation invocation = this.cli.invoke("run", jar.getAbsolutePath(),
6666
"bad.groovy");
6767
invocation.await();
68+
assertThat(invocation.getErrorOutput(), equalTo(""));
69+
invocation = this.cli.invoke("jar", jar.getAbsolutePath(), "bad.groovy");
70+
invocation.await();
6871
assertEquals(invocation.getErrorOutput(), 0, invocation.getErrorOutput().length());
6972
assertTrue(jar.exists());
7073

spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ content into your application; rather pick only the properties that you need.
4343
# LOGGING
4444
logging.path=/var/logs
4545
logging.file=myapp.log
46-
logging.config=
46+
logging.config= # location of config file (default classpath:/logback.xml for logback)
47+
logging.level.*= # levels for loggers, e.g. "logging.level.org.springframework=DEBUG" (TRACE, DEBUG, INFO, WARN, ERROR, FATAL, OFF)
4748
4849
# IDENTITY ({sc-spring-boot}/context/ContextIdApplicationContextInitializer.{sc-ext}[ContextIdApplicationContextInitializer])
4950
spring.application.name=

spring-boot-docs/src/main/asciidoc/howto.adoc

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -833,10 +833,6 @@ Check out {sc-spring-boot-autoconfigure}/web/WebMvcAutoConfiguration.{sc-ext}[`W
833833
[[howto-logging]]
834834
== Logging
835835

836-
837-
838-
[[howto-configure-logback-for-loggin]]
839-
=== Configure Logback for logging
840836
Spring Boot has no mandatory logging dependence, except for the `commons-logging` API, of
841837
which there are many implementations to choose from. To use http://logback.qos.ch[Logback]
842838
you need to include it, and some bindings for `commons-logging` on the classpath. The
@@ -854,10 +850,32 @@ For example, using Maven:
854850
----
855851

856852
Spring Boot has a `LoggingSystem` abstraction that attempts to configure logging based on
857-
the content of the classpath. If Logback is available it is the first choice. So if you
858-
put a `logback.xml` in the root of your classpath it will be picked up from there. Spring
859-
Boot provides a default base configuration that you can include if you just want to set
860-
levels, e.g.
853+
the content of the classpath. If Logback is available it is the first choice.
854+
855+
If the only change you need to make to logging is to set the levels of various loggers
856+
then you can do that in `application.properties` using the "logging.level" prefix, e.g.
857+
858+
[source,properties,indent=0,subs="verbatim,quotes,attributes"]
859+
----
860+
logging.level.org.springframework.web: DEBUG
861+
logging.level.org.hibernate: ERROR
862+
----
863+
864+
You can also set the location of a file to log to (in addition to the console) using
865+
"logging.file".
866+
867+
To configure the more fine grained settings of a logging system you need to use the native configuration
868+
format supported by the `LoggingSystem` in question. By default Spring Boot picks up the native
869+
configuration from its default location for the system (e.g. `classpath:/logback.xml` for Logback), but
870+
you can set the location of the config file using the "logging.config" property.
871+
872+
873+
[[howto-configure-logback-for-loggin]]
874+
=== Configure Logback for logging
875+
If you put a `logback.xml` in the root of your classpath it will be
876+
picked up from there. Spring Boot provides a default base
877+
configuration that you can include if you just want to set levels,
878+
e.g.
861879

862880
[source,xml,indent=0,subs="verbatim,quotes,attributes"]
863881
----

spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,18 @@ using a `logging.file` property.
724724

725725
As with console output, `ERROR`, `WARN` and `INFO` level messages are logged by default.
726726

727+
[[boot-features-custom-log-levels]]
728+
=== Log Levels
729+
730+
All the supported logging systems can have the logger levels set in the Spring `Environment`
731+
(so for example in `application.properties`) using "logging.level.*=LEVEL" where "LEVEL" is one of
732+
TRACE, DEBUG, INFO, WARN, ERROR, FATAL, OFF. Example `application.properties`:
733+
734+
[source,properties,indent=0,subs="verbatim,quotes,attributes"]
735+
----
736+
logging.level.org.springframework.web: DEBUG
737+
logging.level.org.hibernate: ERROR
738+
----
727739

728740

729741
[[boot-features-custom-log-configuration]]

spring-boot-samples/spring-boot-sample-actuator/src/main/resources/application.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
logging.file: /tmp/logs/app.log
2+
logging.level.org.springframework.security: INFO
23
management.address: 127.0.0.1
34
endpoints.shutdown.enabled: true
45
server.tomcat.basedir: target/tomcat

spring-boot-samples/spring-boot-sample-actuator/src/main/resources/logback.xml

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
logging.file: /tmp/logs/app.log
2+
logging.level.org.springframework.integration.file: DEBUG
23
service.greeting: Hello
34
debug: true

spring-boot-samples/spring-boot-sample-integration/src/main/resources/logback.xml

Lines changed: 0 additions & 6 deletions
This file was deleted.

spring-boot-samples/spring-boot-sample-parent-context/src/main/resources/logback.xml

Lines changed: 0 additions & 6 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
# Allow templates to be reloaded at dev time
22
spring.groovy.template.cache: false
3+
logging.level.org.springframework.web: INFO

0 commit comments

Comments
 (0)