[JIRA] Created: (LBCLASSIC-275) LoggingEvent casts to LogbackMDCAdapter without checking

LoggingEvent casts to LogbackMDCAdapter without checking -------------------------------------------------------- Key: LBCLASSIC-275 URL: http://jira.qos.ch/browse/LBCLASSIC-275 Project: logback-classic Issue Type: Bug Affects Versions: 0.9.28 Reporter: Chris Dolan Assignee: Logback dev list LoggingEvent has this code: // ugly but under the circumstances acceptable LogbackMDCAdapter logbackMDCAdapter = (LogbackMDCAdapter) MDC .getMDCAdapter(); mdcPropertyMap = logbackMDCAdapter.getPropertyMap(); I'm trying to build a logback implementation of the OSGi pax-logging-service (http://www.ops4j.org/projects/pax/logging/index.html). But I've got a problem that PAX exports org.slf4j.impl with their own MDC adapter that fails this cast. Theirs has the nice feature that the OSGi bundle context is automatically added to the MDC (at a performance cost, alas). I'd like to see LoggingEvent changed to something like the following for improved flexibility: MDCAdapter mdc = MDC.getMDCAdapter(); if (MDCAdaptor instanceof LogbackMDCAdapter) mdcPropertyMap = ((LogbackMDCAdapter)mdc).getPropertyMap(); else mdcPropertyMap = mdc.getCopyOfContextMap(); -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://jira.qos.ch/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira

