Stop generating logback-spring.xml by default; add opt-in Logback Configuration Forge feature#15757
Stop generating logback-spring.xml by default; add opt-in Logback Configuration Forge feature#15757codeconsole wants to merge 13 commits into
Conversation
Stop scaffolding grails-app/conf/logback-spring.xml into newly created applications. The base profile already declares spring-boot-starter-logging, so Logback and Spring Boot's default configuration (base.xml -> defaults.xml + console-appender.xml) are on the classpath and apply automatically when no user config is present. A generated config file is therefore not required for logging to work, and the one we ship overrides Boot's sensible defaults out of the gate: * Root level is forced to ERROR, hiding WARN/INFO that Boot shows by default and that most apps want during development. * It pins a CONSOLE appender with withJansi=false, opting every new app out of ANSI color that Boot enables automatically on capable consoles. * Most of the file is commented-out boilerplate (file appender, sample loggers), which reads as clutter in a brand-new project. This matches Spring Boot 4.x conventions: apps log correctly with zero config, and users add grails-app/conf/logback-spring.xml only when they need to customize. Levels and patterns remain configurable from application.yml via logging.level.*, logging.pattern.* and logging.file.* without any XML.
52cc29c to
94067b6
Compare
The Logback feature now only adds the grails-logging dependency and no longer renders grails-app/conf/logback-spring.xml. grails-logging brings spring-boot-starter-logging, so Logback and Spring Boot's default configuration apply automatically when the generated app supplies no config, matching Spring Boot 4.x's zero-config logging convention. Removes the now-unused logback.rocker.raw template and updates LogbackSpec to assert the file is not generated. The grails-logging dependency assertion is unchanged.
sbglasius
left a comment
There was a problem hiding this comment.
This needs to be documented, both in the upgrade notes and under configuration, since this will come as a surprise to seasoned Grails developers (I would be one of them).
jdaugherty
left a comment
There was a problem hiding this comment.
I would be ok to stop generating, but we need to do the following:
- document this change in the upgrade guide
- add a forge feature to revert the behavior
|
Unless it can do There were so many tickets when Logback nuked the groovy config and I don't want us back in that situation. This PR is just for application generator and we want new users to have a excellent out of the box experience. |
|
A quick round with AI leads me to believe the environment/spring profile specific logging is only possible via |
Adds a visible `logback-config` logging feature that generates grails-app/conf/logback-spring.xml for projects that prefer to manage their Logback configuration in XML. Logback remains available in every generated app via Spring Boot's zero-config logging (the default Logback feature adds grails-logging); this feature only emits an editable starter config file. As a mutually-exclusive logging feature it supersedes the default when selected, so it re-declares grails-logging to keep Logback on the classpath. - LogbackConfig: visible OneOf LoggingFeature that adds the logback-spring.xml template and grails-logging dependency. - Restore the logback.rocker.raw template used to render the file. - LogbackSpec: cover feature visibility, file generation across all application types, and that grails-logging is declared exactly once.
…guration feature Addresses review feedback that the change must be documented in both the upgrade guide and the configuration reference. - upgrading80x.adoc: add section 27 explaining that new apps no longer generate grails-app/conf/logback-spring.xml, that logging works via Spring Boot's zero-config defaults, how to tune it from application.yml, how to add a logback-spring.xml for custom/environment-specific logging, and that existing apps are unaffected. - logging.adoc: document zero-config logging, application.yml tuning, when to add logback-spring.xml, and the Grails Forge Logback Configuration feature that generates a starter file.
|
@sbglasius Good call — this is now documented in both places:
Both in ed420b1. |
|
@jdaugherty Both points are addressed:
|
|
I would be onboard if the logback-spring.xml feature in forge was default and could be unselected to achieve the desired idea for this PR, since I think the majority of users of forge would want logback-spring.xml |
@jamesfredley per the description, What about "default and could be unselected" like you suggest for 8.0 and then consider defaulting to off in 9.0? |
…ack-spring-xml # Conflicts: # grails-doc/src/en/guide/upgrading/upgrading80x.adoc
…block Environment-specific log levels do not require logback-spring.xml: the Grails environments block in application.yml (and a profile-specific application-development.yml) drive per-environment levels with no XML, because Grails environments map to Spring profiles. Document this in both the upgrade guide and the logging configuration reference, and reframe logback-spring.xml as needed only for things properties cannot express (custom appenders, structured output, per-environment appender routing).
|
@codeconsole I understand why you want it off by default, but I don't think that is the majority use case for generated apps on forge, which in theory are greenfield. I'd love to be able to deselect it for your use case but have default long term, since having more detailed logs in dev is expected behavior and having less detailed logs in prod is also. |
|
@jamesfredley Completely agree env-specific logging is expected and we must not regress it. I tested it on Grails 8 (Spring Boot 4): generated an app, booted it in
Two takeaways:
Given that, I'd argue against generating a replacement file. The old generated
Does that address the concern? If you'd still prefer a generated app to demonstrate env logging, we could seed a commented |
…pt-in Forge feature Per review feedback on apache#15757, flip the default: newly generated applications (profile skeleton and Grails Forge) continue to include the starter grails-app/conf/logback-spring.xml, and the zero-config behavior this PR introduced becomes an opt-in, visible Forge feature (logback-zero-config) that omits the file and relies on Spring Boot's default Logback configuration. The docs now describe the generated file as optional, document tuning levels and per-environment logging from application.yml, and note that a future major release may flip the default to zero-config.
|
@jamesfredley Done — the default is flipped back per your feedback (298cd59). Newly generated applications (both the profile skeleton and Forge) include the starter
PR title/description updated to match. |
…INFO root level Strip the parts of the generated file that duplicated Spring Boot's own configuration, per review discussion on apache#15757: - Compose Spring Boot's defaults.xml and console-appender.xml instead of hand-copying the console appender (this also drops the explicit withJansi setting; Boot's appender does not use Jansi). - Raise the root level from ERROR to INFO, matching Spring Boot's default so new applications no longer suppress WARN/INFO output. - Keep the <springProfile name="development"> block for environment-specific logging, with the commented example logger now using the application's real default package (the skeleton previously contained a leftover hard-coded 'Test38' logger name). - Trim the commented file-appender example to the Boot include form.
|
Following up on your "at a max I would only be OK stripping parts of that file that are no longer needed and are explicitly duplicative of spring defaults" — done in d2422cd. The generated <?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>
<include resource="org/springframework/boot/logging/logback/console-appender.xml"/>
<root level="INFO">
<appender-ref ref="CONSOLE"/>
</root>
<springProfile name="development">
<logger name="StackTrace" level="ERROR"/>
<!-- <logger name="com.example.myapp" level="DEBUG"/>-->
<!-- <logger name="org.hibernate.SQL" level="DEBUG"/>-->
<!-- <logger name="org.hibernate.type.descriptor.sql.BasicBinder" level="TRACE"/>-->
<!-- <logger name="org.springframework.security" level="TRACE"/>-->
</springProfile>
<!-- logging to a file: set logging.file.name in application.yml and include Spring Boot's file appender -->
<!-- <include resource="org/springframework/boot/logging/logback/file-appender.xml"/>-->
<!-- <root level="INFO">-->
<!-- <appender-ref ref="FILE"/>-->
<!-- </root>-->
</configuration>(The commented example logger is rendered with the app's actual default package. This also fixes a leftover hard-coded |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## 8.0.x #15757 +/- ##
==================================================
+ Coverage 49.6709% 49.6848% +0.0138%
- Complexity 17017 17024 +7
==================================================
Files 2004 2004
Lines 93896 93896
Branches 16448 16448
==================================================
+ Hits 46639 46652 +13
+ Misses 40078 40067 -11
+ Partials 7179 7177 -2 🚀 New features to boost your workflow:
|
| ---- | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <configuration> | ||
| <include resource="org/springframework/boot/logging/logback/defaults.xml"/> |
There was a problem hiding this comment.
This example produces an application with no log output at all. Once a logback-spring.xml exists, it replaces Spring Boot's bundled configuration entirely, and defaults.xml only contributes conversion rules and a few logger levels — no appenders. With no console-appender.xml include and no <root> with an appender-ref, the root logger has no appenders, so everything (including the org.hibernate.SQL DEBUG the example enables) goes nowhere. Anyone who copies this snippet when re-adding the file will silence their application.
The example should match the generated starter's shape:
<configuration>
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>
<include resource="org/springframework/boot/logging/logback/console-appender.xml"/>
<root level="INFO">
<appender-ref ref="CONSOLE"/>
</root>
<springProfile name="development">
<logger name="org.hibernate.SQL" level="DEBUG"/>
</springProfile>
</configuration>There was a problem hiding this comment.
Good catch — you're right, with no appender the example silenced everything it claimed to enable. Fixed in 2b1902f: the example now matches the generated starter's shape (defaults.xml + console-appender.xml includes and a <root level="INFO"> with the CONSOLE appender-ref), and the surrounding text now states explicitly that a custom logback-spring.xml replaces Spring Boot's bundled configuration entirely and must declare its own appenders.
| com.example.myapp: DEBUG # your packages | ||
| org.hibernate.SQL: DEBUG # see the generated SQL | ||
| file: | ||
| name: logs/myapp.log # setting this activates Spring Boot's file appender |
There was a problem hiding this comment.
"setting this activates Spring Boot's file appender" is only true in the zero-config case. When a logback-spring.xml is present — which is the default for newly generated applications, per the paragraph above — the custom file replaces Boot's base.xml, so logging.file.name sets the LOG_FILE property but nothing consumes it: no file appender appears until the user uncomments the file-appender.xml include in the generated file. Since this section presents the yaml as generally applicable, the comment will mislead the majority of readers who still have the generated file.
Suggest scoping it, e.g. # activates Boot's file appender when no logback-spring.xml is present (otherwise uncomment the file-appender include in that file). The same line in the upgrade-guide section is fine as-is, because there it sits under "With no configuration file present…".
There was a problem hiding this comment.
Agreed — with the generated file present (the default), logging.file.name sets LOG_FILE but nothing consumes it. Scoped in 2b1902f using your suggested wording: the comment now reads "activates Boot's file appender only when no logback-spring.xml is present (otherwise uncomment the file-appender include in that file)". Left the upgrade-guide occurrence as-is since it sits under "With no configuration file present…".
|
|
||
| When properties are not enough — custom appenders, structured output, or per-environment appender routing — add a `grails-app/conf/logback-spring.xml` file. Use the `-spring` variant (not plain `logback.xml`), because it is processed by Spring Boot and unlocks `<springProfile>` and `<springProperty>`. The Grails environments `development`, `test` and `production` map to the corresponding Spring profiles, so `<springProfile name="development">` blocks configure environment-specific logging — one of the features lost when Logback removed Groovy configuration. | ||
|
|
||
| TIP: When generating a project with https://start.grails.org[Grails Forge], select the *Zero-config Logback Logging* feature to omit the generated `grails-app/conf/logback-spring.xml` and rely entirely on Spring Boot's defaults plus `application.yml` tuning as described above. |
There was a problem hiding this comment.
Neither doc spells out what selecting zero-config gives up relative to the generated file. The current text explains what still works (levels, patterns, per-environment levels via environments), but a reader choosing between the two modes can't see the boundary. Worth one sentence here listing what requires the XML file and is therefore lost until it's re-added:
<springProfile>-conditional appenders/routing (per-environment levels still work via yaml, but per-environment appenders don't)- the starter's development-profile
StackTracelogger setting - activating a file appender purely via
logging.file.nameworks in zero-config (Boot'sbase.xml), so that one actually only works in this mode — another reason to scope the comment on line 33.
Everything else in this section applies to both modes, which is exactly why an explicit supported/unsupported line would make the choice easy.
There was a problem hiding this comment.
Added in 2b1902f — a paragraph after the Forge TIP now draws the boundary explicitly: without the file you give up what only XML can express (<springProfile>-conditional appenders/routing — per-environment levels still work via the environments block — and the starter's development-profile StackTrace logger), while logging.file.name auto-activation of the file appender only works without the file, which is also why the yaml comment above is now scoped.
…ed-file behavior Address review feedback on apache#15757: - The upgrade-guide example logback-spring.xml declared no appenders, so copying it produced an application with no log output (a custom file replaces Spring Boot's bundled configuration entirely, and defaults.xml contributes no appenders). The example now composes Boot's defaults.xml and console-appender.xml with a root appender-ref, matching the generated starter's shape. - Scope the logging.file.name comment in the logging reference: it only activates Boot's file appender when no logback-spring.xml is present; otherwise the file-appender include in the generated file must be uncommented. - Spell out the boundary between the generated file and zero-config: what each mode gives up (springProfile-conditional appenders/routing and the StackTrace dev logger vs logging.file.name auto-activation).
…figuration feature With the generated file's content fixes landed separately in apache#15973 (simplified to compose Spring Boot's defaults with an INFO root level), flip this PR back to its original intent: newly generated applications ship no logback-spring.xml at all. - Profile skeleton: remove grails-app/conf/logback-spring.xml. - Forge: the default logback feature only adds the grails-logging dependency; Spring Boot's zero-config Logback defaults apply. A new visible logback-config feature (Logback Configuration) generates the simplified starter file on demand and supersedes the default feature. - Docs: the logging reference and upgrade guide describe zero-config logging as the default for new applications, application.yml level tuning (including per-environment via the environments block), when to add logback-spring.xml, and the boundaries between the two modes. - Tests: LogbackSpec asserts no file is generated by default and that logback-config emits the simplified configuration with grails-logging declared exactly once.
|
With the generated file's content fixes now merged separately via #15973, this PR is flipped back to its original scope (537614e): newly generated applications ship no Since the earlier discussion, the concerns raised then have been addressed in what's now the default-less setup:
PR title/description updated back to match. |
Document the remaining Spring Boot logging properties so application.yml covers the full non-XML surface: console/file output patterns, custom and predefined (web, sql) logger groups, per-appender thresholds, file-appender rotation via logging.logback.rollingpolicy.*, the debug/trace top-level shortcuts, and ANSI color control via spring.output.ansi.enabled. Notes which properties are consumed by Boot's appenders and therefore apply in both zero-config mode and a logback-spring.xml composing Boot's includes.
|
@jamesfredley before this goes further I want to take each concern you've raised head-on, with working configuration for every behavior you've said requires 1. "Environment/spring profile specific logging is only possible via
|
✅ All tests passed ✅🏷️ Commit: a62acb7 Learn more about TestLens at testlens.app. |
Summary
Stops scaffolding
grails-app/conf/logback-spring.xmlinto newly createdGrails applications, in both app-generation paths, and adds an opt-in
Logback Configuration Forge feature that generates the starter file on
demand.
grails-profiles/base/skeleton/grails-app/conf/logback-spring.xml.logbackfeature no longer emits alogback-spring.xmltemplate; it keeps adding thegrails-loggingdependency. A new visible
logback-configfeature (LogbackConfiguration) generates the starter file for projects that prefer to
manage logging in XML; selecting it supersedes the default feature.
Logging keeps working with zero configuration. The base profile declares
spring-boot-starter-loggingand Forge addsorg.apache.grails:grails-logging(which pulls in the Boot logging starter), so Logback and Spring Boot's own
default Logback configuration are on the classpath and apply automatically
when the app supplies no config of its own: an
INFOroot logger and acolorized console pattern.
Why the file should not be created automatically
1. Spring Boot already provides a complete default configuration
When the Boot logging starter is present and no user config is found,
Spring Boot applies its bundled Logback setup. This is the explicit,
documented "it just works with zero config" contract of Spring Boot.
Shipping a
logback-spring.xmlin the generated app opts every new app outof that contract on day one and replaces a well-maintained, version-matched
default with a static file the framework must keep in sync with Boot.
2. It matches the Spring Boot 4.x convention
The modern Spring Boot convention (and what
start.spring.ioproduces) is toship no logging config file at all. A generated Spring Boot 4.x app
relies on Boot's defaults and adds a
logback-spring.xmlonly when itgenuinely needs to customize. Removing this file brings Grails app generation
in line with that convention and with what Spring/Boot developers already
expect.
3. Environment-specific logging does not require the file
Grails environments map to Spring profiles, so per-environment log levels
work with zero XML from the
environmentsblock every app already has:logback-spring.xml(with<springProfile>) remains the answer forenv-specific appenders and routing, which properties cannot express — and
the Logback Configuration Forge feature generates a starter file for
exactly that case.
Documentation
conf/config/logging.adoc) — documents zero-configlogging as the default for new applications,
application.ymllevel andpattern tuning, per-environment levels, when to add
logback-spring.xml(and that it replaces Boot's bundled configuration entirely, so it must
declare its own appenders), and the boundaries between the two modes.
upgrading80x.adoc) — new section "LogbackConfiguration No Longer Generated by Default" covering the change, that
existing applications are unaffected, and how to re-add the file.
Tests
LogbackSpecasserts nologback-spring.xmlis generated by default forany application type, that
logback-configgenerates the simplified starter(Boot includes,
INFOroot, developmentspringProfile, no Jansi), andthat
grails-loggingis declared exactly once either way.Related: #15756