Something which should be made clearer in the logback doc: Should a layout be threadsafe?

Hi, Quick remark: It is not clear from the logback docs whether a new layout should be threadsafe. I strongly suspect that it should be (why would logback do the possibly unnecessary locking for you?), but - should that not be explicitly said? E.g. coders may fall into the usual trap of having an instance-bound or even static SimpleDateFormat member and not making the access to it synchronized etc (aehm). Best regards, --- David

Actually, Logback was originally designed with the assumption that Layouts were not thread-safe. I'm not sure if it is still the case, but at one PatternLayout was not. If you look at AppenderBase you will see that. UnsynchronizedAppenderBase was created for Appenders that are completely thread-safe, including the Layouts they use. FWIW, I agree that Layouts should always be thread-safe. Ralph On Oct 24, 2011, at 5:29 PM, jakartaman wrote:
Hi,
Quick remark:
It is not clear from the logback docs whether a new layout should be threadsafe. I strongly suspect that it should be (why would logback do the possibly unnecessary locking for you?), but - should that not be explicitly said?
E.g. coders may fall into the usual trap of having an instance-bound or even static SimpleDateFormat member and not making the access to it synchronized etc (aehm).
Best regards,
--- David
_______________________________________________ Logback-user mailing list Logback-user@qos.ch http://mailman.qos.ch/mailman/listinfo/logback-user

Thanks. I shall raise a bug in the JIRA.... On 10/25/2011 03:48 AM, Ralph Goers wrote:
Actually, Logback was originally designed with the assumption that Layouts were not thread-safe. I'm not sure if it is still the case, but at one PatternLayout was not. If you look at AppenderBase you will see that. UnsynchronizedAppenderBase was created for Appenders that are completely thread-safe, including the Layouts they use.
FWIW, I agree that Layouts should always be thread-safe.
Ralph
On Oct 24, 2011, at 5:29 PM, jakartaman wrote:
Hi,
Quick remark:
It is not clear from the logback docs whether a new layout should be threadsafe. I strongly suspect that it should be (why would logback do the possibly unnecessary locking for you?), but - should that not be explicitly said?
E.g. coders may fall into the usual trap of having an instance-bound or even static SimpleDateFormat member and not making the access to it synchronized etc (aehm).
Best regards,
--- David
_______________________________________________ Logback-user mailing list Logback-user@qos.ch http://mailman.qos.ch/mailman/listinfo/logback-user
Logback-user mailing list Logback-user@qos.ch http://mailman.qos.ch/mailman/listinfo/logback-user
participants (2)
-
jakartaman
-
Ralph Goers