using logback in an API w/o impacting other applications

Hi all, In an API I had to write for a client to interface with an COTS application, I used log4j to bridge to the COTS application's log capability. To totally isolate the usage of log4j in the API I created a wrapper around a Logger with its own Hierarchy. I'm wondering if there is an analogous mechanism for accomplishing this in logback. public final class AgentLogger { public static Hierarchy heirarchy = new Hierarchy(new RootLogger(Level.TRACE)); private Logger wl = null; /** * Private constructor * * @param name */ private AgentLogger (String name) { wl = heirarchy.getLogger(name); wl.setAdditivity(false); } Any advice appreciated. Thanks! Best regards, Richard Sand | CEO 239 Kings Highway East | Haddonfield | New Jersey 08033 | USA Mobile: +1 267 984 3651| Office: +1 856 795 1722| Fax: +1 856 795 1733 <http://www.skyworthttg.com/>

Hi all, I'm working with a COTS application, writing some extensions for it. The application has a proprietary logging API. In the past, I wrote a custom logging class wrapping log4j to bridge to the COTS application's log capability. To totally isolate the usage of log4j in the API I created a wrapper around a Logger with its own Hierarchy. We're now exploring replacing log4j with logback in these extensions and I'm wondering if there is an analogous mechanism for accomplishing this in logback. Here is an example of what I'm doing with log4j. Note how I create a new Hierarchy and then create a logger from that hierarchy with additivity turned off. How would I do this with logback? public final class AgentLogger { public static Hierarchy heirarchy = new Hierarchy(new RootLogger(Level.TRACE)); private Logger wl = null; /** * Private constructor * * @param name */ private AgentLogger (String name) { wl = heirarchy.getLogger(name); wl.setAdditivity(false); } Any advice appreciated. Thanks! Best regards, Richard Sand | CEO 239 Kings Highway East | Haddonfield | New Jersey 08033 | USA Mobile: +1 267 984 3651| Office: +1 856 795 1722| Fax: +1 856 795 1733 <http://www.skyworthttg.com/>

Hi all, I'm working with a COTS application, writing some extensions for it. The application has a proprietary logging API. In the past, I wrote a custom logging class wrapping log4j to bridge to the COTS application's log capability. To totally isolate the usage of log4j in the API I created a wrapper around a Logger with its own Hierarchy. We're now exploring replacing log4j with logback in these extensions and I'm wondering if there is an analogous mechanism for accomplishing this in logback. Here is an example of what I'm doing with log4j. Note how I create a new Hierarchy and then create a logger from that hierarchy with additivity turned off. How would I do this with logback? public final class AgentLogger { public static Hierarchy heirarchy = new Hierarchy(new RootLogger(Level.TRACE)); private Logger wl = null; /** * Private constructor * * @param name */ private AgentLogger (String name) { wl = heirarchy.getLogger(name); wl.setAdditivity(false); } Any advice appreciated. Thanks! Best regards, Richard Sand | CEO 239 Kings Highway East | Haddonfield | New Jersey 08033 | USA Mobile: +1 267 984 3651| Office: +1 856 795 1722| Fax: +1 856 795 1733 <http://www.skyworthttg.com/>

Hello Richard, Here is the logback-classic equivalent of the AgentLogger you posted. import ch.qos.logback.classic.Level; import ch.qos.logback.classic.Logger; import ch.qos.logback.classic.LoggerContext; public final class AgentLogger { // LoggerContext replaces log4j's Hierarchy public static LoggerContext context = new LoggerContext(); // set the root logger's level to TRACE static { Logger root = context.getLogger(Logger.ROOT_LOGGER_NAME); root.setLevel(Level.TRACE); } private Logger wl = null; private AgentLogger(String name) { wl = context.getLogger(name); wl.setAdditive(false); } } HTH, -- Ceki On 06/06/2011 11:37 PM, Richard Sand wrote:
Hi all,
I’m working with a COTS application, writing some extensions for it. The application has a proprietary logging API. In the past, I wrote a custom logging class wrapping log4j to bridge to the COTS application’s log capability. To totally isolate the usage of log4j in the API I created a wrapper around a Logger with its own Hierarchy.
We’re now exploring replacing log4j with logback in these extensions and I’m wondering if there is an analogous mechanism for accomplishing this in logback.
Here is an example of what I’m doing with log4j. Note how I create a new Hierarchy and then create a logger from that hierarchy with additivity turned off. How would I do this with logback?
*public**final**class*AgentLogger {
*public**static*Hierarchy /heirarchy/= *new*Hierarchy(*new*RootLogger(Level./TRACE/));
*private*Logger wl= *null*;
/**
* Private constructor
*
* *@param*name
*/
*private*AgentLogger (String name) {
wl= /heirarchy/.getLogger(name);
wl.setAdditivity(*false*);
}
Any advice appreciated. Thanks!
Best regards,
participants (2)
-
Ceki Gülcü
-
Richard Sand