[slf4j-dev] Consolidating the LoggerFactory / A better plugin mechanism
Eric Crahen
eric.crahen.lists at gmail.com
Thu Feb 15 22:44:05 CET 2007
The Service API is in all sun JVMs since 1.3 under sun.misc.Service.
The docs can be found under the previous links I've sent.
On 2/15/07, Boris Unckel <boris.unckel.mlg at gmx.net> wrote:
>
> Hi,
>
> Eric Crahen wrote:
> > ....
> > I think that we can resolve the undesirable issues while still
> > retaining the behavior we have today. Here is my proposal:
> >
> > Create a single LoggerFactory and placed it into slf4j-api, and
> > deleted the LoggerFactory classes everywhere else they exist
> > (slf4j-simple, logback, etc). This new LoggerFactory leverages Sun's
> > ServiceProvider API which exists in all JDK's since 1.4 (maybe 1.3).
> > It looks like this:
>
> do you have a link to the service provider API? I searched the SUN site
> but did not find anything but the usage of the Service Provider but
> http://java.sun.com/j2se/1.4.2/docs/guide/jar/jar.html#Service%20Provider
>
> I am wondering this nice feature is just accesible through sun. packages.
>
> Regards
> Boris
>
>
> public class SampleServiceLoader {
>
> public static final String SERVICE_ID =
> "META-INF/services/org.slf4j.ILoggerFactory";
>
> /**
> *
> */
> public SampleServiceLoader() {
> super();
> }
>
> public Object obtainFactory() {
> ILoggerFactory ret = null;
> ClassLoader cl = Thread.currentThread().getContextClassLoader();
> InputStream is = cl.getResourceAsStream(SERVICE_ID);
> String factoryname = null;
> if(is != null) {
> BufferedReader bufferedReader = null;
> String errmsg = "Error obtaining service provider with
> id["+SERVICE_ID+"]";
> try {
> bufferedReader = new BufferedReader(new
> InputStreamReader(is));
> factoryname = bufferedReader.readLine();
> Class factoryClass = cl.loadClass(factoryname);
> ret = factoryClass.newInstance();
> } catch (IOException e) {
> throw new RuntimeException(errmsg,e);
> } catch (ClassNotFoundException e) {
> throw new RuntimeException(errmsg,e);
> } catch (InstantiationException e) {
> throw new RuntimeException(errmsg,e);
> } catch (IllegalAccessException e) {
> throw new RuntimeException(errmsg,e);
> } finally {
> try {
> bufferedReader.close();
> } catch (IOException e) {
> // NOP
> }
> }
> } else {
> throw new RuntimeException("Service Provider["+SERVICE_ID+"]
> not found.");
> }
> return ret;
> }
>
> }
>
> _______________________________________________
> dev mailing list
> dev at slf4j.org
> http://www.slf4j.org/mailman/listinfo/dev
>
--
- Eric
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://qos.ch/pipermail/slf4j-dev/attachments/20070215/bff08d49/attachment.htm>
More information about the slf4j-dev
mailing list