[JIRA] (MDA-285) Rework logging configuration in SimpleCommandLine
Ian Young (Jira)
jira at shibboleth.atlassian.net
Mon Apr 3 16:37:06 UTC 2023
Ian Young ( https://shibboleth.atlassian.net/secure/ViewProfile.jspa?accountId=557058%3Ae127cb03-43ed-473d-b6ba-592949cb4be8 ) *created* an issue
Metadata Aggregator ( https://shibboleth.atlassian.net/browse/MDA?atlOrigin=eyJpIjoiNWMzNzRjYTZiYzkyNGI3NmE2NDI1NzQyZDBmMTk1Y2UiLCJwIjoiaiJ9 ) / Improvement ( https://shibboleth.atlassian.net/browse/MDA-285?atlOrigin=eyJpIjoiNWMzNzRjYTZiYzkyNGI3NmE2NDI1NzQyZDBmMTk1Y2UiLCJwIjoiaiJ9 ) MDA-285 ( https://shibboleth.atlassian.net/browse/MDA-285?atlOrigin=eyJpIjoiNWMzNzRjYTZiYzkyNGI3NmE2NDI1NzQyZDBmMTk1Y2UiLCJwIjoiaiJ9 ) Rework logging configuration in SimpleCommandLine ( https://shibboleth.atlassian.net/browse/MDA-285?atlOrigin=eyJpIjoiNWMzNzRjYTZiYzkyNGI3NmE2NDI1NzQyZDBmMTk1Y2UiLCJwIjoiaiJ9 )
Issue Type: Improvement Affects Versions: 0.9.2 Assignee: Ian Young ( https://shibboleth.atlassian.net/secure/ViewProfile.jspa?accountId=557058%3Ae127cb03-43ed-473d-b6ba-592949cb4be8 ) Components: Command Line Created: 03/Apr/23 12:37 PM Priority: Trivial Reporter: Ian Young ( https://shibboleth.atlassian.net/secure/ViewProfile.jspa?accountId=557058%3Ae127cb03-43ed-473d-b6ba-592949cb4be8 )
The way logging configuration works in the simple CLI is that the command-line options determinate a suitable value for the logback.configurationFile system property. It uses System.setProperty to put this into effect before setting up any loggers.
This approach is very brittle: if there is even one LoggerFactory.getLogger call before the property is set, the logging context will be initialised with the default settings and the intended logging configuration will not be applied. This might happen if you try to create the application logger statically, for example. Fortunately all of this definitely happens before the Spring context containing the MDA configuration is refreshed, so static loggers within that context are fine.
It would make sense to rework this to not depend on the System.setProperty approach, but an explicit configuration:
final LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
context.reset();
final JoranConfigurator configurator = new JoranConfigurator();
configurator.setContext(context);
final String resName = "/net/shibboleth/metadata/cli/whatever.xml";
final InputStream is = SimpleCommandLine.class.getResourceAsStream("/" + resName);
configurator.doConfigure(is);
This reconfigures the logging context but previously located loggers are still valid. So, this configuration approach is not sensitive to whether or not loggers have already been located.
For this to work, it’s also necessary to make logback-core and logback-classic compile-time dependencies of the CLI package.
( https://shibboleth.atlassian.net/browse/MDA-285#add-comment?atlOrigin=eyJpIjoiNWMzNzRjYTZiYzkyNGI3NmE2NDI1NzQyZDBmMTk1Y2UiLCJwIjoiaiJ9 ) Add Comment ( https://shibboleth.atlassian.net/browse/MDA-285#add-comment?atlOrigin=eyJpIjoiNWMzNzRjYTZiYzkyNGI3NmE2NDI1NzQyZDBmMTk1Y2UiLCJwIjoiaiJ9 )
Get Jira notifications on your phone! Download the Jira Cloud app for Android ( https://play.google.com/store/apps/details?id=com.atlassian.android.jira.core&referrer=utm_source%3DNotificationLink%26utm_medium%3DEmail ) or iOS ( https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=EmailNotificationLink&mt=8 ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100221- sha1:d541bce )
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://shibboleth.net/pipermail/commits/attachments/20230403/3d3a1166/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: jira-generated-image-static-comment-icon-c13326e8-d148-45d4-9703-b844d92cd4a8
Type: image/png
Size: 1084 bytes
Desc: not available
URL: <http://shibboleth.net/pipermail/commits/attachments/20230403/3d3a1166/attachment-0004.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: jira-generated-image-avatar-00091361-2a4c-4c58-b027-cec9ba55d952
Type: image/png
Size: 448 bytes
Desc: not available
URL: <http://shibboleth.net/pipermail/commits/attachments/20230403/3d3a1166/attachment-0005.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: jira-generated-image-static-trivial-05eb6fe1-2450-463b-9dc4-458b5aa9d200
Type: image/png
Size: 446 bytes
Desc: not available
URL: <http://shibboleth.net/pipermail/commits/attachments/20230403/3d3a1166/attachment-0006.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: jira-generated-image-static-footer-desktop-logo-75d80468-3a0a-4a50-896c-a9ccd5e4bdab
Type: image/png
Size: 10805 bytes
Desc: not available
URL: <http://shibboleth.net/pipermail/commits/attachments/20230403/3d3a1166/attachment-0007.png>
More information about the commits
mailing list