Skip to content
This repository was archived by the owner on Feb 23, 2023. It is now read-only.

Have better out of the box support for logback - #895

Closed
phejl wants to merge 9 commits into
spring-attic:mainfrom
phejl:better-logback-experience
Closed

phejl wants to merge 9 commits into
spring-attic:mainfrom
phejl:better-logback-experience

Conversation

@phejl

@phejl phejl commented Jul 6, 2021

Copy link
Copy Markdown

No description provided.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Jul 6, 2021
@sdeleuze

sdeleuze commented Jul 7, 2021

Copy link
Copy Markdown
Contributor

@phejl Hi, could you please provide more details about the new capabilities provided by this PR?

Based on Spring Boot documentation:

In addition, a legacy base.xml file is provided for compatibility with earlier versions of Spring Boot.

So I would tend to think base.xml is not required to be included, for defaults.xml I am not sure but I think it is now done programmatically.

@wilkinsona Could you please confirm that base.xml is not required for a typical Spring Boot 2.5 app? What about defaults.xml, based on the documentation is seems needed but maybe such configuration is now performed programmatically?

@phejl

phejl commented Jul 7, 2021 •

Copy link
Copy Markdown
Author

@phejl Hi, could you please provide more details about the new capabilities provided by this PR?

Based on Spring Boot documentation:

In addition, a legacy base.xml file is provided for compatibility with earlier versions of Spring Boot.

So I would tend to think base.xml is not required to be included, for defaults.xml I am not sure but I think it is now done programmatically.

@sdeleuze Aha, that might be my misuderstanding. As most of the online resources still uses incluson of defaults.xml (including my app). Hence profiler suggested it should be included. I'm wondering how many such cases might be out there - you update Spring Boot but do not bother changing logback.xml to the latest standard as it works as before without any needed change.

Typehints are suggested for common things one ususally customize (console appender, rolling files).

Adds support for simple conditions in form isDefined('VAR') and isNull('VAR') as I believe this might cover major portion of use cases of Janino which would otherwise fail in native image as it is creating bytecode at runtime and loading it as class.

@sdeleuze

sdeleuze commented Jul 7, 2021

Copy link
Copy Markdown
Contributor

Interesting, so does this means we can now support basic logback.xml files by skipping Janino for such use cases?

In the documentation update you mentioned:

Logback XML configuration via -Dlogging.config or --logging.config is supported but you need to enable XML support

I recently removed the conditional activation of the Logback substitution based on the XML flag since we were not supporting it, if we do we should maybe bring back RemoveXmlSupport.class here.

@phejl

phejl commented Jul 7, 2021

Copy link
Copy Markdown
Author

Interesting, so does this means we can now support basic logback.xml files by skipping Janino for such use cases?

I thought the problem with logback.xml on classpath was it was triggering some unwanted build time initializations. My use case I have tested to be working was like ./my-native-image --logging.config=/my/logback-config.xml (with enabled xml support) containing simple conditions.

In the documentation update you mentioned:

Logback XML configuration via -Dlogging.config or --logging.config is supported but you need to enable XML support

I recently removed the conditional activation of the Logback substitution based on the XML flag since we were not supporting it, if we do we should maybe bring back RemoveXmlSupport.class here.

Hm, in my case of log file argument this code is actually bypassed (org.springframework.boot.logging.logback.LogbackLoggingSystem:185) as long as XML is enabled.

@phejl
phejl force-pushed the better-logback-experience branch from 1acc194 to 148af72 Compare July 8, 2021 07:09
@phejl

phejl commented Jul 8, 2021

Copy link
Copy Markdown
Author

@sdeleuze I looked again at the problem with logback.xml bundled as resource (not something this PR intend to solve, but anyway). If I understand things correctly the problematic part is org.slf4j.impl.StaticLoggerBinder's static initializer calling SINGLETON.init();. I'm afraid we can't really push all this to build time. It would initialize custom things such as ch.qos.logback.core.spi.PropertyDefiners in build time when it might not be possible to really evaluate the value (might be deployment specific). On the other hand I assume we don't want to do everything at runtime. I guess the solution would be to postpone that init() method to be invoked lazily. I'm not sure how to do that without touching it's source code as it seems the @Substitution is not applied at the time class initializers are invoked at build time.

@wilkinsona

wilkinsona commented Jul 8, 2021 •

Copy link
Copy Markdown

@wilkinsona Could you please confirm that base.xml is not required for a typical Spring Boot 2.5 app? What about defaults.xml, based on the documentation is seems needed but maybe such configuration is now performed programmatically?

A Boot app that only uses properties to configure its logging won't use base.xml or defaults.xml. If someone is using XML to configure Logback then they may import defaults.xml but they do not have to do so. They may also choose to import console-appender.xml or file-appender.xml. No one should be using base.xml any more, particularly if they're on the leading edge and using Spring Native.

@phejl

phejl commented Jul 8, 2021

Copy link
Copy Markdown
Author

@wilkinsona Could you please confirm that base.xml is not required for a typical Spring Boot 2.5 app? What about defaults.xml, based on the documentation is seems needed but maybe such configuration is now performed programmatically?

