Skip to content

Commit

Permalink
Merge pull request #497 from dmlloyd/jpms-sp
Browse files Browse the repository at this point in the history
Add smart service provider method
  • Loading branch information
jamezp authored Nov 26, 2024
2 parents 8eead3b + c54cc68 commit ec2c0ac
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
exports org.jboss.logmanager.formatters;
exports org.jboss.logmanager.handlers;

provides java.util.logging.LogManager with LogManager;
provides java.util.logging.LogManager with LogManager.Provider;
provides System.LoggerFinder with JBossLoggerFinder;
provides ConfiguratorFactory with DefaultConfiguratorFactory;

Expand Down
21 changes: 21 additions & 0 deletions src/main/java/org/jboss/logmanager/LogManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -222,4 +222,25 @@ public boolean addLogger(java.util.logging.Logger logger) {
public Logger getLogger(String name) {
return LogContext.getLogContext().getLogger(name);
}

public static final class Provider {
/**
* The service provider method.
* This method is used when the log manager service is loaded from a modular application.
*
* @return the log manager instance (not {@code null})
* @throws ClassCastException if the log manager is not initialized to this class
*/
public static LogManager provider() {
Thread ct = Thread.currentThread();
ClassLoader old = ct.getContextClassLoader();
ct.setContextClassLoader(Provider.class.getClassLoader());
try {
System.setProperty("java.util.logging.manager", LogManager.class.getName());
return (LogManager) getLogManager();
} finally {
ct.setContextClassLoader(old);
}
}
}
}

0 comments on commit ec2c0ac

Please sign in to comment.