1 package org.slf4j.helpers; 2 3 import java.io.ObjectStreamException; 4 import java.io.Serializable; 5 6 import org.slf4j.Logger; 7 import org.slf4j.LoggerFactory; 8 9 /** 10 * Serves as base class for named logger implementation. More significantly, this 11 * class establishes deserialization behavior. See @see #readResolve. 12 * 13 * @author Ceki Gulcu 14 * @since 1.5.3 15 */ 16 abstract class NamedLoggerBase implements Logger, Serializable { 17 18 protected String name; 19 20 public String getName() { 21 return name; 22 } 23 24 /** 25 * Replace this instance with a homonymous (same name) logger returned 26 * by LoggerFactory. Note that this method is only called during 27 * deserialization. 28 * 29 * <p> 30 * This approach will work well if the desired ILoggerFactory is the one 31 * references by LoggerFactory. However, if the user manages its logger hierarchy 32 * through a different (non-static) mechanism, e.g. dependency injection, then 33 * this approach would be mostly counterproductive. 34 * 35 * @return logger with same name as returned by LoggerFactory 36 * @throws ObjectStreamException 37 */ 38 protected Object readResolve() throws ObjectStreamException { 39 // using getName() instead of this.name works even for 40 // NOPLogger 41 return LoggerFactory.getLogger(getName()); 42 } 43 44 }