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 6 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 |
✅ All tests passed ✅🏷️ Commit: 3f3732e Learn more about TestLens at testlens.app. |
Summary
Stops scaffolding
grails-app/conf/logback-spring.xmlinto newly created Grailsapplications, in both app-generation paths:
grails-profiles/base/skeleton/grails-app/conf/logback-spring.xml.Logbackfeature no longer emits alogback-spring.xmltemplate; it keeps adding thegrails-loggingdependency. Removes the now-unused
logback.rocker.rawtemplate and updatesLogbackSpecto assert the file is not generated.Logging keeps working with zero configuration. The base profile declares
spring-boot-starter-logging(grails-profiles/base/profile.yml) and Forge addsorg.apache.grails:grails-logging(which pulls in the Boot logging starter), soLogback and Spring Boot's own default Logback configuration are on the
classpath and apply automatically when the app supplies no config of its own.
The generated file is therefore not required — and, as shown below, it actively
works against Spring Boot 4.x conventions.
Why this 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 loads its bundled Logback setup from the
spring-bootjar:org/springframework/boot/logging/logback/base.xml— top-level wiring…/defaults.xml— default levels and conversion rules…/console-appender.xml— the standard console pattern (with ANSI color whenthe console supports it)
…/file-appender.xml— activated only whenlogging.file.name/logging.file.pathis setThis is the explicit, documented "it just works with zero config" contract of
Spring Boot. Shipping a hand-written
logback-spring.xmlin the generated appopts every new app out of 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. The file we generate degrades the out-of-the-box defaults
The generated file does three things that surprise users:
ERROR. Spring Boot's default isINFO. Withthis file, a brand-new app silently swallows all
WARNandINFOoutput —including framework startup warnings and the logging developers expect while
building. This is one of the most common "why isn't my app logging anything?"
papercuts.
coloring Boot enables automatically on capable terminals.
loggers (
org.hibernate.SQL,org.springframework.security, …) that are alldisabled. A freshly generated project starts life with a config file that is
~70% dead, commented code.
None of this is configuration a new project needs. It is configuration a new
project has to understand and undo.
3. 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 it genuinely needsto customize. Removing this file brings Grails app generation in line with that
convention and with what Spring/Boot developers already expect.
4. Nothing depends on the file existing
For the skeleton, the only in-repo references to
grails-app/conf/logback-spring.xmlare documentation that describes it as aplace you can configure logging — not a file that must be present.
profile.ymlcopies the skeleton directory wholesale; it does not enumerate individual files.
For Forge, the only references were the
Logbackfeature and its spec, bothupdated here. The
grails-loggingdependency (and its test) is unchanged, sothe logging library is still added to generated apps.
Best practices: configuring logging in Grails 8 / Spring Boot 4.x
With this change, the recommended workflow for a new app is:
1. Do nothing — logging already works. Boot's defaults give you an INFO root
logger and a colorized console pattern with no files to manage.
2. Tune levels and patterns from
application.yml(no XML required):3. Add a config file only when properties aren't enough — custom appenders,
JSON/structured output, per-profile routing, etc. When you do, create
grails-app/conf/logback-spring.xml(the-springvariant, not plainlogback.xml), because it is processed by Boot and unlocks<springProfile>and
<springProperty>. A minimal, additive file that builds on the defaultsrather than replacing them:
4. Keep environment-specific logging in
<springProfile>blocks so a singlefile serves dev / test / prod, driven by the active Spring profile.
The guiding principle is the Spring Boot one: start from zero config, add only
the delta you need, and build on Boot's defaults instead of overriding them.
Changes
grails-profiles/base/skeleton/grails-app/conf/logback-spring.xml.LogbackForge feature: stop adding thelogback-spring.xmltemplate; keepthe
grails-loggingdependency.logback.rocker.rawForge template.LogbackSpec: assertlogback-spring.xmlis not generated; thegrails-loggingdependency assertion is unchanged.Test plan
grails-forge-coreLogbackSpecpasses: every application type still gets thegrails-loggingdependency and no longer getsgrails-app/conf/logback-spring.xml.starts and logs via Spring Boot's default Logback configuration (INFO root,
colorized console).
logging.level.*toapplication.ymladjusts levels as expected withno XML present.
Update: opt-in
Logback ConfigurationForge featureRemoving the file from the default is no longer a one-way door — this PR now also
adds a way to get it back when you actually want it.
Grails Forge gains a new, visible logging feature —
logback-config("Logback Configuration") — that generatesgrails-app/conf/logback-spring.xmlon demand. Previously, searching the Forgefeature list for "log" returned No matching features; the feature is now
discoverable and selectable.
Behavior
grails-logging(Logback via Spring Boot's logging starter) and no configfile — Spring Boot's zero-config defaults apply, exactly as the rest of this PR
describes.
starter
logback-spring.xmlfor projects that prefer to manage Logback in XML.LoggingFeature(OneOfFeature), so selecting itsupersedes the default
Logbackfeature and re-declaresgrails-loggingto keepLogback on the classpath. The dependency is therefore identical either way; the
only user-visible difference is the generated file.
Implementation
LogbackConfig— visibleOneOfLoggingFeaturethat adds thegrails-loggingdependency and renders the
logback-spring.xmltemplate.logback.rocker.rawtemplate (removed earlier in this PR) used torender the file.
LogbackSpec— covers feature visibility, file generation across all applicationtypes, and that
grails-loggingis declared exactly once.Note on generated content
The opt-in feature currently reproduces the original template verbatim (root level
ERROR, hardcodedwithJansi, and a HibernateBasicBinderlogger name thatchanged in Hibernate 6+). It can instead emit the additive config recommended
above (keep Boot's
INFOroot, drop the Jansi override, build ondefaults.xml)if reviewers prefer.