[ http://jira.qos.ch/browse/LBCLASSIC-275?page=com.atlassian.jira.plugin.syste... ] Chris Dolan commented on LBCLASSIC-275: --------------------------------------- Another possible fix would be to defer reading the MDC until as late as possible: * in prepareForDeferredProcessing() where getCopyOfContextMap() would be appropriate * in getMDCPropertyMap() and getMdc() which could lazily fetch the MDC A proposed implementation: public void prepareForDeferredProcessing() { this.getFormattedMessage(); this.getThreadName(); // fixes http://jira.qos.ch/browse/LBCLASSIC-104 if (mdcPropertyMap != null) { mdcPropertyMap = MDC.getCopyOfContextMap(); } } public Map<String, String> getMDCPropertyMap() { if (mdcPropertyMap == null) { MDCAdapter mdc = MDC.getMDCAdapter(); if (mdc instanceof LogbackMDCAdapter) return ((LogbackMDCAdapter)mdc).getPropertyMap(); else mdcPropertyMap = mdc.getCopyOfContextMap(); } return mdcPropertyMap; } public Map<String, String> getMdc() { return getMDCPropertyMap(); }
LoggingEvent casts to LogbackMDCAdapter without checking --------------------------------------------------------
Key: LBCLASSIC-275 URL: http://jira.qos.ch/browse/LBCLASSIC-275 Project: logback-classic Issue Type: Bug Affects Versions: 0.9.28 Reporter: Chris Dolan Assignee: Logback dev list
LoggingEvent has this code: // ugly but under the circumstances acceptable LogbackMDCAdapter logbackMDCAdapter = (LogbackMDCAdapter) MDC .getMDCAdapter(); mdcPropertyMap = logbackMDCAdapter.getPropertyMap(); I'm trying to build a logback implementation of the OSGi pax-logging-service (http://www.ops4j.org/projects/pax/logging/index.html). But I've got a problem that PAX exports org.slf4j.impl with their own MDC adapter that fails this cast. Theirs has the nice feature that the OSGi bundle context is automatically added to the MDC (at a performance cost, alas). I'd like to see LoggingEvent changed to something like the following for improved flexibility: MDCAdapter mdc = MDC.getMDCAdapter(); if (MDCAdaptor instanceof LogbackMDCAdapter) mdcPropertyMap = ((LogbackMDCAdapter)mdc).getPropertyMap(); else mdcPropertyMap = mdc.getCopyOfContextMap();
-- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://jira.qos.ch/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira

[ http://jira.qos.ch/browse/LBCLASSIC-275?page=com.atlassian.jira.plugin.syste... ] Ceki Gulcu reassigned LBCLASSIC-275: ------------------------------------ Assignee: Ceki Gulcu (was: Logback dev list)
LoggingEvent casts to LogbackMDCAdapter without checking --------------------------------------------------------
Key: LBCLASSIC-275 URL: http://jira.qos.ch/browse/LBCLASSIC-275 Project: logback-classic Issue Type: Bug Affects Versions: 0.9.28 Reporter: Chris Dolan Assignee: Ceki Gulcu
LoggingEvent has this code: // ugly but under the circumstances acceptable LogbackMDCAdapter logbackMDCAdapter = (LogbackMDCAdapter) MDC .getMDCAdapter(); mdcPropertyMap = logbackMDCAdapter.getPropertyMap(); I'm trying to build a logback implementation of the OSGi pax-logging-service (http://www.ops4j.org/projects/pax/logging/index.html). But I've got a problem that PAX exports org.slf4j.impl with their own MDC adapter that fails this cast. Theirs has the nice feature that the OSGi bundle context is automatically added to the MDC (at a performance cost, alas). I'd like to see LoggingEvent changed to something like the following for improved flexibility: MDCAdapter mdc = MDC.getMDCAdapter(); if (MDCAdaptor instanceof LogbackMDCAdapter) mdcPropertyMap = ((LogbackMDCAdapter)mdc).getPropertyMap(); else mdcPropertyMap = mdc.getCopyOfContextMap();
-- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://jira.qos.ch/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira

[ http://jira.qos.ch/browse/LBCLASSIC-275?page=com.atlassian.jira.plugin.syste... ] Chris Dolan commented on LBCLASSIC-275: --------------------------------------- Since 0.9.29 was just released, I studied http://jira.qos.ch/browse/LBCLASSIC-254 (Performance improvement for LogbackMDCAdapter) in the context of my proposed fix. I believe my fix still works because there should not be any changes to MDC until *either* prepareForDeferredProcessing() or getMDCPropertyMap() is called. I just issued a pull request for this change: https://github.com/chrisdolan/logback/commit/2ac4ee863fc4d3c74439a91a0d327e2...
LoggingEvent casts to LogbackMDCAdapter without checking --------------------------------------------------------
Key: LBCLASSIC-275 URL: http://jira.qos.ch/browse/LBCLASSIC-275 Project: logback-classic Issue Type: Bug Affects Versions: 0.9.28 Reporter: Chris Dolan Assignee: Ceki Gulcu
LoggingEvent has this code: // ugly but under the circumstances acceptable LogbackMDCAdapter logbackMDCAdapter = (LogbackMDCAdapter) MDC .getMDCAdapter(); mdcPropertyMap = logbackMDCAdapter.getPropertyMap(); I'm trying to build a logback implementation of the OSGi pax-logging-service (http://www.ops4j.org/projects/pax/logging/index.html). But I've got a problem that PAX exports org.slf4j.impl with their own MDC adapter that fails this cast. Theirs has the nice feature that the OSGi bundle context is automatically added to the MDC (at a performance cost, alas). I'd like to see LoggingEvent changed to something like the following for improved flexibility: MDCAdapter mdc = MDC.getMDCAdapter(); if (MDCAdaptor instanceof LogbackMDCAdapter) mdcPropertyMap = ((LogbackMDCAdapter)mdc).getPropertyMap(); else mdcPropertyMap = mdc.getCopyOfContextMap();
-- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://jira.qos.ch/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira

[ http://jira.qos.ch/browse/LBCLASSIC-275?page=com.atlassian.jira.plugin.syste... ] Chris Dolan commented on LBCLASSIC-275: --------------------------------------- Pretty please? I think my proposed implementation is low-risk and fairly straightforward. This one glitch is blocking a Logback implementation of the PAX-Logging service, which currently uses log4j.
LoggingEvent casts to LogbackMDCAdapter without checking --------------------------------------------------------
Key: LBCLASSIC-275 URL: http://jira.qos.ch/browse/LBCLASSIC-275 Project: logback-classic Issue Type: Bug Affects Versions: 0.9.28 Reporter: Chris Dolan Assignee: Ceki Gulcu
LoggingEvent has this code: // ugly but under the circumstances acceptable LogbackMDCAdapter logbackMDCAdapter = (LogbackMDCAdapter) MDC .getMDCAdapter(); mdcPropertyMap = logbackMDCAdapter.getPropertyMap(); I'm trying to build a logback implementation of the OSGi pax-logging-service (http://www.ops4j.org/projects/pax/logging/index.html). But I've got a problem that PAX exports org.slf4j.impl with their own MDC adapter that fails this cast. Theirs has the nice feature that the OSGi bundle context is automatically added to the MDC (at a performance cost, alas). I'd like to see LoggingEvent changed to something like the following for improved flexibility: MDCAdapter mdc = MDC.getMDCAdapter(); if (MDCAdaptor instanceof LogbackMDCAdapter) mdcPropertyMap = ((LogbackMDCAdapter)mdc).getPropertyMap(); else mdcPropertyMap = mdc.getCopyOfContextMap();
-- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://jira.qos.ch/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira

[ http://jira.qos.ch/browse/LBCLASSIC-275?page=com.atlassian.jira.plugin.syste... ] Ceki Gulcu commented on LBCLASSIC-275: -------------------------------------- Hello Chris, I tried to make the code a little simpler by disallowing LoggingEvent#getMDCPropertyMap to return null values. It makes life easier downstream, in particular for users of JanoniEventEvaluator. As a result of this change, the size of serialized LoggingEvents increased by 3% in the case of null MDC which I think is acceptable.
LoggingEvent casts to LogbackMDCAdapter without checking --------------------------------------------------------
Key: LBCLASSIC-275 URL: http://jira.qos.ch/browse/LBCLASSIC-275 Project: logback-classic Issue Type: Bug Affects Versions: 0.9.28 Reporter: Chris Dolan Assignee: Ceki Gulcu
LoggingEvent has this code: // ugly but under the circumstances acceptable LogbackMDCAdapter logbackMDCAdapter = (LogbackMDCAdapter) MDC .getMDCAdapter(); mdcPropertyMap = logbackMDCAdapter.getPropertyMap(); I'm trying to build a logback implementation of the OSGi pax-logging-service (http://www.ops4j.org/projects/pax/logging/index.html). But I've got a problem that PAX exports org.slf4j.impl with their own MDC adapter that fails this cast. Theirs has the nice feature that the OSGi bundle context is automatically added to the MDC (at a performance cost, alas). I'd like to see LoggingEvent changed to something like the following for improved flexibility: MDCAdapter mdc = MDC.getMDCAdapter(); if (MDCAdaptor instanceof LogbackMDCAdapter) mdcPropertyMap = ((LogbackMDCAdapter)mdc).getPropertyMap(); else mdcPropertyMap = mdc.getCopyOfContextMap();
-- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://jira.qos.ch/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira

[ http://jira.qos.ch/browse/LBCLASSIC-275?page=com.atlassian.jira.plugin.syste... ] Ceki Gulcu resolved LBCLASSIC-275. ---------------------------------- Fix Version/s: 0.9.30 Resolution: Fixed
LoggingEvent casts to LogbackMDCAdapter without checking --------------------------------------------------------
Key: LBCLASSIC-275 URL: http://jira.qos.ch/browse/LBCLASSIC-275 Project: logback-classic Issue Type: Bug Affects Versions: 0.9.28 Reporter: Chris Dolan Assignee: Ceki Gulcu Fix For: 0.9.30
LoggingEvent has this code: // ugly but under the circumstances acceptable LogbackMDCAdapter logbackMDCAdapter = (LogbackMDCAdapter) MDC .getMDCAdapter(); mdcPropertyMap = logbackMDCAdapter.getPropertyMap(); I'm trying to build a logback implementation of the OSGi pax-logging-service (http://www.ops4j.org/projects/pax/logging/index.html). But I've got a problem that PAX exports org.slf4j.impl with their own MDC adapter that fails this cast. Theirs has the nice feature that the OSGi bundle context is automatically added to the MDC (at a performance cost, alas). I'd like to see LoggingEvent changed to something like the following for improved flexibility: MDCAdapter mdc = MDC.getMDCAdapter(); if (MDCAdaptor instanceof LogbackMDCAdapter) mdcPropertyMap = ((LogbackMDCAdapter)mdc).getPropertyMap(); else mdcPropertyMap = mdc.getCopyOfContextMap();
-- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://jira.qos.ch/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira
participants (2)
-
Ceki Gulcu (JIRA)
-
Chris Dolan (JIRA)