[JIRA] (XSTJ-92) Rework logging configuration to be less brittle

Ian Young (Jira) jira at shibboleth.atlassian.net
Mon Apr 3 16:40:59 UTC 2023


Ian Young ( https://shibboleth.atlassian.net/secure/ViewProfile.jspa?accountId=557058%3Ae127cb03-43ed-473d-b6ba-592949cb4be8 ) *created* an issue

XML Security Tool - Java ( https://shibboleth.atlassian.net/browse/XSTJ?atlOrigin=eyJpIjoiNmRmZTIwNjY1Y2Y5NGI3MWJhODljY2M5MTdjNDc4MzIiLCJwIjoiaiJ9 ) / Improvement ( https://shibboleth.atlassian.net/browse/XSTJ-92?atlOrigin=eyJpIjoiNmRmZTIwNjY1Y2Y5NGI3MWJhODljY2M5MTdjNDc4MzIiLCJwIjoiaiJ9 ) XSTJ-92 ( https://shibboleth.atlassian.net/browse/XSTJ-92?atlOrigin=eyJpIjoiNmRmZTIwNjY1Y2Y5NGI3MWJhODljY2M5MTdjNDc4MzIiLCJwIjoiaiJ9 ) Rework logging configuration to be less brittle ( https://shibboleth.atlassian.net/browse/XSTJ-92?atlOrigin=eyJpIjoiNmRmZTIwNjY1Y2Y5NGI3MWJhODljY2M5MTdjNDc4MzIiLCJwIjoiaiJ9 )

Issue Type: Improvement Affects Versions: 3.0.0 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:40 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 is that the command-line options determine 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.

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.

To be clear: this is not currently causing an issue; it’s brittle, not broken.

( https://shibboleth.atlassian.net/browse/XSTJ-92#add-comment?atlOrigin=eyJpIjoiNmRmZTIwNjY1Y2Y5NGI3MWJhODljY2M5MTdjNDc4MzIiLCJwIjoiaiJ9 ) Add Comment ( https://shibboleth.atlassian.net/browse/XSTJ-92#add-comment?atlOrigin=eyJpIjoiNmRmZTIwNjY1Y2Y5NGI3MWJhODljY2M5MTdjNDc4MzIiLCJwIjoiaiJ9 )

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/1afc958d/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: jira-generated-image-static-comment-icon-150b1be8-7510-445c-a65a-d796f2e0fa89
Type: image/png
Size: 1084 bytes
Desc: not available
URL: <http://shibboleth.net/pipermail/commits/attachments/20230403/1afc958d/attachment-0004.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: jira-generated-image-avatar-c53ebf38-f6ff-439f-844e-0a125cd81e31
Type: image/png
Size: 448 bytes
Desc: not available
URL: <http://shibboleth.net/pipermail/commits/attachments/20230403/1afc958d/attachment-0005.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: jira-generated-image-static-trivial-1268d555-315b-45b6-bde6-64d32b6d6fe7
Type: image/png
Size: 446 bytes
Desc: not available
URL: <http://shibboleth.net/pipermail/commits/attachments/20230403/1afc958d/attachment-0006.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: jira-generated-image-static-footer-desktop-logo-c654b3ba-9b6e-4171-8867-014ef6c5d463
Type: image/png
Size: 10805 bytes
Desc: not available
URL: <http://shibboleth.net/pipermail/commits/attachments/20230403/1afc958d/attachment-0007.png>


More information about the commits mailing list