A Boot app that only uses properties to configure its logging won't use base.xml or defaults.xml. If someone is using XML to configure Logback then they may import defaults.xml but they do not have to do so. They may also choose to import console-appender.xml or file-appender.xml. No one should be using base.xml any more, particularly if they're on the leading edge and using Spring Native.

@wilkinsona Thanks for your input! Should the patch be updated to allow access to defaults.xml, console-appender.xml and file-appender.xml (ommitting base.xml) as a result?

@wilkinsona

Copy link
Copy Markdown

I think that's a question of what scope the Spring Native team want their Logback support to have, so I'll defer to them.

@sdeleuze

Copy link
Copy Markdown
Contributor

@phejl I see in the updated documentation:

Logback XML configuration via -Dlogging.config or --logging.config is supported but you need to enable <<spring-aot-configuration, XML support>>.

What prevents us to support logback.xml provided in the classpath if it uses the simple constructs supported in the PR?

@sdeleuze sdeleuze added status: waiting-for-feedback We need additional information before we can continue and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Jul 19, 2021
@phejl

phejl commented Jul 19, 2021 •

Copy link
Copy Markdown
Author

@sdeleuze

What prevents us to support logback.xml provided in the classpath if it uses the simple constructs supported in the PR?

I think the problem with logback.xml in classpath is the static initializer of StaticLoggerBinder triggered in build time. More or less this #625. Or am I missing something?

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Jul 19, 2021
@sdeleuze

Copy link
Copy Markdown
Contributor

@phejl Sorry I missed you comment on #895 (comment) where you already explained that.

Please add a sample in order to allow me to merge this PR.

@phejl

phejl commented Jul 21, 2021

Copy link
Copy Markdown
Author

@sdeleuze

Please add a sample in order to allow me to merge this PR.

Sure I'll try. I just need some more spare time :)

@sdeleuze sdeleuze added this to the 0.11.0 milestone Jul 23, 2021
@sdeleuze sdeleuze added type: compatibility Native image compatibility issue and removed status: feedback-provided Feedback has been provided labels Jul 23, 2021
@phejl

phejl commented Jul 28, 2021

Copy link
Copy Markdown
Author

@sdeleuze

Please add a sample in order to allow me to merge this PR.

Sample added.

Comment thread samples/logger/pom.xml
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please share more context about why the janino dependency is needed?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To trigger (enable) conditional processing and prove that the log config with conditions (conditions in limited form of isDefined and isNull) works ok with native image. Note the log config contains such a condition.

@phejl

phejl commented Aug 16, 2021

Copy link
Copy Markdown
Author

@sdeleuze Please, is there anything more needed from my side?

@sdeleuze sdeleuze modified the milestones: 0.11.0-M1, 0.11.x Sep 24, 2021
@phejl
phejl force-pushed the better-logback-experience branch from 4efa4fa to 02d9384 Compare October 4, 2021 12:04
@phejl

phejl commented Oct 4, 2021

Copy link
Copy Markdown
Author

@sdeleuze I have rebased the branch to resolve merge conflicts.

Comment on lines +25 to +29
try {
return Class.forName("org.codehaus.janino.ScriptEvaluator", false, getClass().getClassLoader()) != null;
} catch (ClassNotFoundException | NoClassDefFoundError ex) {
return false;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be simplified to

return ClassUtils.isPresent("org.codehaus.janino.ScriptEvaluator", getClass().getClassLoader());

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ttddyy Thanks for the hint. Applied.

@phejl
phejl force-pushed the better-logback-experience branch from c090e9f to 6420d17 Compare October 6, 2021 08:33
@phejl
phejl force-pushed the better-logback-experience branch from 6420d17 to 9eca16e Compare October 23, 2021 17:08
@phejl

phejl commented Oct 23, 2021

Copy link
Copy Markdown
Author

@sdeleuze I have no idea why samples/data-mongo fails. It passes locally and the reported error does not seem to be related to the changes. Would you have any advice please?

@phejl
phejl force-pushed the better-logback-experience branch from 9eca16e to a8bec36 Compare October 29, 2021 15:13
@sdeleuze

Copy link
Copy Markdown
Contributor

@phejl It was probably a transient error related to #1191 now fixed on main so nothing worrying for this PR.

@sdeleuze

Copy link
Copy Markdown
Contributor

@phejl If it is ready I can try to merge it for 0.11.0-M2, any thoughts?

@sdeleuze sdeleuze modified the milestones: 0.11.0, 0.11.0-M2 Oct 29, 2021
@phejl

phejl commented Oct 29, 2021

Copy link
Copy Markdown
Author

@sdeleuze I agree. The only thing I was doing from time to time was rebasing to recent main. I was even running my app with the changes (and load tested it) and I havn't found any issue regarding logging.

@sdeleuze sdeleuze self-assigned this Nov 1, 2021
@sdeleuze sdeleuze closed this in 78e2ccb Nov 3, 2021
sdeleuze added a commit that referenced this pull request Nov 3, 2021
sdeleuze added a commit that referenced this pull request Nov 3, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

type: compatibility Native image compatibility issue

Development

Successfully merging this pull request may close these issues.

6 participants