It seems to me that the problem solved by javax.xml.parsers is
significantly different. For example, while it is OK for consecutive
calls to newInstane method in javax.xml.parsers.SAXParserFactory to
return distinct SAXParserFactory instances, in the logging world,
consecutive calls to newLoggerBuilder() in LoggerBuilderFactory should
return the *same* LoggerBuilder.
Unless I am missing something, this difference invalidates the approach
adopted by javax.xml.parsers in the case of logging.
Do you still think that the javax.xml.parsers is applicable? If not,
any better ideas?
Going directly from a static LoggerFactory to a Logger eliminates the
possibility of doing any feature sniffing on the factory. For
example, if we define LoggerFactory with some essential set of logger
accessor methods, there is not a mechanism for an implementation to
offer any additional logger accessors.
The javax.xml.parsers package might be a good pattern. They have a
three stage approach: DocumentBuilderFactory to get a DocumentBuilder
that can get a Document. If that naming pattern was carried over,
you'd have something like:
class LoggerBuilderFactory {
static LoggerBuilder newLoggerBuilder();
}
interface LoggerBuilder {
Logger getLogger(String name);
}
interface Logger {
void debug(String msg);
}
Using Hierarchy instead of Builder and getHierarchy instead of
newLoggerBuilder might make it more familiar to the user community.
For example, an implementation implemented on top an OSGi
implementation might define their LoggerBuilder like:
interface OSGiLoggerBuilder {
Logger getLogger(ServiceReference ref);
}
class OSGiLoggerBuilderImpl implements LoggerBuilder,
OSGiLoggerBuilder {
}
That way if code that wanted to use the configured SLF4J
implementation, but use OSGi specific features if they were available
could do something like:
Logger getLogger(ServiceReference service) {
LoggerBuilder loggerBuilder =
LoggerBuilderFactory.newLoggerBuilder();
if (loggerBuilder instanceof OSGiLoggerBuilder) {
return ((OSGiLoggerBuilder) loggerBuilder).getLogger(service);
}
return loggerBuilder.getLogger(service.toString());
}
_______________________________________________
dev mailing list
[email protected]
http://slf4j.org/mailman/listinfo/dev
--
Ceki Gülcü
The complete log4j manual: http://www.qos.ch/log4j/
_______________________________________________
dev mailing list
[email protected]
http://slf4j.org/mailman/listinfo/dev