I might have a Dog
class that has a single instance shared across multiple threads. I plan on using SLF4J for all logging:
public class Dog {
private Logger logger = LoggerFactory.getLogger(Dog.class);
// ...etc.
}
Is my logger
instance thread safe? Why/why not?
Certainly, everyone assumes that a Logger
is going to be thread-safe. But you would need to look at the code / javadocs of the implementation classes behind the facade to be absolutely sure.
For specific implementations:
(Obviously, these are statements that the respective code is designed to thread-safe. There can always be bugs. For example, were at the time of writing a couple of open thread-safety bugs in the Log4j 2 tracker, though it doesn't seem like those bugs would directly affect your example code.)